Skip to content

Commit

Permalink
module: report unfinished TLA in ambiguous modules
Browse files Browse the repository at this point in the history
PR-URL: nodejs#54980
Fixes: nodejs#54931
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
aduh95 authored and joyeecheung committed Oct 1, 2024
1 parent e40196b commit 3dd9c34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,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);
Expand Down
12 changes: 12 additions & 0 deletions test/es-module/test-esm-detect-ambiguous.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es-modules/tla/unresolved.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await new Promise(() => {});

0 comments on commit 3dd9c34

Please sign in to comment.