fix corner case in `merge_vars` (#4402)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 18 Dec 2020 04:20:43 +0000 (04:20 +0000)
committerGitHub <noreply@github.com>
Fri, 18 Dec 2020 04:20:43 +0000 (12:20 +0800)
fixes #4401

lib/compress.js
test/compress/arrows.js
test/ufuzz/index.js

index 33d8cf5..ab5ad06 100644 (file)
@@ -4915,7 +4915,11 @@ merge(Compressor.prototype, {
                         argname.mark_symbol(marker, scanner);
                     });
                 }
-                walk_body(node, tw);
+                if (node instanceof AST_Arrow && node.value) {
+                    node.value.walk(tw);
+                } else {
+                    walk_body(node, tw);
+                }
                 pop();
                 return true;
             }
index dd71fe9..c91cd27 100644 (file)
@@ -465,3 +465,28 @@ issue_4390: {
     ]
     node_version: ">=4"
 }
+
+issue_4401: {
+    options = {
+        merge_vars: true,
+    }
+    input: {
+        (function() {
+            var a = (b => b(a))(console.log || a);
+            var c = console.log;
+            c && c(typeof b);
+        })();
+    }
+    expect: {
+        (function() {
+            var a = (b => b(a))(console.log || a);
+            var c = console.log;
+            c && c(typeof b);
+        })();
+    }
+    expect_stdout: [
+        "undefined",
+        "undefined",
+    ]
+    node_version: ">=4"
+}
index c4ad4a7..eb38a75 100644 (file)
@@ -1011,7 +1011,7 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
                         suffix = "})";
                     } else {
                         s.push("((" + params + ") => ");
-                        switch (rng(4)) {
+                        switch (rng(10)) {
                           case 0:
                             s.push('(typeof arguments != "undefined" && arguments && arguments[' + rng(3) + "])");
                             break;