Skip to content

Commit a39ae1f

Browse files
authored
Fix crash when attempting to merge an import with a local declaration (#18032) (#18034)
* There should be no crash when attempting to merge an import with a local declaration * Show symbol has actually merged within the module
1 parent 350c9f6 commit a39ae1f

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19126,6 +19126,8 @@ namespace ts {
1912619126
: DeclarationSpaces.ExportNamespace;
1912719127
case SyntaxKind.ClassDeclaration:
1912819128
case SyntaxKind.EnumDeclaration:
19129+
// A NamespaceImport declares an Alias, which is allowed to merge with other values within the module
19130+
case SyntaxKind.NamespaceImport:
1912919131
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
1913019132
case SyntaxKind.ImportEqualsDeclaration:
1913119133
let result = DeclarationSpaces.None;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
tests/cases/compiler/index.ts(4,1): error TS2693: 'B' 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 'OriginalB'.
3+
4+
5+
==== tests/cases/compiler/b.ts (0 errors) ====
6+
export const zzz = 123;
7+
8+
==== tests/cases/compiler/a.ts (0 errors) ====
9+
import * as B from "./b";
10+
11+
interface B {
12+
x: string;
13+
}
14+
15+
const x: B = { x: "" };
16+
B.zzz;
17+
18+
export { B };
19+
20+
==== tests/cases/compiler/index.ts (2 errors) ====
21+
import { B } from "./a";
22+
23+
const x: B = { x: "" };
24+
B.zzz;
25+
~
26+
!!! error TS2693: 'B' only refers to a type, but is being used as a value here.
27+
28+
import * as OriginalB from "./b";
29+
OriginalB.zzz;
30+
31+
const y: OriginalB = x;
32+
~~~~~~~~~
33+
!!! error TS2304: Cannot find name 'OriginalB'.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tests/cases/compiler/noCrashOnImportShadowing.ts] ////
2+
3+
//// [b.ts]
4+
export const zzz = 123;
5+
6+
//// [a.ts]
7+
import * as B from "./b";
8+
9+
interface B {
10+
x: string;
11+
}
12+
13+
const x: B = { x: "" };
14+
B.zzz;
15+
16+
export { B };
17+
18+
//// [index.ts]
19+
import { B } from "./a";
20+
21+
const x: B = { x: "" };
22+
B.zzz;
23+
24+
import * as OriginalB from "./b";
25+
OriginalB.zzz;
26+
27+
const y: OriginalB = x;
28+
29+
//// [b.js]
30+
"use strict";
31+
exports.__esModule = true;
32+
exports.zzz = 123;
33+
//// [a.js]
34+
"use strict";
35+
exports.__esModule = true;
36+
var B = require("./b");
37+
var x = { x: "" };
38+
B.zzz;
39+
//// [index.js]
40+
"use strict";
41+
exports.__esModule = true;
42+
var x = { x: "" };
43+
B.zzz;
44+
var OriginalB = require("./b");
45+
OriginalB.zzz;
46+
var y = x;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @filename: b.ts
2+
export const zzz = 123;
3+
4+
// @filename: a.ts
5+
import * as B from "./b";
6+
7+
interface B {
8+
x: string;
9+
}
10+
11+
const x: B = { x: "" };
12+
B.zzz;
13+
14+
export { B };
15+
16+
// @filename: index.ts
17+
import { B } from "./a";
18+
19+
const x: B = { x: "" };
20+
B.zzz;
21+
22+
import * as OriginalB from "./b";
23+
OriginalB.zzz;
24+
25+
const y: OriginalB = x;

0 commit comments

Comments
 (0)