diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efee668a24b..8b59d1a2d37 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1165,7 +1165,9 @@ namespace ts { // Check if symbol is any of the alias return forEachValue(symbols, symbolFromSymbolTable => { - if (symbolFromSymbolTable.flags & SymbolFlags.Alias && symbolFromSymbolTable.name !== "export=") { + if (symbolFromSymbolTable.flags & SymbolFlags.Alias + && symbolFromSymbolTable.name !== "export=" + && !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)) { if (!useOnlyExternalAliasing || // We can use any type of alias to get the name // Is this external alias, then use it to name ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration)) { @@ -1207,7 +1209,7 @@ namespace ts { } // Qualify if the symbol from symbol table has same meaning as expected - symbolFromSymbolTable = (symbolFromSymbolTable.flags & SymbolFlags.Alias) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & SymbolFlags.Alias && !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types index 9d87ec9925d..6b621f4c777 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types @@ -31,8 +31,8 @@ export { c as c2 } from "server"; export { i, m as instantiatedModule } from "server"; >i : any ->m : typeof instantiatedModule ->instantiatedModule : typeof instantiatedModule +>m : typeof m +>instantiatedModule : typeof m export { uninstantiated } from "server"; >uninstantiated : any diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types index 9d87ec9925d..6b621f4c777 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -31,8 +31,8 @@ export { c as c2 } from "server"; export { i, m as instantiatedModule } from "server"; >i : any ->m : typeof instantiatedModule ->instantiatedModule : typeof instantiatedModule +>m : typeof m +>instantiatedModule : typeof m export { uninstantiated } from "server"; >uninstantiated : any diff --git a/tests/baselines/reference/exportSpecifierForAGlobal.js b/tests/baselines/reference/exportSpecifierForAGlobal.js new file mode 100644 index 00000000000..6b4343a299b --- /dev/null +++ b/tests/baselines/reference/exportSpecifierForAGlobal.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/exportSpecifierForAGlobal.ts] //// + +//// [a.d.ts] + +declare class X { } + +//// [b.ts] +export {X}; +export function f() { + var x: X; + return x; +} + + +//// [b.js] +function f() { + var x; + return x; +} +exports.f = f; + + +//// [b.d.ts] +export { X }; +export declare function f(): X; diff --git a/tests/baselines/reference/exportSpecifierForAGlobal.symbols b/tests/baselines/reference/exportSpecifierForAGlobal.symbols new file mode 100644 index 00000000000..b38fc7be270 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierForAGlobal.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/a.d.ts === + +declare class X { } +>X : Symbol(X, Decl(a.d.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +export {X}; +>X : Symbol(X, Decl(b.ts, 0, 8)) + +export function f() { +>f : Symbol(f, Decl(b.ts, 0, 11)) + + var x: X; +>x : Symbol(x, Decl(b.ts, 2, 7)) +>X : Symbol(X, Decl(a.d.ts, 0, 0)) + + return x; +>x : Symbol(x, Decl(b.ts, 2, 7)) +} + diff --git a/tests/baselines/reference/exportSpecifierForAGlobal.types b/tests/baselines/reference/exportSpecifierForAGlobal.types new file mode 100644 index 00000000000..e3d728ad0d0 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierForAGlobal.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/a.d.ts === + +declare class X { } +>X : X + +=== tests/cases/compiler/b.ts === +export {X}; +>X : typeof X + +export function f() { +>f : () => X + + var x: X; +>x : X +>X : X + + return x; +>x : X +} + diff --git a/tests/baselines/reference/exportsAndImports3-amd.symbols b/tests/baselines/reference/exportsAndImports3-amd.symbols index 4ab418a9bef..a46d7df2a68 100644 --- a/tests/baselines/reference/exportsAndImports3-amd.symbols +++ b/tests/baselines/reference/exportsAndImports3-amd.symbols @@ -16,17 +16,17 @@ export enum E { >E : Symbol(E, Decl(t1.ts, 6, 1)) A, B, C ->A : Symbol(E1.A, Decl(t1.ts, 7, 15)) ->B : Symbol(E1.B, Decl(t1.ts, 8, 6)) ->C : Symbol(E1.C, Decl(t1.ts, 8, 9)) +>A : Symbol(E.A, Decl(t1.ts, 7, 15)) +>B : Symbol(E.B, Decl(t1.ts, 8, 6)) +>C : Symbol(E.C, Decl(t1.ts, 8, 9)) } export const enum D { >D : Symbol(D, Decl(t1.ts, 9, 1)) A, B, C ->A : Symbol(D1.A, Decl(t1.ts, 10, 21)) ->B : Symbol(D1.B, Decl(t1.ts, 11, 6)) ->C : Symbol(D1.C, Decl(t1.ts, 11, 9)) +>A : Symbol(D.A, Decl(t1.ts, 10, 21)) +>B : Symbol(D.B, Decl(t1.ts, 11, 6)) +>C : Symbol(D.C, Decl(t1.ts, 11, 9)) } export module M { >M : Symbol(M, Decl(t1.ts, 12, 1)) diff --git a/tests/baselines/reference/exportsAndImports3.symbols b/tests/baselines/reference/exportsAndImports3.symbols index 4ab418a9bef..a46d7df2a68 100644 --- a/tests/baselines/reference/exportsAndImports3.symbols +++ b/tests/baselines/reference/exportsAndImports3.symbols @@ -16,17 +16,17 @@ export enum E { >E : Symbol(E, Decl(t1.ts, 6, 1)) A, B, C ->A : Symbol(E1.A, Decl(t1.ts, 7, 15)) ->B : Symbol(E1.B, Decl(t1.ts, 8, 6)) ->C : Symbol(E1.C, Decl(t1.ts, 8, 9)) +>A : Symbol(E.A, Decl(t1.ts, 7, 15)) +>B : Symbol(E.B, Decl(t1.ts, 8, 6)) +>C : Symbol(E.C, Decl(t1.ts, 8, 9)) } export const enum D { >D : Symbol(D, Decl(t1.ts, 9, 1)) A, B, C ->A : Symbol(D1.A, Decl(t1.ts, 10, 21)) ->B : Symbol(D1.B, Decl(t1.ts, 11, 6)) ->C : Symbol(D1.C, Decl(t1.ts, 11, 9)) +>A : Symbol(D.A, Decl(t1.ts, 10, 21)) +>B : Symbol(D.B, Decl(t1.ts, 11, 6)) +>C : Symbol(D.C, Decl(t1.ts, 11, 9)) } export module M { >M : Symbol(M, Decl(t1.ts, 12, 1)) diff --git a/tests/cases/compiler/exportSpecifierForAGlobal.ts b/tests/cases/compiler/exportSpecifierForAGlobal.ts new file mode 100644 index 00000000000..c24ec0b086f --- /dev/null +++ b/tests/cases/compiler/exportSpecifierForAGlobal.ts @@ -0,0 +1,12 @@ +// @declaration: true +// @module: commonjs + +// @filename: a.d.ts +declare class X { } + +// @filename: b.ts +export {X}; +export function f() { + var x: X; + return x; +}