Skip to content

Commit

Permalink
module: report unfinished TLA in ambiguous modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Sep 17, 2024
1 parent d17fefc commit 5930f8e
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -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);
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')

Check failure on line 258 in test/es-module/test-esm-detect-ambiguous.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
]);

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

0 comments on commit 5930f8e

Please sign in to comment.