From 6e9acb158e21b80119d211369ccd7c39a1c2ee25 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 24 Aug 2017 15:24:41 -0700 Subject: [PATCH 1/2] There should be no crash when attempting to merge an import with a local declaration --- src/compiler/checker.ts | 2 + .../noCrashOnImportShadowing.errors.txt | 29 ++++++++++++++ .../reference/noCrashOnImportShadowing.js | 39 +++++++++++++++++++ .../compiler/noCrashOnImportShadowing.ts | 21 ++++++++++ 4 files changed, 91 insertions(+) create mode 100644 tests/baselines/reference/noCrashOnImportShadowing.errors.txt create mode 100644 tests/baselines/reference/noCrashOnImportShadowing.js create mode 100644 tests/cases/compiler/noCrashOnImportShadowing.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 24a9a868c4aa2..7a0a77ceb6d4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19151,6 +19151,8 @@ namespace ts { : DeclarationSpaces.ExportNamespace; case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: + // A NamespaceImport declares an Alias, which is allowed to merge with other values within the module + case SyntaxKind.NamespaceImport: return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue; case SyntaxKind.ImportEqualsDeclaration: let result = DeclarationSpaces.None; diff --git a/tests/baselines/reference/noCrashOnImportShadowing.errors.txt b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt new file mode 100644 index 0000000000000..be168580435fd --- /dev/null +++ b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/index.ts(4,1): error TS2693: 'B' only refers to a type, but is being used as a value here. +tests/cases/compiler/index.ts(9,10): error TS2304: Cannot find name 'OriginalB'. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + export const zzz = 123; + +==== tests/cases/compiler/a.ts (0 errors) ==== + import * as B from "./b"; + + interface B { + x: string; + } + export { B }; + +==== tests/cases/compiler/index.ts (2 errors) ==== + import { B } from "./a"; + + const x: B = { x: "" }; + B.zzz; + ~ +!!! error TS2693: 'B' only refers to a type, but is being used as a value here. + + import * as OriginalB from "./b"; + OriginalB.zzz; + + const y: OriginalB = x; + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'OriginalB'. \ No newline at end of file diff --git a/tests/baselines/reference/noCrashOnImportShadowing.js b/tests/baselines/reference/noCrashOnImportShadowing.js new file mode 100644 index 0000000000000..1ef780b65d1b6 --- /dev/null +++ b/tests/baselines/reference/noCrashOnImportShadowing.js @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/noCrashOnImportShadowing.ts] //// + +//// [b.ts] +export const zzz = 123; + +//// [a.ts] +import * as B from "./b"; + +interface B { + x: string; +} +export { B }; + +//// [index.ts] +import { B } from "./a"; + +const x: B = { x: "" }; +B.zzz; + +import * as OriginalB from "./b"; +OriginalB.zzz; + +const y: OriginalB = x; + +//// [b.js] +"use strict"; +exports.__esModule = true; +exports.zzz = 123; +//// [a.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +var x = { x: "" }; +B.zzz; +var OriginalB = require("./b"); +OriginalB.zzz; +var y = x; diff --git a/tests/cases/compiler/noCrashOnImportShadowing.ts b/tests/cases/compiler/noCrashOnImportShadowing.ts new file mode 100644 index 0000000000000..c56637e8db9c2 --- /dev/null +++ b/tests/cases/compiler/noCrashOnImportShadowing.ts @@ -0,0 +1,21 @@ +// @filename: b.ts +export const zzz = 123; + +// @filename: a.ts +import * as B from "./b"; + +interface B { + x: string; +} +export { B }; + +// @filename: index.ts +import { B } from "./a"; + +const x: B = { x: "" }; +B.zzz; + +import * as OriginalB from "./b"; +OriginalB.zzz; + +const y: OriginalB = x; \ No newline at end of file From a030d5d8511840fa1c23f51ad2fbdb07684bcbc1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 24 Aug 2017 15:30:31 -0700 Subject: [PATCH 2/2] Show symbol has actually merged within the module --- .../reference/noCrashOnImportShadowing.errors.txt | 4 ++++ tests/baselines/reference/noCrashOnImportShadowing.js | 7 +++++++ tests/cases/compiler/noCrashOnImportShadowing.ts | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/tests/baselines/reference/noCrashOnImportShadowing.errors.txt b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt index be168580435fd..c1d1dbcdef1a1 100644 --- a/tests/baselines/reference/noCrashOnImportShadowing.errors.txt +++ b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt @@ -11,6 +11,10 @@ tests/cases/compiler/index.ts(9,10): error TS2304: Cannot find name 'OriginalB'. interface B { x: string; } + + const x: B = { x: "" }; + B.zzz; + export { B }; ==== tests/cases/compiler/index.ts (2 errors) ==== diff --git a/tests/baselines/reference/noCrashOnImportShadowing.js b/tests/baselines/reference/noCrashOnImportShadowing.js index 1ef780b65d1b6..7ca2116954d6f 100644 --- a/tests/baselines/reference/noCrashOnImportShadowing.js +++ b/tests/baselines/reference/noCrashOnImportShadowing.js @@ -9,6 +9,10 @@ import * as B from "./b"; interface B { x: string; } + +const x: B = { x: "" }; +B.zzz; + export { B }; //// [index.ts] @@ -29,6 +33,9 @@ exports.zzz = 123; //// [a.js] "use strict"; exports.__esModule = true; +var B = require("./b"); +var x = { x: "" }; +B.zzz; //// [index.js] "use strict"; exports.__esModule = true; diff --git a/tests/cases/compiler/noCrashOnImportShadowing.ts b/tests/cases/compiler/noCrashOnImportShadowing.ts index c56637e8db9c2..69e8b6a0f8c01 100644 --- a/tests/cases/compiler/noCrashOnImportShadowing.ts +++ b/tests/cases/compiler/noCrashOnImportShadowing.ts @@ -7,6 +7,10 @@ import * as B from "./b"; interface B { x: string; } + +const x: B = { x: "" }; +B.zzz; + export { B }; // @filename: index.ts