Fix elided var handling in declaration emit visibility checks (#58605)

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
This commit is contained in:
Wesley Wigham
2024-05-21 13:44:35 -07:00
committed by GitHub
co-authored by TypeScript Bot
parent 11b73ecc4a
commit 6f72e24544
7 changed files with 56 additions and 7 deletions
+9 -2
View File
@@ -5862,9 +5862,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return { accessibility: SymbolAccessibility.Accessible };
}
if (!symbol) {
return {
accessibility: SymbolAccessibility.NotResolved,
errorSymbolName: getTextOfNode(firstIdentifier),
errorNode: firstIdentifier,
};
}
// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol, shouldComputeAliasToMakeVisible)) || {
accessibility: SymbolAccessibility.NotResolved,
return hasVisibleDeclarations(symbol, shouldComputeAliasToMakeVisible) || {
accessibility: SymbolAccessibility.NotAccessible,
errorSymbolName: getTextOfNode(firstIdentifier),
errorNode: firstIdentifier,
};
@@ -1,11 +1,14 @@
declarationEmitInvalidExport.ts(4,30): error TS4081: Exported type alias 'MyClass' has or is using private name 'myClass'.
declarationEmitInvalidExport.ts(5,1): error TS1128: Declaration or statement expected.
==== declarationEmitInvalidExport.ts (1 errors) ====
==== declarationEmitInvalidExport.ts (2 errors) ====
if (false) {
export var myClass = 0;
}
export type MyClass = typeof myClass;
~~~~~~~
!!! error TS4081: Exported type alias 'MyClass' has or is using private name 'myClass'.
}
~
!!! error TS1128: Declaration or statement expected.
@@ -14,7 +14,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
if (false) {
exports.myClass = 0;
}
//// [declarationEmitInvalidExport.d.ts]
export type MyClass = typeof myClass;
@@ -0,0 +1,10 @@
declarationEmitVarInElidedBlock.ts(4,22): error TS4025: Exported variable 'b' has or is using private name 'a'.
==== declarationEmitVarInElidedBlock.ts (1 errors) ====
{
var a = "";
}
export let b: typeof a;
~
!!! error TS4025: Exported variable 'b' has or is using private name 'a'.
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/declarationEmitVarInElidedBlock.ts] ////
=== declarationEmitVarInElidedBlock.ts ===
{
var a = "";
>a : Symbol(a, Decl(declarationEmitVarInElidedBlock.ts, 1, 7))
}
export let b: typeof a;
>b : Symbol(b, Decl(declarationEmitVarInElidedBlock.ts, 3, 10))
>a : Symbol(a, Decl(declarationEmitVarInElidedBlock.ts, 1, 7))
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/declarationEmitVarInElidedBlock.ts] ////
=== declarationEmitVarInElidedBlock.ts ===
{
var a = "";
>a : string
> : ^^^^^^
>"" : ""
> : ^^
}
export let b: typeof a;
>b : string
> : ^^^^^^
>a : string
> : ^^^^^^
@@ -0,0 +1,6 @@
// @declaration: true
// @emitDeclarationOnly: true
{
var a = "";
}
export let b: typeof a;