fix corner case in `reduce_vars` (#4459)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 25 Dec 2020 14:50:11 +0000 (14:50 +0000)
committerGitHub <noreply@github.com>
Fri, 25 Dec 2020 14:50:11 +0000 (22:50 +0800)
fixes #4458

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

index 1dc01f9..e4506f7 100644 (file)
@@ -879,6 +879,13 @@ merge(Compressor.prototype, {
             pop(tw);
             return true;
         });
+        def(AST_DefaultValue, function(tw) {
+            this.name.walk(tw);
+            push(tw);
+            this.value.walk(tw);
+            pop(tw);
+            return true;
+        });
         def(AST_Defun, reduce_defun);
         def(AST_Do, function(tw) {
             var saved_loop = tw.in_loop;
index bda32c1..eefa6e0 100644 (file)
@@ -1076,3 +1076,27 @@ issue_4446_2: {
     expect_stdout: "PASS 42"
     node_version: ">=6"
 }
+
+issue_4458: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        function f(b = a = "FAIL") {
+            console.log(a, b);
+        }
+        f(42);
+    }
+    expect: {
+        var a = "PASS";
+        (function(b = a = "FAIL") {
+            console.log(a, b);
+        })(42);
+    }
+    expect_stdout: "PASS 42"
+    node_version: ">=6"
+}