module: report unfinished TLA in ambiguous modules

PR-URL: https://github.com/nodejs/node/pull/54980
Fixes: https://github.com/nodejs/node/issues/54931
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Antoine du Hamel 2024-09-19 12:34:13 +02:00 committed by GitHub
parent 6031a4bc7c
commit be4babb3c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View File

@ -1381,7 +1381,7 @@ function loadESMFromCJS(mod, filename) {
if (isMain) {
require('internal/modules/run_main').runEntryPointWithESMLoader((cascadedLoader) => {
const mainURL = pathToFileURL(filename).href;
cascadedLoader.import(mainURL, undefined, { __proto__: null }, true);
return cascadedLoader.import(mainURL, undefined, { __proto__: null }, true);
});
// ESM won't be accessible via process.mainModule.
setOwnProperty(process, 'mainModule', undefined);

View File

@ -252,6 +252,18 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
strictEqual(signal, null);
});
it('reports unfinished top-level `await`', async () => {
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
'--no-warnings',
fixtures.path('es-modules/tla/unresolved.js'),
]);
strictEqual(stderr, '');
strictEqual(stdout, '');
strictEqual(code, 13);
strictEqual(signal, null);
});
it('permits top-level `await` above import/export syntax', async () => {
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
'--eval',

View File

@ -0,0 +1 @@
await new Promise(() => {});