diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 289265b7572..70b39980882 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1093,12 +1093,16 @@ namespace ts { return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol)); } - interface ExportedSymbolDiagnostics { + interface ExportCollisionTracker { specifierText: string; exportsWithDuplicate: ExportDeclaration[]; } - function extendExportSymbols(target: SymbolTable, source: SymbolTable, lookupTable?: Map, exportNode?: ExportDeclaration) { + /** + * Extends one symbol table with abother while collecting information on name collisions for error message generation into the `lookupTable` argument + * Not passing `lookupTable` and `exportNode` disables this collection, and just extends the tables + */ + function extendExportSymbols(target: SymbolTable, source: SymbolTable, lookupTable?: Map, exportNode?: ExportDeclaration) { for (const id in source) { if (id !== "default" && !hasProperty(target, id)) { target[id] = source[id]; @@ -1129,7 +1133,7 @@ namespace ts { const exportStars = symbol.exports["__export"]; if (exportStars) { const nestedSymbols: SymbolTable = {}; - const lookupTable: Map = {}; + const lookupTable: Map = {}; for (const node of exportStars.declarations) { const resolvedModule = resolveExternalModuleName(node, (node as ExportDeclaration).moduleSpecifier); const exportedSymbols = visit(resolvedModule); @@ -1149,7 +1153,7 @@ namespace ts { for (const node of exportsWithDuplicate) { diagnostics.add(createDiagnosticForNode( node, - Diagnostics.An_export_Asterisk_from_0_declaration_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity, + Diagnostics.Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity, lookupTable[id].specifierText, id )); @@ -14094,7 +14098,7 @@ namespace ts { } function isNotOverload(declaration: Declaration): boolean { - return (declaration.kind !== SyntaxKind.FunctionDeclaration || typeof (declaration as FunctionDeclaration).body !== "undefined"); + return declaration.kind !== SyntaxKind.FunctionDeclaration || !!(declaration as FunctionDeclaration).body; } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a0976e6cc6a..b2a63085ae4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -836,7 +836,7 @@ "category": "Error", "code": 2307 }, - "An `export * from {0}` declaration has already exported a member named '{1}'. Consider explicitly re-exporting to resolve the ambiguity.": { + "Module {0} has already exported a member named '{1}'. Consider explicitly re-exporting to resolve the ambiguity.": { "category": "Error", "code": 2308 }, diff --git a/tests/baselines/reference/exportStar-amd.errors.txt b/tests/baselines/reference/exportStar-amd.errors.txt index 714890d5a14..edd5c0d51bd 100644 --- a/tests/baselines/reference/exportStar-amd.errors.txt +++ b/tests/baselines/reference/exportStar-amd.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: Module '"tests/cases/conformance/es6/modules/t4"' has no default export. -tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from "./t1"` declaration has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. -tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from "./t1"` declaration has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. +tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. +tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. ==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== @@ -23,9 +23,9 @@ tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from export * from "./t2"; export * from "./t3"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2308: An `export * from "./t1"` declaration has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. +!!! error TS2308: Module "./t1" has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2308: An `export * from "./t1"` declaration has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. +!!! error TS2308: Module "./t1" has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. ==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== import hello, { x, y, z, foo } from "./t4"; diff --git a/tests/baselines/reference/exportStar.errors.txt b/tests/baselines/reference/exportStar.errors.txt index 714890d5a14..edd5c0d51bd 100644 --- a/tests/baselines/reference/exportStar.errors.txt +++ b/tests/baselines/reference/exportStar.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: Module '"tests/cases/conformance/es6/modules/t4"' has no default export. -tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from "./t1"` declaration has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. -tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from "./t1"` declaration has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. +tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. +tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. ==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== @@ -23,9 +23,9 @@ tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: An `export * from export * from "./t2"; export * from "./t3"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2308: An `export * from "./t1"` declaration has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. +!!! error TS2308: Module "./t1" has already exported a member named 'x'. Consider explicitly re-exporting to resolve the ambiguity. ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2308: An `export * from "./t1"` declaration has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. +!!! error TS2308: Module "./t1" has already exported a member named 'y'. Consider explicitly re-exporting to resolve the ambiguity. ==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== import hello, { x, y, z, foo } from "./t4";