fix escape analysis on `||` and `&&` (#2600)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 15 Dec 2017 11:48:14 +0000 (19:48 +0800)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2017 11:48:14 +0000 (19:48 +0800)
fixes #2598

lib/compress.js
test/compress/reduce_vars.js

index a8bcf54..0fac325 100644 (file)
@@ -674,6 +674,7 @@ merge(Compressor.prototype, {
                 d.escaped = true;
                 return;
             } else if (parent instanceof AST_Array
+                || parent instanceof AST_Binary && lazy_op(parent.operator)
                 || parent instanceof AST_Conditional && node !== parent.condition
                 || parent instanceof AST_Sequence && node === parent.tail_node()) {
                 mark_escaped(d, scope, parent, parent, level + 1);
index 394bb58..bf1155b 100644 (file)
@@ -4899,3 +4899,27 @@ do_while: {
     }
     expect_stdout: "PASS"
 }
+
+issue_2598: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function f() {}
+        function g(a) {
+            return a || f;
+        }
+        console.log(g(false) === g(null));
+    }
+    expect: {
+        function f() {}
+        function g(a) {
+            return a || f;
+        }
+        console.log(g(false) === g(null));
+    }
+    expect_stdout: "true"
+}