Skip to content

Commit

Permalink
Unify tests testing different values of module
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 17, 2025
1 parent 33f70c0 commit 2a8e8b6
Show file tree
Hide file tree
Showing 48 changed files with 595 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module
}

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

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

27 changes: 27 additions & 0 deletions tests/baselines/reference/dynamicImportDefer(module=commonjs).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

//// [a.ts]
export function foo() {
console.log("foo from a");
}

//// [b.ts]
import.defer("./a.js").then(ns => {
ns.foo();
});

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a


//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = foo;
function foo() {
console.log("foo from a");
}
//// [b.js]
import.defer("./a.js").then(ns => {
ns.foo();
});
Promise.resolve().then(() => require("./a.js")); // TODO: Without this the import.defer cannot resolve ./a
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/importDefer/dynamicImportDeferModuleNodeNext.ts] ////
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

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

});

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

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

=== a.ts ===
export function foo() {
Expand All @@ -19,19 +19,19 @@ export function foo() {
}

=== b.ts ===
import.defer("./a").then(ns => {
>import.defer("./a").then(ns => { ns.foo();}) : Promise<void>
> : ^^^^^^^^^^^^^
>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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer("./a") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
import.defer("./a.js").then(ns => {
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
> : ^^^^^^^^^^^^^
>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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer : any
> : ^^^
>defer : any
> : ^^^
>"./a" : "./a"
> : ^^^^^
>"./a.js" : "./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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ns => { ns.foo();} : (ns: typeof import("a")) => void
Expand All @@ -51,9 +51,9 @@ import.defer("./a").then(ns => {

});

import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
>import("./a") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"./a" : "./a"
> : ^^^^^
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
>import("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"./a.js" : "./a.js"
> : ^^^^^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ b.ts(5,1): error TS1323: Dynamic imports are only supported when the '--module'
}

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

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

24 changes: 24 additions & 0 deletions tests/baselines/reference/dynamicImportDefer(module=es2015).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

//// [a.ts]
export function foo() {
console.log("foo from a");
}

//// [b.ts]
import.defer("./a.js").then(ns => {
ns.foo();
});

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a


//// [a.js]
export function foo() {
console.log("foo from a");
}
//// [b.js]
import.defer("./a.js").then(ns => {
ns.foo();
});
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

=== a.ts ===
export function foo() {
>foo : Symbol(foo, Decl(a.ts, 0, 0))

console.log("foo from a");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}

=== b.ts ===
import.defer("./a.js").then(ns => {
>import.defer("./a.js").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>ns : Symbol(ns, Decl(b.ts, 0, 28))

ns.foo();
>ns.foo : Symbol(foo, Decl(a.ts, 0, 0))
>ns : Symbol(ns, Decl(b.ts, 0, 28))
>foo : Symbol(foo, Decl(a.ts, 0, 0))

});

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

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

=== a.ts ===
export function foo() {
Expand All @@ -19,19 +19,19 @@ export function foo() {
}

=== b.ts ===
import.defer("./a").then(ns => {
>import.defer("./a").then(ns => { ns.foo();}) : Promise<void>
> : ^^^^^^^^^^^^^
>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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer("./a") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
import.defer("./a.js").then(ns => {
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
> : ^^^^^^^^^^^^^
>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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer : any
> : ^^^
>defer : any
> : ^^^
>"./a" : "./a"
> : ^^^^^
>"./a.js" : "./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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ns => { ns.foo();} : (ns: typeof import("a")) => void
Expand All @@ -51,9 +51,9 @@ import.defer("./a").then(ns => {

});

import("./a"); // TODO: Removing this makes the `import.defer` call complain about module not found
>import("./a") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"./a" : "./a"
> : ^^^^^
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
>import("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"./a.js" : "./a.js"
> : ^^^^^^^^

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
b.ts(1,1): error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext' or 'nodenext'.


==== a.ts (0 errors) ====
export function foo() {
console.log("foo from a");
}

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

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a

24 changes: 24 additions & 0 deletions tests/baselines/reference/dynamicImportDefer(module=es2020).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

//// [a.ts]
export function foo() {
console.log("foo from a");
}

//// [b.ts]
import.defer("./a.js").then(ns => {
ns.foo();
});

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a


//// [a.js]
export function foo() {
console.log("foo from a");
}
//// [b.js]
import.defer("./a.js").then(ns => {
ns.foo();
});
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

=== a.ts ===
export function foo() {
>foo : Symbol(foo, Decl(a.ts, 0, 0))

console.log("foo from a");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}

=== b.ts ===
import.defer("./a.js").then(ns => {
>import.defer("./a.js").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>"./a.js" : Symbol("a", Decl(a.ts, 0, 0))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>ns : Symbol(ns, Decl(b.ts, 0, 28))

ns.foo();
>ns.foo : Symbol(foo, Decl(a.ts, 0, 0))
>ns : Symbol(ns, Decl(b.ts, 0, 28))
>foo : Symbol(foo, Decl(a.ts, 0, 0))

});

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

59 changes: 59 additions & 0 deletions tests/baselines/reference/dynamicImportDefer(module=es2020).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

=== a.ts ===
export function foo() {
>foo : () => void
> : ^^^^^^^^^^

console.log("foo from a");
>console.log("foo from a") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"foo from a" : "foo from a"
> : ^^^^^^^^^^^^
}

=== b.ts ===
import.defer("./a.js").then(ns => {
>import.defer("./a.js").then(ns => { ns.foo();}) : Promise<void>
> : ^^^^^^^^^^^^^
>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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import.defer : any
> : ^^^
>defer : any
> : ^^^
>"./a.js" : "./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>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ns => { ns.foo();} : (ns: typeof import("a")) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ns : typeof import("a")
> : ^^^^^^^^^^^^^^^^^^

ns.foo();
>ns.foo() : void
> : ^^^^
>ns.foo : () => void
> : ^^^^^^^^^^
>ns : typeof import("a")
> : ^^^^^^^^^^^^^^^^^^
>foo : () => void
> : ^^^^^^^^^^

});

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
>import("./a.js") : Promise<typeof import("a")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"./a.js" : "./a.js"
> : ^^^^^^^^

24 changes: 24 additions & 0 deletions tests/baselines/reference/dynamicImportDefer(module=esnext).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [tests/cases/conformance/importDefer/dynamicImportDefer.ts] ////

//// [a.ts]
export function foo() {
console.log("foo from a");
}

//// [b.ts]
import.defer("./a.js").then(ns => {
ns.foo();
});

import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a


//// [a.js]
export function foo() {
console.log("foo from a");
}
//// [b.js]
import.defer("./a.js").then(ns => {
ns.foo();
});
import("./a.js"); // TODO: Without this the import.defer cannot resolve ./a
Loading

0 comments on commit 2a8e8b6

Please sign in to comment.