Skip to content

Commit ecd44e4

Browse files
aduh95joyeecheung
authored andcommittedFeb 5, 2025
module: report unfinished TLA in ambiguous modules
PR-URL: nodejs#54980 Fixes: nodejs#54931 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent a0566f6 commit ecd44e4

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

‎lib/internal/modules/cjs/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ function loadESMFromCJS(mod, filename) {
13621362
if (isMain) {
13631363
require('internal/modules/run_main').runEntryPointWithESMLoader((cascadedLoader) => {
13641364
const mainURL = pathToFileURL(filename).href;
1365-
cascadedLoader.import(mainURL, undefined, { __proto__: null }, true);
1365+
return cascadedLoader.import(mainURL, undefined, { __proto__: null }, true);
13661366
});
13671367
// ESM won't be accessible via process.mainModule.
13681368
setOwnProperty(process, 'mainModule', undefined);

‎test/es-module/test-esm-detect-ambiguous.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
252252
strictEqual(signal, null);
253253
});
254254

255+
it('reports unfinished top-level `await`', async () => {
256+
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
257+
'--no-warnings',
258+
fixtures.path('es-modules/tla/unresolved.js'),
259+
]);
260+
261+
strictEqual(stderr, '');
262+
strictEqual(stdout, '');
263+
strictEqual(code, 13);
264+
strictEqual(signal, null);
265+
});
266+
255267
it('permits top-level `await` above import/export syntax', async () => {
256268
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
257269
'--eval',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
await new Promise(() => {});

0 commit comments

Comments
 (0)