Skip to content

Commit dedec09

Browse files
committed
Upgrade acorn parsing to a newer version that can parse dynamic imports
1 parent bbe653c commit dedec09

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,17 @@ async function parseExportNamesInto(
266266
if (typeof source !== 'string') {
267267
throw new Error('Expected the transformed source to be a string.');
268268
}
269-
const {body: childBody} = acorn.parse(source, {
270-
ecmaVersion: '2019',
271-
sourceType: 'module',
272-
});
269+
let childBody;
270+
try {
271+
childBody = acorn.parse(source, {
272+
ecmaVersion: '2024',
273+
sourceType: 'module',
274+
}).body;
275+
} catch (x) {
276+
// eslint-disable-next-line react-internal/no-production-logging
277+
console.error('Error parsing %s %s', url, x.message);
278+
continue;
279+
}
273280
await parseExportNamesInto(childBody, names, url, loader);
274281
continue;
275282
}
@@ -381,10 +388,17 @@ async function transformModuleIfNeeded(
381388
return source;
382389
}
383390

384-
const {body} = acorn.parse(source, {
385-
ecmaVersion: '2019',
386-
sourceType: 'module',
387-
});
391+
let body;
392+
try {
393+
body = acorn.parse(source, {
394+
ecmaVersion: '2024',
395+
sourceType: 'module',
396+
}).body;
397+
} catch (x) {
398+
// eslint-disable-next-line react-internal/no-production-logging
399+
console.error('Error parsing %s %s', url, x.message);
400+
return source;
401+
}
388402

389403
let useClient = false;
390404
let useServer = false;

packages/react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,17 @@ module.exports = function register() {
244244
return originalCompile.apply(this, arguments);
245245
}
246246

247-
const {body} = acorn.parse(content, {
248-
ecmaVersion: '2019',
249-
sourceType: 'source',
250-
});
247+
let body;
248+
try {
249+
body = acorn.parse(content, {
250+
ecmaVersion: '2024',
251+
sourceType: 'source',
252+
}).body;
253+
} catch (x) {
254+
// eslint-disable-next-line react-internal/no-production-logging
255+
console.error('Error parsing %s %s', url, x.message);
256+
return originalCompile.apply(this, arguments);
257+
}
251258

252259
let useClient = false;
253260
let useServer = false;

0 commit comments

Comments
 (0)