diff --git a/test/optimizer/JSDCE-output.js b/test/optimizer/JSDCE-output.js index 89c4957f78f3c..480f0396ba8a2 100644 --- a/test/optimizer/JSDCE-output.js +++ b/test/optimizer/JSDCE-output.js @@ -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; } diff --git a/test/optimizer/JSDCE.js b/test/optimizer/JSDCE.js index 9c59e2e1bfb1f..82c64f4773b61 100644 --- a/test/optimizer/JSDCE.js +++ b/test/optimizer/JSDCE.js @@ -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) { diff --git a/tools/acorn-optimizer.js b/tools/acorn-optimizer.js index 59c5f61b5d601..2171ea728ef73 100755 --- a/tools/acorn-optimizer.js +++ b/tools/acorn-optimizer.js @@ -235,6 +235,7 @@ function hasSideEffects(node) { case 'VariableDeclarator': case 'ObjectExpression': case 'Property': + case 'SpreadElement': case 'BlockStatement': case 'ArrayExpression': case 'EmptyStatement': { @@ -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) {