Skip to content

Commit

Permalink
module: fix cyclical dynamic import
Browse files Browse the repository at this point in the history
ensures that instantiation result is only used during initial loading

PR-URL: #18965
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
bmeck authored and MylesBorins committed Mar 7, 2018
1 parent 4b34b2e commit 95f6467
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/loader/ModuleJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class ModuleJob {
}

async instantiate() {
if (this.instantiated) {
return this.instantiated;
if (!this.instantiated) {
return this.instantiated = this._instantiate();
}
return this.instantiated = this._instantiate();
await this.instantiated;
return this.module;
}

// This method instantiates the module associated with this job and its
Expand Down
3 changes: 3 additions & 0 deletions test/es-module/test-esm-cyclic-dynamic-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Flags: --experimental-modules
import '../common';
import('./test-esm-cyclic-dynamic-import');

0 comments on commit 95f6467

Please sign in to comment.