fix corner case in `ie8` & `reduce_vars` (#3919)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 22 May 2020 01:56:35 +0000 (02:56 +0100)
committerGitHub <noreply@github.com>
Fri, 22 May 2020 01:56:35 +0000 (09:56 +0800)
fixes #3918

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

index 17eeb87..02b18ad 100644 (file)
@@ -7515,6 +7515,8 @@ merge(Compressor.prototype, {
                                 scope.inlined = true;
                             } while (scope = scope.parent_scope);
                         }
+                    } else if (compressor.option("ie8") && fixed.name && def !== fixed.name.definition()) {
+                        single_use = false;
                     }
                     if (single_use) fixed.parent_scope = self.scope;
                 } else if (!fixed || !fixed.is_constant_expression()) {
index 68ccab1..e11e365 100644 (file)
@@ -2489,3 +2489,36 @@ issue_3889: {
     }
     expect_stdout: "undefined"
 }
+
+issue_3918: {
+    options = {
+        conditionals: true,
+        ie8: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    mangle = {
+        ie8: true,
+    }
+    input: {
+        if (console.log("PASS")) {
+            var a = function f() {
+                f.p;
+                try {
+                    console.log("FAIL");
+                } catch (e) {}
+            }, b = a;
+        }
+    }
+    expect: {
+        var a;
+        console.log("PASS") && (a = function f() {
+            f.p;
+            try {
+                console.log("FAIL");
+            } catch (o) {}
+        }, a);
+    }
+    expect_stdout: "PASS"
+}