Skip to content

Commit

Permalink
Fix JS optimizer error on ES6 spread operator (#18461)
Browse files Browse the repository at this point in the history
fixes #12543
  • Loading branch information
pavelsavara authored Jan 5, 2023
1 parent a6e8d85 commit de13451
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/optimizer/JSDCE-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ 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 ];

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

0 comments on commit de13451

Please sign in to comment.