fix corner case in `collapse_vars` (#4243)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 24 Oct 2020 14:44:20 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Sat, 24 Oct 2020 14:44:20 +0000 (22:44 +0800)
fixes #4242

lib/compress.js
test/compress/collapse_vars.js

index 216ca92..647c97e 100644 (file)
@@ -1974,6 +1974,7 @@ merge(Compressor.prototype, {
             }
 
             function foldable(expr) {
+                if (expr instanceof AST_Assign && expr.right.single_use) return;
                 var lhs_ids = Object.create(null);
                 var marker = new TreeWalker(function(node) {
                     if (node instanceof AST_SymbolRef) lhs_ids[node.definition().id] = true;
index 4c3a6ed..dea01b6 100644 (file)
@@ -8556,3 +8556,24 @@ issue_4070: {
     }
     expect_stdout: "NaN"
 }
+
+issue_4242: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            if (console)
+                var a = function(){}, b = (!1 === console || a)();
+        }());
+    }
+    expect: {
+        console.log(function() {
+            console && (!1 === console || function(){})();
+        }());
+    }
+    expect_stdout: "undefined"
+}