Add fix for crash in #18712 (#18751)

This commit is contained in:
Wesley Wigham
2017-09-25 13:07:44 -07:00
committed by GitHub
parent b4018a2ef1
commit 8f9724811d
6 changed files with 221 additions and 2 deletions

View File

@@ -19274,10 +19274,11 @@ 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;
// The below options all declare an Alias, which is allowed to merge with other values within the importing module
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.NamespaceImport:
case SyntaxKind.ImportClause:
let result = DeclarationSpaces.None;
const target = resolveAlias(getSymbolOfNode(d));
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });

View File

@@ -0,0 +1,34 @@
tests/cases/compiler/index.ts(4,1): error TS2693: 'zzz' 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 'originalZZZ'.
==== tests/cases/compiler/b.ts (0 errors) ====
export const zzz = 123;
export default zzz;
==== tests/cases/compiler/a.ts (0 errors) ====
export default interface zzz {
x: string;
}
import zzz from "./b";
const x: zzz = { x: "" };
zzz;
export { zzz as default };
==== tests/cases/compiler/index.ts (2 errors) ====
import zzz from "./a";
const x: zzz = { x: "" };
zzz;
~~~
!!! error TS2693: 'zzz' only refers to a type, but is being used as a value here.
import originalZZZ from "./b";
originalZZZ;
const y: originalZZZ = x;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'originalZZZ'.

View File

@@ -0,0 +1,49 @@
//// [tests/cases/compiler/allowImportClausesToMergeWithTypes.ts] ////
//// [b.ts]
export const zzz = 123;
export default zzz;
//// [a.ts]
export default interface zzz {
x: string;
}
import zzz from "./b";
const x: zzz = { x: "" };
zzz;
export { zzz as default };
//// [index.ts]
import zzz from "./a";
const x: zzz = { x: "" };
zzz;
import originalZZZ from "./b";
originalZZZ;
const y: originalZZZ = x;
//// [b.js]
"use strict";
exports.__esModule = true;
exports.zzz = 123;
exports["default"] = exports.zzz;
//// [a.js]
"use strict";
exports.__esModule = true;
var b_1 = require("./b");
exports["default"] = b_1["default"];
var x = { x: "" };
b_1["default"];
//// [index.js]
"use strict";
exports.__esModule = true;
var x = { x: "" };
zzz;
var b_1 = require("./b");
b_1["default"];
var y = x;

View File

@@ -0,0 +1,51 @@
=== tests/cases/compiler/b.ts ===
export const zzz = 123;
>zzz : Symbol(zzz, Decl(b.ts, 0, 12))
export default zzz;
>zzz : Symbol(zzz, Decl(b.ts, 0, 12))
=== tests/cases/compiler/a.ts ===
export default interface zzz {
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
x: string;
>x : Symbol(zzz.x, Decl(a.ts, 0, 30))
}
import zzz from "./b";
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 4, 6))
const x: zzz = { x: "" };
>x : Symbol(x, Decl(a.ts, 6, 5))
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
>x : Symbol(x, Decl(a.ts, 6, 16))
zzz;
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 4, 6))
export { zzz as default };
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
>default : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
=== tests/cases/compiler/index.ts ===
import zzz from "./a";
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))
const x: zzz = { x: "" };
>x : Symbol(x, Decl(index.ts, 2, 5))
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))
>x : Symbol(x, Decl(index.ts, 2, 16))
zzz;
import originalZZZ from "./b";
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))
originalZZZ;
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))
const y: originalZZZ = x;
>y : Symbol(y, Decl(index.ts, 8, 5))
>x : Symbol(x, Decl(index.ts, 2, 5))

View File

@@ -0,0 +1,58 @@
=== tests/cases/compiler/b.ts ===
export const zzz = 123;
>zzz : 123
>123 : 123
export default zzz;
>zzz : 123
=== tests/cases/compiler/a.ts ===
export default interface zzz {
>zzz : zzz
x: string;
>x : string
}
import zzz from "./b";
>zzz : 123
const x: zzz = { x: "" };
>x : zzz
>zzz : zzz
>{ x: "" } : { x: string; }
>x : string
>"" : ""
zzz;
>zzz : 123
export { zzz as default };
>zzz : 123
>default : 123
=== tests/cases/compiler/index.ts ===
import zzz from "./a";
>zzz : any
const x: zzz = { x: "" };
>x : zzz
>zzz : zzz
>{ x: "" } : { x: string; }
>x : string
>"" : ""
zzz;
>zzz : any
import originalZZZ from "./b";
>originalZZZ : 123
originalZZZ;
>originalZZZ : 123
const y: originalZZZ = x;
>y : any
>originalZZZ : No type information available!
>x : zzz

View File

@@ -0,0 +1,26 @@
// @filename: b.ts
export const zzz = 123;
export default zzz;
// @filename: a.ts
export default interface zzz {
x: string;
}
import zzz from "./b";
const x: zzz = { x: "" };
zzz;
export { zzz as default };
// @filename: index.ts
import zzz from "./a";
const x: zzz = { x: "" };
zzz;
import originalZZZ from "./b";
originalZZZ;
const y: originalZZZ = x;