Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix elided var handling in declaration emit visibility checks #58605

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 0 additions & 4 deletions tests/baselines/reference/declarationEmitInvalidExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
if (false) {
exports.myClass = 0;
}


//// [declarationEmitInvalidExport.d.ts]
export type MyClass = typeof myClass;
Original file line number Diff line number Diff line change
@@ -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'.
11 changes: 11 additions & 0 deletions tests/baselines/reference/declarationEmitVarInElidedBlock.symbols
Original file line number Diff line number Diff line change
@@ -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))

16 changes: 16 additions & 0 deletions tests/baselines/reference/declarationEmitVarInElidedBlock.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/declarationEmitVarInElidedBlock.ts] ////

=== declarationEmitVarInElidedBlock.ts ===
{
var a = "";
>a : string
> : ^^^^^^
>"" : ""
> : ^^
}
export let b: typeof a;
>b : string
> : ^^^^^^
>a : string
> : ^^^^^^

6 changes: 6 additions & 0 deletions tests/cases/compiler/declarationEmitVarInElidedBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @declaration: true
// @emitDeclarationOnly: true
{
var a = "";
}
export let b: typeof a;