From b7fed9a2e13331f86fbd92d1a82149617ee48712 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 3 Jan 2023 23:58:43 +0100 Subject: [PATCH 1/3] fix fail on spread operator --- tools/acorn-optimizer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) { From 29e10ff500096a6d85c2602ccedb33add1ab54bd Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 4 Jan 2023 18:39:57 +0100 Subject: [PATCH 2/3] run tests on CI --- test/optimizer/JSDCE-output.js | 8 ++++++++ test/optimizer/JSDCE.js | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/test/optimizer/JSDCE-output.js b/test/optimizer/JSDCE-output.js index 89c4957f78f3c..833c8339368aa 100644 --- a/test/optimizer/JSDCE-output.js +++ b/test/optimizer/JSDCE-output.js @@ -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 ]; + 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) { From 3edc22731632f8f789b1715644b478323fd05021 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 4 Jan 2023 16:01:31 -0800 Subject: [PATCH 3/3] Update test/optimizer/JSDCE-output.js --- test/optimizer/JSDCE-output.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/optimizer/JSDCE-output.js b/test/optimizer/JSDCE-output.js index 833c8339368aa..480f0396ba8a2 100644 --- a/test/optimizer/JSDCE-output.js +++ b/test/optimizer/JSDCE-output.js @@ -14,13 +14,18 @@ function g(a) { Module["g"] = g; -const sx = {a:1}; +const sx = { + a: 1 +}; -const sar = [1,2,3]; +const sar = [ 1, 2, 3 ]; -Module['spread'] = { b:2, ...sx }; +Module["spread"] = { + b: 2, + ...sx +}; -Module['spread2'] = [ ...sar, 4, 5, 6 ]; +Module["spread2"] = [ ...sar, 4, 5, 6 ]; function h(a) { return a + 1;