Skip to content

Commit 503ea95

Browse files
authored
fix(4122): preserve import.defer in CommonJS emit (#4149)
1 parent 704847d commit 503ea95

6 files changed

Lines changed: 62 additions & 1 deletion

File tree

internal/ast/ast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ func (node *NewExpression) propagateSubtreeFacts() SubtreeFacts {
21512151
}
21522152

21532153
func (node *MetaProperty) computeSubtreeFacts() SubtreeFacts {
2154-
return propagateSubtreeFacts(node.name)
2154+
return propagateSubtreeFacts(node.name) &^ SubtreeContainsIdentifier
21552155
}
21562156

21572157
func (node *NonNullExpression) computeSubtreeFacts() SubtreeFacts {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
main.ts(2,1): error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'preserve'.
2+
3+
4+
==== a.ts (0 errors) ====
5+
export {};
6+
7+
==== main.ts (1 errors) ====
8+
export {};
9+
import.defer("./a");
10+
~~~~~~~~~~~~~~~~~~~
11+
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'preserve'.
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/compiler/importDeferCallCommonJS.ts] ////
2+
3+
//// [a.ts]
4+
export {};
5+
6+
//// [main.ts]
7+
export {};
8+
import.defer("./a");
9+
10+
11+
//// [a.js]
12+
"use strict";
13+
Object.defineProperty(exports, "__esModule", { value: true });
14+
//// [main.js]
15+
"use strict";
16+
Object.defineProperty(exports, "__esModule", { value: true });
17+
import.defer("./a");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/importDeferCallCommonJS.ts] ////
2+
3+
=== a.ts ===
4+
5+
export {};
6+
7+
=== main.ts ===
8+
export {};
9+
import.defer("./a");
10+
>"./a" : Symbol("./a", Decl(a.ts, 0, 0))
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/importDeferCallCommonJS.ts] ////
2+
3+
=== a.ts ===
4+
5+
export {};
6+
7+
=== main.ts ===
8+
export {};
9+
import.defer("./a");
10+
>import.defer("./a") : Promise<typeof import("./a")>
11+
>defer : any
12+
>"./a" : "./a"
13+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: commonjs
2+
3+
// @filename: a.ts
4+
export {};
5+
6+
// @filename: main.ts
7+
export {};
8+
import.defer("./a");

0 commit comments

Comments
 (0)