fix corner case in `reduce_vars` (#4569)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 18 Jan 2021 22:34:48 +0000 (22:34 +0000)
committerGitHub <noreply@github.com>
Mon, 18 Jan 2021 22:34:48 +0000 (06:34 +0800)
fixes #4568

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

index 8151153..e33f4f3 100644 (file)
@@ -9733,7 +9733,7 @@ merge(Compressor.prototype, {
                         single_use = false;
                     }
                     if (single_use) fixed.parent_scope = self.scope;
-                } else if (!fixed || !fixed.is_constant_expression()) {
+                } else if (!fixed || !fixed.is_constant_expression() || fixed.drop_side_effect_free(compressor)) {
                     single_use = false;
                 }
             }
index c28512a..ed3950a 100644 (file)
@@ -2900,3 +2900,22 @@ issue_4250: {
     }
     expect_stdout: "0"
 }
+
+issue_4568: {
+    options = {
+        ie8: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(typeof f, function(a) {
+            return a.length;
+        }([ function f() {} ]));
+    }
+    expect: {
+        console.log(typeof f, function(a) {
+            return a.length;
+        }([ function f() {} ]));
+    }
+    expect_stdout: "undefined 1"
+}
index ea9efee..185a39c 100644 (file)
@@ -7601,3 +7601,32 @@ issue_4188_2: {
     }
     expect_stdout: "number undefined"
 }
+
+issue_4568: {
+    options = {
+        booleans: true,
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        loops: true,
+        passes: 2,
+        reduce_vars: true,
+        sequences: true,
+        unused: true,
+    }
+    input: {
+        (function(a) {
+            a && console.log("FAIL");
+            if (1)
+                do {
+                    if (!console.log("PASS")) break;
+                } while (1);
+        })(!(0 !== delete NaN));
+    }
+    expect: {
+        (function(a) {
+            for (a && console.log("FAIL"), 1; console.log("PASS"); ) 1;
+        })(!(0 !== delete NaN));
+    }
+    expect_stdout: "PASS"
+}