Skip to content

Commit 2a8e8b6

Browse files
Unify tests testing different values of module
1 parent 33f70c0 commit 2a8e8b6

File tree

48 files changed

+595
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+595
-259
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module
77
}
88

99
==== b.ts (1 errors) ====
10-
import.defer("./a").then(ns => {
11-
~~~~~~~~~~~~~~~~~~~
10+
import.defer("./a.js").then(ns => {
11+
~~~~~~~~~~~~~~~~~~~~~~
1212
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
1313
ns.foo();
1414
});
1515

16-
import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
16+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
1717

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
//// [a.ts]
4+
export function foo() {
5+
console.log("foo from a");
6+
}
7+
8+
//// [b.ts]
9+
import.defer("./a.js").then(ns => {
10+
ns.foo();
11+
});
12+
13+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
14+
15+
16+
//// [a.js]
17+
"use strict";
18+
Object.defineProperty(exports, "__esModule", { value: true });
19+
exports.foo = foo;
20+
function foo() {
21+
console.log("foo from a");
22+
}
23+
//// [b.js]
24+
import.defer("./a.js").then(ns => {
25+
ns.foo();
26+
});
27+
Promise.resolve().then(() => require("./a.js")); // TODO: Without this the import.defer cannot resolve ./a

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [tests/cases/conformance/importDefer/dynamicImportDeferModuleNodeNext.ts] ////
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
22

33
=== a.ts ===
44
export function foo() {
@@ -24,6 +24,6 @@ import.defer("./a.js").then(ns => {
2424

2525
});
2626

27-
import("./a.js"); // TODO: Removing this makes the `import.defer` call complain about module not found
27+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
2828
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
2929

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [tests/cases/conformance/importDefer/dynamicImportDeferModuleUnset.ts] ////
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
22

33
=== a.ts ===
44
export function foo() {
@@ -19,19 +19,19 @@ export function foo() {
1919
}
2020

2121
=== b.ts ===
22-
import.defer("./a").then(ns => {
23-
>import.defer("./a").then(ns => { ns.foo();}) : Promise<void>
24-
> : ^^^^^^^^^^^^^
25-
>import.defer("./a").then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
26-
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27-
>import.defer("./a") : Promise<typeof import("a")>
28-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
import.defer("./a.js").then(ns => {
23+
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
24+
> : ^^^^^^^^^^^^^
25+
>import.defer("./a.js").then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
26+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
>import.defer("./a.js") : Promise<typeof import("a")>
28+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2929
>import.defer : any
3030
> : ^^^
3131
>defer : any
3232
> : ^^^
33-
>"./a" : "./a"
34-
> : ^^^^^
33+
>"./a.js" : "./a.js"
34+
> : ^^^^^^^^
3535
>then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
3636
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3737
>ns => { ns.foo();} : (ns: typeof import("a")) => void
@@ -51,9 +51,9 @@ import.defer("./a").then(ns => {
5151

5252
});
5353

54-
import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
55-
>import("./a") : Promise<typeof import("a")>
56-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57-
>"./a" : "./a"
58-
> : ^^^^^
54+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
55+
>import("./a.js") : Promise<typeof import("a")>
56+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
>"./a.js" : "./a.js"
58+
> : ^^^^^^^^
5959

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ b.ts(5,1): error TS1323: Dynamic imports are only supported when the '--module'
88
}
99

1010
==== b.ts (2 errors) ====
11-
import.defer("./a").then(ns => {
12-
~~~~~~~~~~~~~~~~~~~
11+
import.defer("./a.js").then(ns => {
12+
~~~~~~~~~~~~~~~~~~~~~~
1313
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
1414
ns.foo();
1515
});
1616

17-
import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
18-
~~~~~~~~~~~~~
17+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
18+
~~~~~~~~~~~~~~~~
1919
!!! 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'.
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
//// [a.ts]
4+
export function foo() {
5+
console.log("foo from a");
6+
}
7+
8+
//// [b.ts]
9+
import.defer("./a.js").then(ns => {
10+
ns.foo();
11+
});
12+
13+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
14+
15+
16+
//// [a.js]
17+
export function foo() {
18+
console.log("foo from a");
19+
}
20+
//// [b.js]
21+
import.defer("./a.js").then(ns => {
22+
ns.foo();
23+
});
24+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
=== a.ts ===
4+
export function foo() {
5+
>foo : Symbol(foo, Decl(a.ts, 0, 0))
6+
7+
console.log("foo from a");
8+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
9+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
10+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
11+
}
12+
13+
=== b.ts ===
14+
import.defer("./a.js").then(ns => {
15+
>import.defer("./a.js").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
16+
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
17+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
18+
>ns : Symbol(ns, Decl(b.ts, 0, 28))
19+
20+
ns.foo();
21+
>ns.foo : Symbol(foo, Decl(a.ts, 0, 0))
22+
>ns : Symbol(ns, Decl(b.ts, 0, 28))
23+
>foo : Symbol(foo, Decl(a.ts, 0, 0))
24+
25+
});
26+
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/dynamicImportDeferModuleES2020.types tests/baselines/reference/dynamicImportDefer(module=es2015).types

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [tests/cases/conformance/importDefer/dynamicImportDeferModuleES2020.ts] ////
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
22

33
=== a.ts ===
44
export function foo() {
@@ -19,19 +19,19 @@ export function foo() {
1919
}
2020

2121
=== b.ts ===
22-
import.defer("./a").then(ns => {
23-
>import.defer("./a").then(ns => { ns.foo();}) : Promise<void>
24-
> : ^^^^^^^^^^^^^
25-
>import.defer("./a").then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
26-
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27-
>import.defer("./a") : Promise<typeof import("a")>
28-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
import.defer("./a.js").then(ns => {
23+
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
24+
> : ^^^^^^^^^^^^^
25+
>import.defer("./a.js").then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
26+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
>import.defer("./a.js") : Promise<typeof import("a")>
28+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2929
>import.defer : any
3030
> : ^^^
3131
>defer : any
3232
> : ^^^
33-
>"./a" : "./a"
34-
> : ^^^^^
33+
>"./a.js" : "./a.js"
34+
> : ^^^^^^^^
3535
>then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
3636
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3737
>ns => { ns.foo();} : (ns: typeof import("a")) => void
@@ -51,9 +51,9 @@ import.defer("./a").then(ns => {
5151

5252
});
5353

54-
import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
55-
>import("./a") : Promise<typeof import("a")>
56-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57-
>"./a" : "./a"
58-
> : ^^^^^
54+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
55+
>import("./a.js") : Promise<typeof import("a")>
56+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
>"./a.js" : "./a.js"
58+
> : ^^^^^^^^
5959

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
2+
3+
4+
==== a.ts (0 errors) ====
5+
export function foo() {
6+
console.log("foo from a");
7+
}
8+
9+
==== b.ts (1 errors) ====
10+
import.defer("./a.js").then(ns => {
11+
~~~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.
13+
ns.foo();
14+
});
15+
16+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
//// [a.ts]
4+
export function foo() {
5+
console.log("foo from a");
6+
}
7+
8+
//// [b.ts]
9+
import.defer("./a.js").then(ns => {
10+
ns.foo();
11+
});
12+
13+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
14+
15+
16+
//// [a.js]
17+
export function foo() {
18+
console.log("foo from a");
19+
}
20+
//// [b.js]
21+
import.defer("./a.js").then(ns => {
22+
ns.foo();
23+
});
24+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
=== a.ts ===
4+
export function foo() {
5+
>foo : Symbol(foo, Decl(a.ts, 0, 0))
6+
7+
console.log("foo from a");
8+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
9+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
10+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
11+
}
12+
13+
=== b.ts ===
14+
import.defer("./a.js").then(ns => {
15+
>import.defer("./a.js").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
16+
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
17+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
18+
>ns : Symbol(ns, Decl(b.ts, 0, 28))
19+
20+
ns.foo();
21+
>ns.foo : Symbol(foo, Decl(a.ts, 0, 0))
22+
>ns : Symbol(ns, Decl(b.ts, 0, 28))
23+
>foo : Symbol(foo, Decl(a.ts, 0, 0))
24+
25+
});
26+
27+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
28+
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
=== a.ts ===
4+
export function foo() {
5+
>foo : () => void
6+
> : ^^^^^^^^^^
7+
8+
console.log("foo from a");
9+
>console.log("foo from a") : void
10+
> : ^^^^
11+
>console.log : (...data: any[]) => void
12+
> : ^^^^ ^^ ^^^^^
13+
>console : Console
14+
> : ^^^^^^^
15+
>log : (...data: any[]) => void
16+
> : ^^^^ ^^ ^^^^^
17+
>"foo from a" : "foo from a"
18+
> : ^^^^^^^^^^^^
19+
}
20+
21+
=== b.ts ===
22+
import.defer("./a.js").then(ns => {
23+
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
24+
> : ^^^^^^^^^^^^^
25+
>import.defer("./a.js").then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
26+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
>import.defer("./a.js") : Promise<typeof import("a")>
28+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
>import.defer : any
30+
> : ^^^
31+
>defer : any
32+
> : ^^^
33+
>"./a.js" : "./a.js"
34+
> : ^^^^^^^^
35+
>then : <TResult1 = typeof import("a"), TResult2 = never>(onfulfilled?: (value: typeof import("a")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
36+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
>ns => { ns.foo();} : (ns: typeof import("a")) => void
38+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
>ns : typeof import("a")
40+
> : ^^^^^^^^^^^^^^^^^^
41+
42+
ns.foo();
43+
>ns.foo() : void
44+
> : ^^^^
45+
>ns.foo : () => void
46+
> : ^^^^^^^^^^
47+
>ns : typeof import("a")
48+
> : ^^^^^^^^^^^^^^^^^^
49+
>foo : () => void
50+
> : ^^^^^^^^^^
51+
52+
});
53+
54+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
55+
>import("./a.js") : Promise<typeof import("a")>
56+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
>"./a.js" : "./a.js"
58+
> : ^^^^^^^^
59+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////
2+
3+
//// [a.ts]
4+
export function foo() {
5+
console.log("foo from a");
6+
}
7+
8+
//// [b.ts]
9+
import.defer("./a.js").then(ns => {
10+
ns.foo();
11+
});
12+
13+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
14+
15+
16+
//// [a.js]
17+
export function foo() {
18+
console.log("foo from a");
19+
}
20+
//// [b.js]
21+
import.defer("./a.js").then(ns => {
22+
ns.foo();
23+
});
24+
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

0 commit comments

Comments
 (0)