summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorAndreu Botella <andreu@andreubotella.com>2022-06-25 20:56:29 +0200
committerGitHub <noreply@github.com>2022-06-25 20:56:29 +0200
commit38505db39137f33bfdb942658ea892a617ac0980 (patch)
treedd8a03dc9e8bcb436f78f8e9a0c91f9be958e083 /cli
parent18c9a7ad641302a9f5e0ccb07da732890f8e0505 (diff)
fix(modules): Immediately resolve follow-up dyn imports to a dyn imported module (#14958)
When a dynamically imported module gets resolved, any code that comes after an await import() to that module will continue running. However, if that is the last code in the evaluation of another dynamically imported module, that second module will not resolve until the next iteration of the event loop, even though it does not depend on the event loop at all. When the event loop is being blocked by a long-running operation, such as a long-running timer, or by an async op that might never end, such as with workers or BroadcastChannels, that will result in the second dynamically imported module not being resolved for a while, or ever. This change fixes this by running the dynamic module loading steps in a loop until no more dynamic modules can be resolved.
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/integration/run_tests.rs5
-rw-r--r--cli/tests/testdata/followup_dyn_import_resolves/main.ts14
-rw-r--r--cli/tests/testdata/followup_dyn_import_resolves/main.ts.out3
-rw-r--r--cli/tests/testdata/followup_dyn_import_resolves/sub1.ts2
-rw-r--r--cli/tests/testdata/followup_dyn_import_resolves/sub2.ts1
5 files changed, 25 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 09a1ba500..bd27cd8dd 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2733,3 +2733,8 @@ itest!(test_and_bench_are_noops_in_run {
args: "run test_and_bench_in_run.js",
output_str: Some(""),
});
+
+itest!(followup_dyn_import_resolved {
+ args: "run --unstable --allow-read followup_dyn_import_resolves/main.ts",
+ output: "followup_dyn_import_resolves/main.ts.out",
+});
diff --git a/cli/tests/testdata/followup_dyn_import_resolves/main.ts b/cli/tests/testdata/followup_dyn_import_resolves/main.ts
new file mode 100644
index 000000000..a8508f942
--- /dev/null
+++ b/cli/tests/testdata/followup_dyn_import_resolves/main.ts
@@ -0,0 +1,14 @@
+// https://github.com/denoland/deno/issues/14726
+
+// Any dynamic modules that are only pending on a TLA import should be resolved
+// in the same event loop iteration as the imported module.
+
+// Long-running timer so the event loop doesn't have a next iteration for a
+// while.
+setTimeout(() => {}, 24 * 60 * 60 * 1000);
+
+await import("./sub1.ts");
+
+// If we reach here, the test is passed.
+console.log("Done.");
+Deno.exit();
diff --git a/cli/tests/testdata/followup_dyn_import_resolves/main.ts.out b/cli/tests/testdata/followup_dyn_import_resolves/main.ts.out
new file mode 100644
index 000000000..a19976d4a
--- /dev/null
+++ b/cli/tests/testdata/followup_dyn_import_resolves/main.ts.out
@@ -0,0 +1,3 @@
+sub2
+sub1
+Done.
diff --git a/cli/tests/testdata/followup_dyn_import_resolves/sub1.ts b/cli/tests/testdata/followup_dyn_import_resolves/sub1.ts
new file mode 100644
index 000000000..d06c30221
--- /dev/null
+++ b/cli/tests/testdata/followup_dyn_import_resolves/sub1.ts
@@ -0,0 +1,2 @@
+await import("./sub2.ts");
+console.log("sub1");
diff --git a/cli/tests/testdata/followup_dyn_import_resolves/sub2.ts b/cli/tests/testdata/followup_dyn_import_resolves/sub2.ts
new file mode 100644
index 000000000..cce2b524c
--- /dev/null
+++ b/cli/tests/testdata/followup_dyn_import_resolves/sub2.ts
@@ -0,0 +1 @@
+console.log("sub2");