Skip to content

Commit 7b17c31

Browse files
Properly resolve specifiers in import.defer(...)
1 parent e787ee5 commit 7b17c31

20 files changed

+2
-73
lines changed

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12074,7 +12074,7 @@ export function forEachDynamicImportOrRequireCall<IncludeTypeSpaceImports extend
1207412074
cb: (node: CallExpression | (IncludeTypeSpaceImports extends false ? never : JSDocImportTag | ImportTypeNode), argument: RequireStringLiteralLikeArgument extends true ? StringLiteralLike : Expression) => void,
1207512075
): void {
1207612076
const isJavaScriptFile = isInJSFile(file);
12077-
const r = /import|require/g;
12077+
const r = /import|defer|require/g;
1207812078
while (r.exec(file.text) !== null) { // eslint-disable-line no-restricted-syntax
1207912079
const node = getNodeAtPosition(file, r.lastIndex, /*includeJSDoc*/ includeTypeSpaceImports);
1208012080
if (isJavaScriptFile && isRequireCall(node, requireStringLiteralLikeArgument)) {

tests/baselines/reference/dynamicImportDefer(module=commonjs).errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module
1212
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
1313
ns.foo();
1414
});
15-
16-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1715

tests/baselines/reference/dynamicImportDefer(module=commonjs).js

-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export function foo() {
99
import.defer("./a.js").then(ns => {
1010
ns.foo();
1111
});
12-
13-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1412

1513

1614
//// [a.js]
@@ -24,4 +22,3 @@ function foo() {
2422
import.defer("./a.js").then(ns => {
2523
ns.foo();
2624
});
27-
Promise.resolve().then(() => require("./a.js")); // TODO: Without this the import.defer cannot resolve ./a

tests/baselines/reference/dynamicImportDefer(module=commonjs).symbols

-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28-
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29-

tests/baselines/reference/dynamicImportDefer(module=commonjs).types

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ import.defer("./a.js").then(ns => {
4949

5050
});
5151

52-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
53-
>import("./a.js") : Promise<typeof import("a")>
54-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
>"./a.js" : "./a.js"
56-
> : ^^^^^^^^
57-
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
2-
b.ts(5,1): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', 'node18', or 'nodenext'.
32

43

54
==== a.ts (0 errors) ====
65
export function foo() {
76
console.log("foo from a");
87
}
98

10-
==== b.ts (2 errors) ====
9+
==== b.ts (1 errors) ====
1110
import.defer("./a.js").then(ns => {
1211
~~~~~~~~~~~~~~~~~~~~~~
1312
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
1413
ns.foo();
1514
});
16-
17-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
18-
~~~~~~~~~~~~~~~~
19-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', 'node18', or 'nodenext'.
2015

tests/baselines/reference/dynamicImportDefer(module=es2015).js

-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export function foo() {
99
import.defer("./a.js").then(ns => {
1010
ns.foo();
1111
});
12-
13-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1412

1513

1614
//// [a.js]
@@ -21,4 +19,3 @@ export function foo() {
2119
import.defer("./a.js").then(ns => {
2220
ns.foo();
2321
});
24-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

tests/baselines/reference/dynamicImportDefer(module=es2015).symbols

-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28-
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29-

tests/baselines/reference/dynamicImportDefer(module=es2015).types

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ import.defer("./a.js").then(ns => {
4949

5050
});
5151

52-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
53-
>import("./a.js") : Promise<typeof import("a")>
54-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
>"./a.js" : "./a.js"
56-
> : ^^^^^^^^
57-

tests/baselines/reference/dynamicImportDefer(module=es2020).errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module
1212
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
1313
ns.foo();
1414
});
15-
16-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1715

tests/baselines/reference/dynamicImportDefer(module=es2020).js

-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export function foo() {
99
import.defer("./a.js").then(ns => {
1010
ns.foo();
1111
});
12-
13-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1412

1513

1614
//// [a.js]
@@ -21,4 +19,3 @@ export function foo() {
2119
import.defer("./a.js").then(ns => {
2220
ns.foo();
2321
});
24-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

tests/baselines/reference/dynamicImportDefer(module=es2020).symbols

-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28-
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29-

tests/baselines/reference/dynamicImportDefer(module=es2020).types

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ import.defer("./a.js").then(ns => {
4949

5050
});
5151

52-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
53-
>import("./a.js") : Promise<typeof import("a")>
54-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
>"./a.js" : "./a.js"
56-
> : ^^^^^^^^
57-

tests/baselines/reference/dynamicImportDefer(module=esnext).js

-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export function foo() {
99
import.defer("./a.js").then(ns => {
1010
ns.foo();
1111
});
12-
13-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1412

1513

1614
//// [a.js]
@@ -21,4 +19,3 @@ export function foo() {
2119
import.defer("./a.js").then(ns => {
2220
ns.foo();
2321
});
24-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

tests/baselines/reference/dynamicImportDefer(module=esnext).symbols

-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28-
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29-

tests/baselines/reference/dynamicImportDefer(module=esnext).types

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ import.defer("./a.js").then(ns => {
4949

5050
});
5151

52-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
53-
>import("./a.js") : Promise<typeof import("a")>
54-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
>"./a.js" : "./a.js"
56-
> : ^^^^^^^^
57-

tests/baselines/reference/dynamicImportDefer(module=nodenext).js

-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export function foo() {
99
import.defer("./a.js").then(ns => {
1010
ns.foo();
1111
});
12-
13-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1412

1513

1614
//// [a.js]
@@ -26,4 +24,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
2624
import.defer("./a.js").then(ns => {
2725
ns.foo();
2826
});
29-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

tests/baselines/reference/dynamicImportDefer(module=nodenext).symbols

-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28-
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29-

tests/baselines/reference/dynamicImportDefer(module=nodenext).types

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ import.defer("./a.js").then(ns => {
4949

5050
});
5151

52-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
53-
>import("./a.js") : Promise<{ default: typeof import("a"); foo(): void; }>
54-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
>"./a.js" : "./a.js"
56-
> : ^^^^^^^^
57-

tests/cases/conformance/importDefer/dynamicImportDefer.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ export function foo() {
1010
import.defer("./a.js").then(ns => {
1111
ns.foo();
1212
});
13-
14-
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

0 commit comments

Comments
 (0)