Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,14 @@
throw this.module.getError();
}
if (status > kInstantiated) {
// Already evaluated (e.g. previously require()'d and now import()'d again).
if (this.evaluationPromise) {
// Evaluation was started by an earlier run() of this job and is still in flight.
await this.evaluationPromise;
} else if (status === kEvaluated && this.module.hasAsyncGraph) {
// await the cycle root's capability promise.

Check failure on line 656 in lib/internal/modules/esm/module_job.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
await this.module.evaluate(-1, false);
}
// Otherwise the module is already evaluated
return { __proto__: null, module: this.module };
}
if (status < kInstantiated) {
Expand Down
11 changes: 11 additions & 0 deletions test/es-module/test-esm-tla-dynamic-import-evaluating-async.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.mjs';

// Regression test for https://github.com/nodejs/node/issues/66806
spawnSyncAndAssert(process.execPath, [
fixtures.path('es-modules', 'tla', 'dynamic-import-evaluating-async', 'main.mjs'),
], {
stdout: /^ok 2 2\n$/,
stderr: '',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Suspend so that main.mjs goes on to start evaluating b.mjs
await import('./d.mjs');
// b.mjs has been started but its body has not run yet
const { x } = await import('./b.mjs');
// b.mjs is now fully evaluated
const again = await import('./b.mjs');
if (again.x !== x) throw new Error(`expected ${x}, got ${again.x}`);
export const a = () => x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { c } from './c.mjs';
export const x = c + 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
await new Promise((resolve) => setTimeout(resolve, 10));
export const c = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const d = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a } from './a.mjs';
import { x } from './b.mjs';
console.log('ok', a(), x);
Loading