From 54ab1e99c0320ff0a8784bff0ca14b0580e66741 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 26 Nov 2015 14:24:12 -0800 Subject: [PATCH] fix module record nonambiguous case, add test for it --- src/compiler/checker.ts | 2 +- ...oduleSameValueDuplicateExportedBindings.js | 28 +++++++++++++++++++ ...SameValueDuplicateExportedBindings.symbols | 11 ++++++++ ...leSameValueDuplicateExportedBindings.types | 12 ++++++++ ...oduleSameValueDuplicateExportedBindings.ts | 10 +++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/moduleSameValueDuplicateExportedBindings.js create mode 100644 tests/baselines/reference/moduleSameValueDuplicateExportedBindings.symbols create mode 100644 tests/baselines/reference/moduleSameValueDuplicateExportedBindings.types create mode 100644 tests/cases/compiler/moduleSameValueDuplicateExportedBindings.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28691b3a30e..1dce8d2406d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1113,7 +1113,7 @@ namespace ts { }; } } - else if (lookupTable && exportNode && id !== "default" && hasProperty(target, id)) { + else if (lookupTable && exportNode && id !== "default" && hasProperty(target, id) && target[id] !== source[id]) { lookupTable[id].exportsWithDuplicate.push(exportNode); } } diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.js b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.js new file mode 100644 index 00000000000..8a12973dc02 --- /dev/null +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/moduleSameValueDuplicateExportedBindings.ts] //// + +//// [a.ts] +export * from "./b"; +export * from "./c"; + +//// [b.ts] +export * from "./c"; + +//// [c.ts] +export var foo = 42; + +//// [c.js] +"use strict"; +exports.foo = 42; +//// [b.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("./c")); +//// [a.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("./b")); +__export(require("./c")); diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.symbols b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.symbols new file mode 100644 index 00000000000..2f8bba9b6ab --- /dev/null +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +export * from "./b"; +No type information for this code.export * from "./c"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +export * from "./c"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/c.ts === +export var foo = 42; +>foo : Symbol(foo, Decl(c.ts, 0, 10)) + diff --git a/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.types b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.types new file mode 100644 index 00000000000..57be71c802b --- /dev/null +++ b/tests/baselines/reference/moduleSameValueDuplicateExportedBindings.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/a.ts === +export * from "./b"; +No type information for this code.export * from "./c"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +export * from "./c"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/c.ts === +export var foo = 42; +>foo : number +>42 : number + diff --git a/tests/cases/compiler/moduleSameValueDuplicateExportedBindings.ts b/tests/cases/compiler/moduleSameValueDuplicateExportedBindings.ts new file mode 100644 index 00000000000..d51de9c2e5a --- /dev/null +++ b/tests/cases/compiler/moduleSameValueDuplicateExportedBindings.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @filename: a.ts +export * from "./b"; +export * from "./c"; + +// @filename: b.ts +export * from "./c"; + +// @filename: c.ts +export var foo = 42; \ No newline at end of file