aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-05 17:26:19 +0000
committerGitHub <noreply@github.com>2021-01-06 01:26:19 +0800
commit4c89550c43974d5d570f132b2d8bc105c05cc618 (patch)
treebdc0f1c7877cd8046aa4d587dae68626b24ecbf3
parent7ebfb22d16a314404e1255aee9a470e1dd7b0af4 (diff)
downloadtracifyjs-4c89550c43974d5d570f132b2d8bc105c05cc618.tar.gz
tracifyjs-4c89550c43974d5d570f132b2d8bc105c05cc618.zip
fix corner case in`default_values` (#4511)
fixes #4510
-rw-r--r--lib/compress.js3
-rw-r--r--test/compress/default-values.js48
2 files changed, 50 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1714306e..dcb2cc4c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6143,8 +6143,9 @@ merge(Compressor.prototype, {
var values = value instanceof AST_Array && value.elements;
var elements = [];
node.elements.forEach(function(element, index) {
- if (element instanceof AST_Hole) return;
value = values && values[index];
+ if (value instanceof AST_Spread) value = values = null;
+ if (element instanceof AST_Hole) return;
element = element.transform(trimmer);
if (element) elements[index] = element;
});
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index 0fa27ea5..8e5910d9 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -1479,3 +1479,51 @@ issue_4502_4: {
expect_stdout: "42"
node_version: ">=6"
}
+
+issue_4510_1: {
+ options = {
+ default_values: true,
+ unused: true,
+ }
+ input: {
+ var a = [];
+ var [ , b = console.log("PASS") ] = [ ...a, null ];
+ }
+ expect: {
+ var a = [];
+ var [ , b = console.log("PASS") ] = [ ...a, null ];
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+issue_4510_2: {
+ options = {
+ default_values: true,
+ unused: true,
+ }
+ input: {
+ var o = {
+ p: void 0,
+ };
+ var {
+ p: a = console.log("PASS"),
+ } = {
+ p: null,
+ ...o,
+ };
+ }
+ expect: {
+ var o = {
+ p: void 0,
+ };
+ var {
+ p: a = console.log("PASS"),
+ } = {
+ p: null,
+ ...o,
+ };
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}