Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when attempting to merge an import with a local declaration #18032

Merged
merged 2 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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;