1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix: Properly await already evaluating dynamic imports (#9984)

This commit is contained in:
Nayeem Rahman 2021-04-04 12:26:00 +01:00 committed by GitHub
parent fe027b4a59
commit 1312a57984
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 9 deletions

View file

@ -0,0 +1,2 @@
import("./088_dynamic_import_target.ts").then(() => console.log(3));
import("./088_dynamic_import_target.ts").then(() => console.log(3));

View file

@ -0,0 +1,4 @@
[WILDCARD]1
2
3
3

View file

@ -0,0 +1,3 @@
console.log(1);
await new Promise((r) => setTimeout(r, 100));
console.log(2);

View file

@ -2841,6 +2841,11 @@ console.log("finish");
output: "087_no_check_imports_not_used_as_values.ts.out", output: "087_no_check_imports_not_used_as_values.ts.out",
}); });
itest!(_088_dynamic_import_already_evaluating {
args: "run --allow-read 088_dynamic_import_already_evaluating.ts",
output: "088_dynamic_import_already_evaluating.ts.out",
});
itest!(js_import_detect { itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts", args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out", output: "js_import_detect.ts.out",

View file

@ -784,15 +784,9 @@ impl JsRuntime {
module.get_status() module.get_status()
}; };
// Since the same module might be dynamically imported more than once, match status {
// we short-circuit is it is already evaluated. v8::ModuleStatus::Instantiated | v8::ModuleStatus::Evaluated => {}
if status == v8::ModuleStatus::Evaluated { _ => return Ok(()),
self.dyn_import_done(load_id, id);
return Ok(());
}
if status != v8::ModuleStatus::Instantiated {
return Ok(());
} }
// IMPORTANT: Top-level-await is enabled, which means that return value // IMPORTANT: Top-level-await is enabled, which means that return value