Files
node/test/es-module/test-require-module-tla-execution.js
Joyee Cheung a006c5dd12 esm: improve ERR_REQUIRE_ASYNC_MODULE
This brings back several improvements that were reverted by mistake when
landing https://redirect.github.com/nodejs/node/pull/64154

- Update the documentation about how the removal of side effects of
  source collection
- Add non-enumerable `requireStack` and `topLevelAwaitLocations`
  properties to `ERR_REQUIRE_ASYNC_MODULE`, the latter is only
  populated when --experimental-print-required-tla is enabled
- Add "Required module: <url>" to the error message to identify the
  required ESM entry point regardless of whether the flag is enabled
- Fix TLA caret column from 0-based to 1-based
- Store module source via a private symbol instead of a public property
- Use `hasAsyncGraph` (post-instantiation) in `throwIfAsyncGraph`
  instead of walking the graph before instantiation
- Merge the require stack checking into the
  `common.expectRequiredTLAError` helper.
- Removed tests that are made redundant by the snapshot tests

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64260
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-07-04 15:22:48 +00:00

25 lines
771 B
JavaScript

'use strict';
// Tests the output of require(esm) with top-level-await when --experimental-print-required-tla
// is NOT enabled.
const common = require('../common');
const assert = require('assert');
const { spawnSyncAndExit } = require('../common/child_process');
const fixtures = require('../common/fixtures');
{
const filename = fixtures.path('es-modules/tla/require-execution.js');
spawnSyncAndExit(process.execPath, [ filename ], {
signal: null,
status: 1,
stderr(output) {
assert.match(output, /To see where the top-level await comes from, use --experimental-print-required-tla/);
assert.doesNotMatch(output, /I am executed/);
common.expectRequiredTLAError(output, [filename]);
return true;
},
stdout: '',
});
}