Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
esm: apply code review suggestions
- Refactor getUndefinedCJSGlobalLike to use ArrayPrototypeFind
- Change if-else chain to switch statement
- Add single quotes around global names in error messages
- Revert test file to use --input-type=module flag and original order
- Update test regex patterns to expect quoted global names
  • Loading branch information
mag123c authored and aduh95 committed Dec 4, 2025
commit e2efe89d48a97a86d28afef5ddfe7d55336451e5
13 changes: 7 additions & 6 deletions test/es-module/test-esm-detect-ambiguous.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },

assert.match(
stderr,
/ReferenceError: Cannot determine intended module format because both require and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./
/ReferenceError: Cannot determine intended module format because both 'require' and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./
);
assert.strictEqual(stdout, '');
assert.strictEqual(code, 1);
Expand Down Expand Up @@ -432,14 +432,15 @@ describe('cjs & esm ambiguous syntax case', () => {
const { stderr, code, signal } = await spawnPromisified(
process.execPath,
[
'--input-type=module',
'--eval',
`const fs = require('fs');\nawait 1;`,
`await 1;\nconst fs = require('fs');`,
]
);

assert.match(
stderr,
/ReferenceError: Cannot determine intended module format because both require and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./
/ReferenceError: Cannot determine intended module format because both 'require' and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./
);

strictEqual(code, 1);
Expand All @@ -457,7 +458,7 @@ describe('cjs & esm ambiguous syntax case', () => {

match(
stderr,
/ReferenceError: Cannot determine intended module format because both exports and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use export instead of module\.exports\/exports\./
/ReferenceError: Cannot determine intended module format because both 'exports' and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use export instead of module\.exports\/exports\./
);

assert.strictEqual(code, 1);
Expand All @@ -475,7 +476,7 @@ describe('cjs & esm ambiguous syntax case', () => {

match(
stderr,
/ReferenceError: Cannot determine intended module format because both __filename and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use import\.meta\.filename instead\./
/ReferenceError: Cannot determine intended module format because both '__filename' and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use import\.meta\.filename instead\./
);

strictEqual(code, 1);
Expand All @@ -493,7 +494,7 @@ describe('cjs & esm ambiguous syntax case', () => {

match(
stderr,
/ReferenceError: Cannot determine intended module format because both __dirname and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use import\.meta\.dirname instead\./
/ReferenceError: Cannot determine intended module format because both '__dirname' and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, use import\.meta\.dirname instead\./
);

strictEqual(code, 1);
Expand Down