Skip to content

Commit 8f97248

Browse files
authored
Add fix for crash in #18712 (#18751)
1 parent b4018a2 commit 8f97248

6 files changed

+221
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19274,10 +19274,11 @@ namespace ts {
1927419274
: DeclarationSpaces.ExportNamespace;
1927519275
case SyntaxKind.ClassDeclaration:
1927619276
case SyntaxKind.EnumDeclaration:
19277-
// A NamespaceImport declares an Alias, which is allowed to merge with other values within the module
19278-
case SyntaxKind.NamespaceImport:
1927919277
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
19278+
// The below options all declare an Alias, which is allowed to merge with other values within the importing module
1928019279
case SyntaxKind.ImportEqualsDeclaration:
19280+
case SyntaxKind.NamespaceImport:
19281+
case SyntaxKind.ImportClause:
1928119282
let result = DeclarationSpaces.None;
1928219283
const target = resolveAlias(getSymbolOfNode(d));
1928319284
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/compiler/index.ts(4,1): error TS2693: 'zzz' only refers to a type, but is being used as a value here.
2+
tests/cases/compiler/index.ts(9,10): error TS2304: Cannot find name 'originalZZZ'.
3+
4+
5+
==== tests/cases/compiler/b.ts (0 errors) ====
6+
export const zzz = 123;
7+
export default zzz;
8+
9+
==== tests/cases/compiler/a.ts (0 errors) ====
10+
export default interface zzz {
11+
x: string;
12+
}
13+
14+
import zzz from "./b";
15+
16+
const x: zzz = { x: "" };
17+
zzz;
18+
19+
export { zzz as default };
20+
21+
==== tests/cases/compiler/index.ts (2 errors) ====
22+
import zzz from "./a";
23+
24+
const x: zzz = { x: "" };
25+
zzz;
26+
~~~
27+
!!! error TS2693: 'zzz' only refers to a type, but is being used as a value here.
28+
29+
import originalZZZ from "./b";
30+
originalZZZ;
31+
32+
const y: originalZZZ = x;
33+
~~~~~~~~~~~
34+
!!! error TS2304: Cannot find name 'originalZZZ'.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [tests/cases/compiler/allowImportClausesToMergeWithTypes.ts] ////
2+
3+
//// [b.ts]
4+
export const zzz = 123;
5+
export default zzz;
6+
7+
//// [a.ts]
8+
export default interface zzz {
9+
x: string;
10+
}
11+
12+
import zzz from "./b";
13+
14+
const x: zzz = { x: "" };
15+
zzz;
16+
17+
export { zzz as default };
18+
19+
//// [index.ts]
20+
import zzz from "./a";
21+
22+
const x: zzz = { x: "" };
23+
zzz;
24+
25+
import originalZZZ from "./b";
26+
originalZZZ;
27+
28+
const y: originalZZZ = x;
29+
30+
//// [b.js]
31+
"use strict";
32+
exports.__esModule = true;
33+
exports.zzz = 123;
34+
exports["default"] = exports.zzz;
35+
//// [a.js]
36+
"use strict";
37+
exports.__esModule = true;
38+
var b_1 = require("./b");
39+
exports["default"] = b_1["default"];
40+
var x = { x: "" };
41+
b_1["default"];
42+
//// [index.js]
43+
"use strict";
44+
exports.__esModule = true;
45+
var x = { x: "" };
46+
zzz;
47+
var b_1 = require("./b");
48+
b_1["default"];
49+
var y = x;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/compiler/b.ts ===
2+
export const zzz = 123;
3+
>zzz : Symbol(zzz, Decl(b.ts, 0, 12))
4+
5+
export default zzz;
6+
>zzz : Symbol(zzz, Decl(b.ts, 0, 12))
7+
8+
=== tests/cases/compiler/a.ts ===
9+
export default interface zzz {
10+
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
11+
12+
x: string;
13+
>x : Symbol(zzz.x, Decl(a.ts, 0, 30))
14+
}
15+
16+
import zzz from "./b";
17+
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 4, 6))
18+
19+
const x: zzz = { x: "" };
20+
>x : Symbol(x, Decl(a.ts, 6, 5))
21+
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
22+
>x : Symbol(x, Decl(a.ts, 6, 16))
23+
24+
zzz;
25+
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 4, 6))
26+
27+
export { zzz as default };
28+
>zzz : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
29+
>default : Symbol(zzz, Decl(a.ts, 0, 0), Decl(a.ts, 9, 8))
30+
31+
=== tests/cases/compiler/index.ts ===
32+
import zzz from "./a";
33+
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))
34+
35+
const x: zzz = { x: "" };
36+
>x : Symbol(x, Decl(index.ts, 2, 5))
37+
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))
38+
>x : Symbol(x, Decl(index.ts, 2, 16))
39+
40+
zzz;
41+
42+
import originalZZZ from "./b";
43+
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))
44+
45+
originalZZZ;
46+
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))
47+
48+
const y: originalZZZ = x;
49+
>y : Symbol(y, Decl(index.ts, 8, 5))
50+
>x : Symbol(x, Decl(index.ts, 2, 5))
51+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
=== tests/cases/compiler/b.ts ===
2+
export const zzz = 123;
3+
>zzz : 123
4+
>123 : 123
5+
6+
export default zzz;
7+
>zzz : 123
8+
9+
=== tests/cases/compiler/a.ts ===
10+
export default interface zzz {
11+
>zzz : zzz
12+
13+
x: string;
14+
>x : string
15+
}
16+
17+
import zzz from "./b";
18+
>zzz : 123
19+
20+
const x: zzz = { x: "" };
21+
>x : zzz
22+
>zzz : zzz
23+
>{ x: "" } : { x: string; }
24+
>x : string
25+
>"" : ""
26+
27+
zzz;
28+
>zzz : 123
29+
30+
export { zzz as default };
31+
>zzz : 123
32+
>default : 123
33+
34+
=== tests/cases/compiler/index.ts ===
35+
import zzz from "./a";
36+
>zzz : any
37+
38+
const x: zzz = { x: "" };
39+
>x : zzz
40+
>zzz : zzz
41+
>{ x: "" } : { x: string; }
42+
>x : string
43+
>"" : ""
44+
45+
zzz;
46+
>zzz : any
47+
48+
import originalZZZ from "./b";
49+
>originalZZZ : 123
50+
51+
originalZZZ;
52+
>originalZZZ : 123
53+
54+
const y: originalZZZ = x;
55+
>y : any
56+
>originalZZZ : No type information available!
57+
>x : zzz
58+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @filename: b.ts
2+
export const zzz = 123;
3+
export default zzz;
4+
5+
// @filename: a.ts
6+
export default interface zzz {
7+
x: string;
8+
}
9+
10+
import zzz from "./b";
11+
12+
const x: zzz = { x: "" };
13+
zzz;
14+
15+
export { zzz as default };
16+
17+
// @filename: index.ts
18+
import zzz from "./a";
19+
20+
const x: zzz = { x: "" };
21+
zzz;
22+
23+
import originalZZZ from "./b";
24+
originalZZZ;
25+
26+
const y: originalZZZ = x;

0 commit comments

Comments
 (0)