Skip to content

Commit 2a13190

Browse files
authored
Acorn optimizer: Fix a crash on a direct call in isExportWrapperFunction (#19101)
We assumed that a call in there is of a special expression, but it could also be just a call to an identifier, a normal call like z(). We just need to ignore that and not crash. Fixes #19052
1 parent b735d4b commit 2a13190

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

test/optimizer/emitDCEGraph.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ dynCall('vii', ptr, [2, 3]); // use indirectly, depending on analysis of dynCall
110110
x++;
111111
});
112112

113+
// Don't crash on this code pattern, which we should ignore.
114+
var _bad = function() {
115+
return something();
116+
};

tools/acorn-optimizer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,9 @@ function isExportWrapperFunction(f) {
601601
const expr = f.body.body[0];
602602
if (expr.type == 'ReturnStatement') {
603603
const rtn = expr.argument;
604-
if (rtn.type == 'CallExpression') {
604+
// We are looking for a call of special target, like (x = y)(), and not a
605+
// non-call or a normal direct call such as z().
606+
if (rtn.type == 'CallExpression' && rtn.callee.object) {
605607
let target = rtn.callee.object;
606608
if (target.type == 'ParenthesizedExpression') {
607609
target = target.expression;

0 commit comments

Comments
 (0)