Skip to content

Commit

Permalink
Fix crash when attempting to merge an import with a local declaration (
Browse files Browse the repository at this point in the history
…#18032)

* There should be no crash when attempting to merge an import with a local declaration

* Show symbol has actually merged within the module
  • Loading branch information
weswigham authored Aug 25, 2017
1 parent 643a7e7 commit 62eaaf9
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19180,6 +19180,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;
Expand Down
33 changes: 33 additions & 0 deletions tests/baselines/reference/noCrashOnImportShadowing.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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;
}

const x: B = { x: "" };
B.zzz;

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'.
46 changes: 46 additions & 0 deletions tests/baselines/reference/noCrashOnImportShadowing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/noCrashOnImportShadowing.ts] ////

//// [b.ts]
export const zzz = 123;

//// [a.ts]
import * as B from "./b";

interface B {
x: string;
}

const x: B = { x: "" };
B.zzz;

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;
var B = require("./b");
var x = { x: "" };
B.zzz;
//// [index.js]
"use strict";
exports.__esModule = true;
var x = { x: "" };
B.zzz;
var OriginalB = require("./b");
OriginalB.zzz;
var y = x;
25 changes: 25 additions & 0 deletions tests/cases/compiler/noCrashOnImportShadowing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @filename: b.ts
export const zzz = 123;

// @filename: a.ts
import * as B from "./b";

interface B {
x: string;
}

const x: B = { x: "" };
B.zzz;

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;

0 comments on commit 62eaaf9

Please sign in to comment.