From aa9f6a328b71a946215af1df46dc7f48ba0154e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Thu, 29 Mar 2018 18:13:28 +0100 Subject: [PATCH] stop replacement of symbols in an AST_Expansion --- lib/compress.js | 3 +++ test/compress/harmony.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 886a4b5b..0167ff9c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1047,6 +1047,9 @@ merge(Compressor.prototype, { || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression) || node instanceof AST_Debugger || node instanceof AST_Destructuring + || node instanceof AST_Expansion + && node.expression instanceof AST_Symbol + && node.expression.definition().references.length > 1 || node instanceof AST_IterationStatement && !(node instanceof AST_For) || node instanceof AST_LoopControl || node instanceof AST_Try diff --git a/test/compress/harmony.js b/test/compress/harmony.js index b85214ec..da936ce1 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -1601,3 +1601,28 @@ issue_2874_3: { ] node_version: ">=6" } + +issue_3028: { + options = { + collapse_vars: true, + evaluate: true, + side_effects: true, + unused: true, + } + input: { + function a(array) { + var shifted = array.splice(0, 2); + return [ ...array, ...shifted ]; + } + console.log(a([ 1, 2, 3 ]).join(" ")); + } + expect: { + function a(array) { + var shifted = array.splice(0, 2); + return [ ...array, ...shifted ]; + } + console.log(a([ 1, 2, 3 ]).join(" ")); + } + expect_stdout: "3 1 2" + node_version: ">=6" +}