Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix JS optimizer fail on ES6 spread operator #18461

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 8 additions & 0 deletions test/optimizer/JSDCE-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ function g(a) {

Module["g"] = g;

const sx = {a:1};

const sar = [1,2,3];

Module['spread'] = { b:2, ...sx };

Module['spread2'] = [ ...sar, 4, 5, 6 ];
kripken marked this conversation as resolved.
Show resolved Hide resolved

function h(a) {
return a + 1;
}
Expand Down
4 changes: 4 additions & 0 deletions test/optimizer/JSDCE.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function g(a) {
return a+1;
}
Module['g'] = g;
const sx = {a:1};
const sar = [1,2,3];
Module['spread'] = { b:2, ...sx };
Module['spread2'] = [ ...sar, 4, 5, 6 ];

// used
function h(a) {
Expand Down
7 changes: 6 additions & 1 deletion tools/acorn-optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function hasSideEffects(node) {
case 'VariableDeclarator':
case 'ObjectExpression':
case 'Property':
case 'SpreadElement':
case 'BlockStatement':
case 'ArrayExpression':
case 'EmptyStatement': {
Expand Down Expand Up @@ -399,7 +400,11 @@ function runJSDCE(ast, aggressive) {
ObjectExpression(node, c) {
// ignore the property identifiers
node.properties.forEach(function (node) {
c(node.value);
if (node.value) {
c(node.value);
} else if (node.argument) {
c(node.argument);
}
});
},
MemberExpression(node, c) {
Expand Down