diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index fd897848e767c..5e1ec26dabeef 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -8,9 +8,9 @@ namespace ts { export interface ExternalModuleInfo { externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers - exportSpecifiers: Map; // export specifiers by name + exportSpecifiers: Map; // file-local export specifiers by name (no reexports) exportedBindings: Identifier[][]; // exported names of local declarations - exportedNames: Identifier[] | undefined; // all exported names local to module + exportedNames: Identifier[] | undefined; // all exported names in the module, both local and reexported exportEquals: ExportAssignment | undefined; // an export= declaration if one was present hasExportStarsToExportValues: boolean; // whether this module contains export* } @@ -201,7 +201,9 @@ namespace ts { for (const specifier of cast(node.exportClause, isNamedExports).elements) { if (!uniqueExports.get(idText(specifier.name))) { const name = specifier.propertyName || specifier.name; - exportSpecifiers.add(idText(name), specifier); + if (!node.moduleSpecifier) { + exportSpecifiers.add(idText(name), specifier); + } const decl = resolver.getReferencedImportDeclaration(name) || resolver.getReferencedValueDeclaration(name); diff --git a/tests/baselines/reference/reexportNameAliasedAndHoisted.js b/tests/baselines/reference/reexportNameAliasedAndHoisted.js new file mode 100644 index 0000000000000..4dabd47388e7a --- /dev/null +++ b/tests/baselines/reference/reexportNameAliasedAndHoisted.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/reexportNameAliasedAndHoisted.ts] //// + +//// [gridview.ts] +export type Sizing = any; +export const Sizing = null; +//// [index.ts] +// https://github.com/microsoft/TypeScript/issues/39195 +export { Sizing as GridViewSizing } from './gridview'; +export namespace Sizing { + export const Distribute = { type: 'distribute' }; +} + +//// [gridview.js] +"use strict"; +exports.__esModule = true; +exports.Sizing = void 0; +exports.Sizing = null; +//// [index.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +exports.__esModule = true; +exports.Sizing = exports.GridViewSizing = void 0; +// https://github.com/microsoft/TypeScript/issues/39195 +var gridview_1 = require("./gridview"); +__createBinding(exports, gridview_1, "Sizing", "GridViewSizing"); +var Sizing; +(function (Sizing) { + Sizing.Distribute = { type: 'distribute' }; +})(Sizing = exports.Sizing || (exports.Sizing = {})); diff --git a/tests/baselines/reference/reexportNameAliasedAndHoisted.symbols b/tests/baselines/reference/reexportNameAliasedAndHoisted.symbols new file mode 100644 index 0000000000000..3363b9efa38eb --- /dev/null +++ b/tests/baselines/reference/reexportNameAliasedAndHoisted.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/gridview.ts === +export type Sizing = any; +>Sizing : Symbol(Sizing, Decl(gridview.ts, 0, 0), Decl(gridview.ts, 1, 12)) + +export const Sizing = null; +>Sizing : Symbol(Sizing, Decl(gridview.ts, 0, 0), Decl(gridview.ts, 1, 12)) + +=== tests/cases/compiler/index.ts === +// https://github.com/microsoft/TypeScript/issues/39195 +export { Sizing as GridViewSizing } from './gridview'; +>Sizing : Symbol(Sizing, Decl(gridview.ts, 0, 0), Decl(gridview.ts, 1, 12)) +>GridViewSizing : Symbol(GridViewSizing, Decl(index.ts, 1, 8)) + +export namespace Sizing { +>Sizing : Symbol(Sizing, Decl(index.ts, 1, 54)) + + export const Distribute = { type: 'distribute' }; +>Distribute : Symbol(Distribute, Decl(index.ts, 3, 16)) +>type : Symbol(type, Decl(index.ts, 3, 31)) +} diff --git a/tests/baselines/reference/reexportNameAliasedAndHoisted.types b/tests/baselines/reference/reexportNameAliasedAndHoisted.types new file mode 100644 index 0000000000000..e3c1fb1feebc8 --- /dev/null +++ b/tests/baselines/reference/reexportNameAliasedAndHoisted.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/gridview.ts === +export type Sizing = any; +>Sizing : any + +export const Sizing = null; +>Sizing : any +>null : null + +=== tests/cases/compiler/index.ts === +// https://github.com/microsoft/TypeScript/issues/39195 +export { Sizing as GridViewSizing } from './gridview'; +>Sizing : any +>GridViewSizing : any + +export namespace Sizing { +>Sizing : typeof Sizing + + export const Distribute = { type: 'distribute' }; +>Distribute : { type: string; } +>{ type: 'distribute' } : { type: string; } +>type : string +>'distribute' : "distribute" +} diff --git a/tests/cases/compiler/reexportNameAliasedAndHoisted.ts b/tests/cases/compiler/reexportNameAliasedAndHoisted.ts new file mode 100644 index 0000000000000..e3c7b23f6de72 --- /dev/null +++ b/tests/cases/compiler/reexportNameAliasedAndHoisted.ts @@ -0,0 +1,9 @@ +// @filename: gridview.ts +export type Sizing = any; +export const Sizing = null; +// @filename: index.ts +// https://github.com/microsoft/TypeScript/issues/39195 +export { Sizing as GridViewSizing } from './gridview'; +export namespace Sizing { + export const Distribute = { type: 'distribute' }; +} \ No newline at end of file