mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
fix(43347): fix crash occurred when export type to existing commonJs imported name (#43369)
This commit is contained in:
@@ -33805,11 +33805,14 @@ namespace ts {
|
||||
case SyntaxKind.SourceFile:
|
||||
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue | DeclarationSpaces.ExportNamespace;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
const node = d as ExportAssignment | BinaryExpression;
|
||||
const expression = isExportAssignment(node) ? node.expression : node.right;
|
||||
// Export assigned entity name expressions act as aliases and should fall through, otherwise they export values
|
||||
if (!isEntityNameExpression((d as ExportAssignment).expression)) {
|
||||
if (!isEntityNameExpression(expression)) {
|
||||
return DeclarationSpaces.ExportValue;
|
||||
}
|
||||
d = (d as ExportAssignment).expression;
|
||||
d = expression;
|
||||
|
||||
// The below options all declare an Alias, which is allowed to merge with other values within the importing module.
|
||||
// falls through
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
tests/cases/compiler/types1.ts(2,17): error TS1110: Type expected.
|
||||
tests/cases/compiler/types1.ts(3,1): error TS1005: '=' expected.
|
||||
tests/cases/compiler/types2.ts(2,19): error TS1110: Type expected.
|
||||
tests/cases/compiler/types3.ts(2,13): error TS2456: Type alias 'test' circularly references itself.
|
||||
|
||||
|
||||
==== tests/cases/compiler/test.js (0 errors) ====
|
||||
module.exports = {
|
||||
message: ""
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/types1.ts (2 errors) ====
|
||||
import test from "./test";
|
||||
export type test
|
||||
|
||||
!!! error TS1110: Type expected.
|
||||
|
||||
|
||||
!!! error TS1005: '=' expected.
|
||||
==== tests/cases/compiler/types2.ts (1 errors) ====
|
||||
import test from "./test";
|
||||
export type test =
|
||||
|
||||
!!! error TS1110: Type expected.
|
||||
|
||||
==== tests/cases/compiler/types3.ts (1 errors) ====
|
||||
import test from "./test";
|
||||
export type test = test;
|
||||
~~~~
|
||||
!!! error TS2456: Type alias 'test' circularly references itself.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//// [tests/cases/compiler/commonJsExportTypeDeclarationError.ts] ////
|
||||
|
||||
//// [test.js]
|
||||
module.exports = {
|
||||
message: ""
|
||||
}
|
||||
|
||||
//// [types1.ts]
|
||||
import test from "./test";
|
||||
export type test
|
||||
|
||||
//// [types2.ts]
|
||||
import test from "./test";
|
||||
export type test =
|
||||
|
||||
//// [types3.ts]
|
||||
import test from "./test";
|
||||
export type test = test;
|
||||
|
||||
|
||||
//// [test.js]
|
||||
module.exports = {
|
||||
message: ""
|
||||
};
|
||||
//// [types1.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//// [types2.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//// [types3.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -0,0 +1,32 @@
|
||||
=== tests/cases/compiler/test.js ===
|
||||
module.exports = {
|
||||
>module.exports : Symbol(module.exports, Decl(test.js, 0, 0))
|
||||
>module : Symbol(export=, Decl(test.js, 0, 0))
|
||||
>exports : Symbol(export=, Decl(test.js, 0, 0))
|
||||
|
||||
message: ""
|
||||
>message : Symbol(message, Decl(test.js, 0, 18))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/types1.ts ===
|
||||
import test from "./test";
|
||||
>test : Symbol(test, Decl(types1.ts, 0, 6), Decl(types1.ts, 0, 26))
|
||||
|
||||
export type test
|
||||
>test : Symbol(test, Decl(types1.ts, 0, 26))
|
||||
|
||||
=== tests/cases/compiler/types2.ts ===
|
||||
import test from "./test";
|
||||
>test : Symbol(test, Decl(types2.ts, 0, 6), Decl(types2.ts, 0, 26))
|
||||
|
||||
export type test =
|
||||
>test : Symbol(test, Decl(types2.ts, 0, 26))
|
||||
|
||||
=== tests/cases/compiler/types3.ts ===
|
||||
import test from "./test";
|
||||
>test : Symbol(test, Decl(types3.ts, 0, 6), Decl(types3.ts, 0, 26))
|
||||
|
||||
export type test = test;
|
||||
>test : Symbol(test, Decl(types3.ts, 0, 26))
|
||||
>test : Symbol(test, Decl(types3.ts, 0, 26))
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/compiler/test.js ===
|
||||
module.exports = {
|
||||
>module.exports = { message: ""} : { message: string; }
|
||||
>module.exports : { message: string; }
|
||||
>module : { exports: { message: string; }; }
|
||||
>exports : { message: string; }
|
||||
>{ message: ""} : { message: string; }
|
||||
|
||||
message: ""
|
||||
>message : string
|
||||
>"" : ""
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/types1.ts ===
|
||||
import test from "./test";
|
||||
>test : { message: string; }
|
||||
|
||||
export type test
|
||||
>test : any
|
||||
|
||||
=== tests/cases/compiler/types2.ts ===
|
||||
import test from "./test";
|
||||
>test : { message: string; }
|
||||
|
||||
export type test =
|
||||
>test : any
|
||||
|
||||
=== tests/cases/compiler/types3.ts ===
|
||||
import test from "./test";
|
||||
>test : { message: string; }
|
||||
|
||||
export type test = test;
|
||||
>test : any
|
||||
|
||||
22
tests/cases/compiler/commonJsExportTypeDeclarationError.ts
Normal file
22
tests/cases/compiler/commonJsExportTypeDeclarationError.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// @esModuleInterop: true
|
||||
// @checkJs: true
|
||||
// @module: commonjs
|
||||
// @target: es5
|
||||
// @outDir: ./out
|
||||
|
||||
// @Filename: ./test.js
|
||||
module.exports = {
|
||||
message: ""
|
||||
}
|
||||
|
||||
// @Filename: ./types1.ts
|
||||
import test from "./test";
|
||||
export type test
|
||||
|
||||
// @Filename: ./types2.ts
|
||||
import test from "./test";
|
||||
export type test =
|
||||
|
||||
// @Filename: ./types3.ts
|
||||
import test from "./test";
|
||||
export type test = test;
|
||||
Reference in New Issue
Block a user