mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix: Properly await already evaluating dynamic imports (#9984)
This commit is contained in:
parent
fe027b4a59
commit
1312a57984
5 changed files with 17 additions and 9 deletions
2
cli/tests/088_dynamic_import_already_evaluating.ts
Normal file
2
cli/tests/088_dynamic_import_already_evaluating.ts
Normal 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));
|
4
cli/tests/088_dynamic_import_already_evaluating.ts.out
Normal file
4
cli/tests/088_dynamic_import_already_evaluating.ts.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
[WILDCARD]1
|
||||
2
|
||||
3
|
||||
3
|
3
cli/tests/088_dynamic_import_target.ts
Normal file
3
cli/tests/088_dynamic_import_target.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
console.log(1);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
console.log(2);
|
|
@ -2841,6 +2841,11 @@ console.log("finish");
|
|||
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 {
|
||||
args: "run --quiet --reload js_import_detect.ts",
|
||||
output: "js_import_detect.ts.out",
|
||||
|
|
|
@ -784,15 +784,9 @@ impl JsRuntime {
|
|||
module.get_status()
|
||||
};
|
||||
|
||||
// Since the same module might be dynamically imported more than once,
|
||||
// we short-circuit is it is already evaluated.
|
||||
if status == v8::ModuleStatus::Evaluated {
|
||||
self.dyn_import_done(load_id, id);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if status != v8::ModuleStatus::Instantiated {
|
||||
return Ok(());
|
||||
match status {
|
||||
v8::ModuleStatus::Instantiated | v8::ModuleStatus::Evaluated => {}
|
||||
_ => return Ok(()),
|
||||
}
|
||||
|
||||
// IMPORTANT: Top-level-await is enabled, which means that return value
|
||||
|
|
Loading…
Reference in a new issue