esm: fix missed renaming in ModuleJob.runSync · nodejs/node@dbe6e63

File tree

5 files changed

lines changed

    • fixtures/es-modules/import-require-tla-twice

5 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -335,7 +335,7 @@ class ModuleJob extends ModuleJobBase {

335335

const parentFilename = urlToFilename(parent?.filename);

336336

this.module.hasAsyncGraph ??= this.module.isGraphAsync();

337337
338-

if (this.module.async && !getOptionValue('--experimental-print-required-tla')) {

338+

if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) {

339339

throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);

340340

}

341341

if (status === kInstantiated) {

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,21 @@

1+

'use strict';

2+

// This tests that in the require() in imported CJS can retry loading an ESM with TLA

3+

// twice and get the correct error both times.

4+
5+

require('../common');

6+

const { spawnSyncAndAssert } = require('../common/child_process');

7+

const fixtures = require('../common/fixtures');

8+

const assert = require('assert');

9+
10+

spawnSyncAndAssert(

11+

process.execPath,

12+

['--import', fixtures.fileURL('es-modules', 'import-require-tla-twice', 'hook.js'),

13+

fixtures.path('es-modules', 'import-require-tla-twice', 'require-tla.js'),

14+

],

15+

{

16+

stdout(output) {

17+

const matches = output.matchAll(/e\.code === ERR_REQUIRE_ASYNC_MODULE true/g);

18+

assert.strictEqual([...matches].length, 2);

19+

}

20+

}

21+

);

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,6 @@

1+

const { registerHooks } = require('module');

2+

registerHooks({

3+

load(url, context, nextLoad) {

4+

return nextLoad(url, context);

5+

}

6+

});

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,11 @@

1+

try {

2+

require('./tla.mjs');

3+

} catch (e) {

4+

console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');

5+

}

6+
7+

try {

8+

require('./tla.mjs');

9+

} catch (e) {

10+

console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');

11+

}

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

await Promise.resolve('1');