| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ebd8c6b commit d7805e0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,6 +67,18 @@ async function checkSyntax(source, filename) { | |||
| 67 | 67 | format = await defaultGetFormat(new URL(url)); | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | + // A `.js` file with no `"type"` in the nearest package.json has no format of | ||
| 71 | + // its own. At load time the goal is decided by looking for module syntax in | ||
| 72 | + // the source, so decide it the same way here. Otherwise such a file is only | ||
| 73 | + // ever parsed as CommonJS, where module syntax makes the parse bail out | ||
| 74 | + // before any syntax error in the rest of the file is reported. | ||
| 75 | + if (format === null || format === undefined) { | ||
| 76 | + const { containsModuleSyntax } = internalBinding('contextify'); | ||
| 77 | + if (containsModuleSyntax(source, filename)) { | ||
| 78 | + format = 'module'; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 70 | 82 | if (format === 'module') { | |
| 71 | 83 | const { ModuleWrap } = internalBinding('module_wrap'); | |
| 72 | 84 | new ModuleWrap(filename, undefined, source, 0, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + import fs from 'node:fs'; | ||
| 2 | + var = ; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,9 @@ const syntaxErrorRE = /^SyntaxError: \b/m; | |||
| 21 | 21 | 'syntax/bad_syntax', | |
| 22 | 22 | 'syntax/bad_syntax_shebang.js', | |
| 23 | 23 | 'syntax/bad_syntax_shebang', | |
| 24 | + // A `.js` file with no `"type"` in the nearest package.json, whose module | ||
| 25 | + // syntax makes it load as ESM. Refs: https://github.com/nodejs/node/issues/65202 | ||
| 26 | + 'syntax/bad_syntax_esm_ambiguous.js', | ||
| 24 | 27 | ].forEach((file) => { | |
| 25 | 28 | const path = fixtures.path(file); | |
| 26 | 29 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments