fix corner case in `merge_vars` (#4550)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 12 Jan 2021 19:48:46 +0000 (19:48 +0000)
committerGitHub <noreply@github.com>
Tue, 12 Jan 2021 19:48:46 +0000 (03:48 +0800)
fixes #4548

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

index dde50e0..80dd7ea 100644 (file)
@@ -4979,7 +4979,9 @@ merge(Compressor.prototype, {
                     var marker = new TreeWalker(function(node) {
                         if (node instanceof AST_Destructured) return;
                         if (node instanceof AST_DefaultValue) {
+                            push();
                             node.value.walk(tw);
+                            pop();
                             node.name.walk(marker);
                         } else if (node instanceof AST_DestructuredKeyVal) {
                             if (node.key instanceof AST_Node) {
index 985651a..6fc2d3f 100644 (file)
@@ -1570,3 +1570,29 @@ issue_4540: {
     expect_stdout: "undefined"
     node_version: ">=6"
 }
+
+issue_4548: {
+    options = {
+        merge_vars: true,
+        toplevel: true,
+    }
+    input: {
+        A = "foo";
+        var a = A;
+        [ b = c = "bar" ] = [ console, console.log(a) ];
+        console.log(c);
+        var c;
+    }
+    expect: {
+        A = "foo";
+        var a = A;
+        [ b = c = "bar" ] = [ console, console.log(a) ];
+        console.log(c);
+        var c;
+    }
+    expect_stdout: [
+        "foo",
+        "undefined",
+    ]
+    node_version: ">=6"
+}