fix corner case with default values (#4484)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 30 Dec 2020 17:47:00 +0000 (17:47 +0000)
committerGitHub <noreply@github.com>
Wed, 30 Dec 2020 17:47:00 +0000 (01:47 +0800)
fixes #4483

lib/compress.js
test/compress/default-values.js
test/reduce.js

index 3ac9e74..aea3155 100644 (file)
@@ -3603,6 +3603,7 @@ merge(Compressor.prototype, {
 
     function is_lhs(node, parent) {
         if (parent instanceof AST_Assign) return parent.left === node && node;
+        if (parent instanceof AST_DefaultValue) return parent.name === node && node;
         if (parent instanceof AST_Destructured) return node;
         if (parent instanceof AST_DestructuredKeyVal) return node;
         if (parent instanceof AST_Unary) return unary_side_effects[parent.operator] && parent.expression;
index 39fcddb..5b21ae6 100644 (file)
@@ -1206,3 +1206,24 @@ issue_4468: {
     expect_stdout: "PASS"
     node_version: ">=6"
 }
+
+issue_4483: {
+    options = {
+        conditionals: true,
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+    }
+    input: {
+        if (console)
+            var [ a = "FAIL" ] = [], b = a = "PASS";
+        console.log(b);
+    }
+    expect: {
+        var a, b;
+        console && ([ a = "FAIL" ] = [], b = "PASS");
+        console.log(b);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}
index 48030b0..120868f 100644 (file)
@@ -124,7 +124,6 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
 
             // ignore lvalues
             if (parent instanceof U.AST_Assign && parent.left === node) return;
-            if (parent instanceof U.AST_DestructuredArray) return;
             if (parent instanceof U.AST_DestructuredKeyVal && parent.value === node) return;
             if (parent instanceof U.AST_Unary && parent.expression === node) switch (parent.operator) {
               case "++":