Skip to content

Commit e2efe89

Browse files
mag123caduh95
authored andcommitted
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
1 parent 63b391c commit e2efe89

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
283283

284284
assert.match(
285285
stderr,
286-
/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\./
286+
/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\./
287287
);
288288
assert.strictEqual(stdout, '');
289289
assert.strictEqual(code, 1);
@@ -432,14 +432,15 @@ describe('cjs & esm ambiguous syntax case', () => {
432432
const { stderr, code, signal } = await spawnPromisified(
433433
process.execPath,
434434
[
435+
'--input-type=module',
435436
'--eval',
436-
`const fs = require('fs');\nawait 1;`,
437+
`await 1;\nconst fs = require('fs');`,
437438
]
438439
);
439440

440441
assert.match(
441442
stderr,
442-
/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\./
443+
/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\./
443444
);
444445

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

458459
match(
459460
stderr,
460-
/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\./
461+
/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\./
461462
);
462463

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

476477
match(
477478
stderr,
478-
/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\./
479+
/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\./
479480
);
480481

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

494495
match(
495496
stderr,
496-
/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\./
497+
/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\./
497498
);
498499

499500
strictEqual(code, 1);

0 commit comments

Comments
 (0)