Skip to content

Commit

Permalink
Upgrade acorn parsing to a newer version that can parse dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Feb 28, 2023
1 parent bbe653c commit a347217
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,16 @@ async function parseExportNamesInto(
if (typeof source !== 'string') {
throw new Error('Expected the transformed source to be a string.');
}
const {body: childBody} = acorn.parse(source, {
ecmaVersion: '2019',
sourceType: 'module',
});
let childBody;
try {
childBody = acorn.parse(source, {
ecmaVersion: '2024',
sourceType: 'module',
}).body;
} catch (x) {
console.error('Error parsing %s %s', url, x.message);
continue;
}
await parseExportNamesInto(childBody, names, url, loader);
continue;
}
Expand Down Expand Up @@ -381,10 +387,16 @@ async function transformModuleIfNeeded(
return source;
}

const {body} = acorn.parse(source, {
ecmaVersion: '2019',
sourceType: 'module',
});
let body;
try {
body = acorn.parse(source, {
ecmaVersion: '2024',
sourceType: 'module',
}).body;
} catch (x) {
console.error('Error parsing %s %s', url, x.message);
return source;
}

let useClient = false;
let useServer = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,16 @@ module.exports = function register() {
return originalCompile.apply(this, arguments);
}

const {body} = acorn.parse(content, {
ecmaVersion: '2019',
sourceType: 'source',
});
let body;
try {
body = acorn.parse(content, {
ecmaVersion: '2024',
sourceType: 'source',
}).body;
} catch (x) {
console.error('Error parsing %s %s', url, x.message);
return originalCompile.apply(this, arguments);
}

let useClient = false;
let useServer = false;
Expand Down

0 comments on commit a347217

Please sign in to comment.