mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
esm: fix missed renaming in ModuleJob.runSync
https://redirect.github.com/nodejs/node/pull/59675 missed a case when renaming .async to .hasAsyncGraph. This fixes that and add a test that would previously crash with the missed rename. PR-URL: https://github.com/nodejs/node/pull/59724 Refs: https://github.com/nodejs/node/pull/59675 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
parent
2258f22672
commit
3ffc3d73ac
|
|
@ -335,7 +335,7 @@ class ModuleJob extends ModuleJobBase {
|
|||
const parentFilename = urlToFilename(parent?.filename);
|
||||
this.module.hasAsyncGraph ??= this.module.isGraphAsync();
|
||||
|
||||
if (this.module.async && !getOptionValue('--experimental-print-required-tla')) {
|
||||
if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) {
|
||||
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
|
||||
}
|
||||
if (status === kInstantiated) {
|
||||
|
|
|
|||
21
test/es-module/test-import-require-tla-twice.js
Normal file
21
test/es-module/test-import-require-tla-twice.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
// This tests that in the require() in imported CJS can retry loading an ESM with TLA
|
||||
// twice and get the correct error both times.
|
||||
|
||||
require('../common');
|
||||
const { spawnSyncAndAssert } = require('../common/child_process');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
|
||||
spawnSyncAndAssert(
|
||||
process.execPath,
|
||||
['--import', fixtures.fileURL('es-modules', 'import-require-tla-twice', 'hook.js'),
|
||||
fixtures.path('es-modules', 'import-require-tla-twice', 'require-tla.js'),
|
||||
],
|
||||
{
|
||||
stdout(output) {
|
||||
const matches = output.matchAll(/e\.code === ERR_REQUIRE_ASYNC_MODULE true/g);
|
||||
assert.strictEqual([...matches].length, 2);
|
||||
}
|
||||
}
|
||||
);
|
||||
6
test/fixtures/es-modules/import-require-tla-twice/hook.js
vendored
Normal file
6
test/fixtures/es-modules/import-require-tla-twice/hook.js
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
const { registerHooks } = require('module');
|
||||
registerHooks({
|
||||
load(url, context, nextLoad) {
|
||||
return nextLoad(url, context);
|
||||
}
|
||||
});
|
||||
11
test/fixtures/es-modules/import-require-tla-twice/require-tla.js
vendored
Normal file
11
test/fixtures/es-modules/import-require-tla-twice/require-tla.js
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
try {
|
||||
require('./tla.mjs');
|
||||
} catch (e) {
|
||||
console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');
|
||||
}
|
||||
|
||||
try {
|
||||
require('./tla.mjs');
|
||||
} catch (e) {
|
||||
console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');
|
||||
}
|
||||
1
test/fixtures/es-modules/import-require-tla-twice/tla.mjs
vendored
Normal file
1
test/fixtures/es-modules/import-require-tla-twice/tla.mjs
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
await Promise.resolve('1');
|
||||
Loading…
Reference in New Issue
Block a user