fix corner case in `ie8` (#3543)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 28 Oct 2019 15:54:27 +0000 (23:54 +0800)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2019 15:54:27 +0000 (23:54 +0800)
fixes #3542

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

index 7c5558b..1016133 100644 (file)
@@ -4238,7 +4238,7 @@ merge(Compressor.prototype, {
         def(AST_Binary, function(compressor, first_in_statement) {
             var right = this.right.drop_side_effect_free(compressor, first_in_statement);
             if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);
-            if (lazy_op[this.operator]) {
+            if (lazy_op[this.operator] && !(right instanceof AST_Function)) {
                 var node = this;
                 if (right !== node.right) {
                     node = this.clone();
index 1a84026..f8ce35d 100644 (file)
@@ -2339,3 +2339,25 @@ issue_3523_rename_ie8_toplevel: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3542: {
+    options = {
+        ie8: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 0;
+        var b = a++;
+        var c = b && function a() {} || b;
+        console.log(a);
+    }
+    expect: {
+        var a = 0;
+        a++;
+        (function a() {});
+        console.log(a);
+    }
+    expect_stdout: "1"
+}