Fix crash when attempting to merge an import with a local declaration (#18032)
* There should be no crash when attempting to merge an import with a local declaration * Show symbol has actually merged within the module
This commit is contained in:
parent
643a7e7e33
commit
62eaaf9206
4 changed files with 106 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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
tests/baselines/reference/noCrashOnImportShadowing.js
Normal file
46
tests/baselines/reference/noCrashOnImportShadowing.js
Normal file
|
@ -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
tests/cases/compiler/noCrashOnImportShadowing.ts
Normal file
25
tests/cases/compiler/noCrashOnImportShadowing.ts
Normal file
|
@ -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;
|
Loading…
Reference in a new issue