From 5930f8ec3db260b4b7c0b237d52377a7f2e2a2b1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 17 Sep 2024 12:21:49 +0200 Subject: [PATCH 1/2] module: report unfinished TLA in ambiguous modules --- lib/internal/modules/cjs/loader.js | 2 +- test/es-module/test-esm-detect-ambiguous.mjs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 8d3f59abcf5720..a8d245b10814c9 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -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); diff --git a/test/es-module/test-esm-detect-ambiguous.mjs b/test/es-module/test-esm-detect-ambiguous.mjs index fce455cf18bb60..62b4fa7ef2ba0b 100644 --- a/test/es-module/test-esm-detect-ambiguous.mjs +++ b/test/es-module/test-esm-detect-ambiguous.mjs @@ -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', From 2ee5df927616f02c1291f22a19ba95f793b1ebbe Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 17 Sep 2024 12:25:28 +0200 Subject: [PATCH 2/2] fixup! module: report unfinished TLA in ambiguous modules --- test/es-module/test-esm-detect-ambiguous.mjs | 2 +- test/fixtures/es-modules/tla/unresolved.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/es-modules/tla/unresolved.js diff --git a/test/es-module/test-esm-detect-ambiguous.mjs b/test/es-module/test-esm-detect-ambiguous.mjs index 62b4fa7ef2ba0b..5d5a2744afcd14 100644 --- a/test/es-module/test-esm-detect-ambiguous.mjs +++ b/test/es-module/test-esm-detect-ambiguous.mjs @@ -255,7 +255,7 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 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') + fixtures.path('es-modules/tla/unresolved.js'), ]); strictEqual(stderr, ''); diff --git a/test/fixtures/es-modules/tla/unresolved.js b/test/fixtures/es-modules/tla/unresolved.js new file mode 100644 index 00000000000000..231a8cd634825c --- /dev/null +++ b/test/fixtures/es-modules/tla/unresolved.js @@ -0,0 +1 @@ +await new Promise(() => {});