Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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