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 <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
bmeck authored and MylesBorins committed Mar 6, 2018
1 parent a243961 commit bc1038a
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 bc1038a

Please sign in to comment.