Skip to content
Closed
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
fixup! module: refine enrichCJSError
  • Loading branch information
aduh95 committed Jul 24, 2021
commit 083ad71ee152f3401466f430814bcc3a4d8288e1
11 changes: 8 additions & 3 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ translators.set('module', async function moduleStrategy(url) {
return module;
});

function enrichCJSError(err, content) {
/**
* @param {Error | any} err
Comment thread
aduh95 marked this conversation as resolved.
Outdated
* @param {string} [content] Content of the file, if known.
* @param {string} [filename] Useful only if `content` is unknown.
*/
function enrichCJSError(err, content, filename) {
if (err != null && ObjectGetPrototypeOf(err) === SyntaxErrorPrototype &&
hasEsmSyntax(content)) {
hasEsmSyntax(content || readFileSync(filename, 'utf-8'))) {
// Emit the warning synchronously because we are in the middle of handling
// a SyntaxError that will throw and likely terminate the process before an
// asynchronous warning would be emitted.
Expand Down Expand Up @@ -190,7 +195,7 @@ translators.set('commonjs', async function commonjsStrategy(url, isMain) {
try {
exports = CJSModule._load(filename, undefined, isMain);
} catch (err) {
enrichCJSError(err, readFileSync(filename, 'utf-8'));
enrichCJSError(err, undefined, filename);
throw err;
}
}
Expand Down