From c09f63aefb4609bbdae259213e7fa458d959e20b Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 9 Aug 2021 01:59:33 +0100 Subject: [PATCH] fix corner case in `rests` (#5109) fixes #5108 --- lib/compress.js | 6 ++++-- test/compress/rests.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index c19091d7..3820a3ad 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -12313,8 +12313,10 @@ merge(Compressor.prototype, { OPT(AST_DestructuredArray, function(self, compressor) { if (compressor.option("rests") && self.rest instanceof AST_DestructuredArray) { - self.elements = self.elements.concat(self.rest.elements); - self.rest = self.rest.rest; + return make_node(AST_DestructuredArray, self, { + elements: self.elements.concat(self.rest.elements), + rest: self.rest.rest, + }); } return self; }); diff --git a/test/compress/rests.js b/test/compress/rests.js index 45d8e222..a62e380a 100644 --- a/test/compress/rests.js +++ b/test/compress/rests.js @@ -1069,3 +1069,25 @@ issue_5100_2: { expect_stdout: "PASS" node_version: ">=10" } + +issue_5108: { + options = { + evaluate: true, + reduce_vars: true, + rests: true, + unsafe: true, + unused: true, + } + input: { + console.log(function([ ...[ a ] ]) { + return a; + }([ "PASS", "FAIL" ])); + } + expect: { + console.log(function([]) { + return "PASS"; + }([ "PASS", "FAIL" ])); + } + expect_stdout: "PASS" + node_version: ">=6" +}