fix corner case in `ie8` & `reduce_vars` (#4020)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 21 Jul 2020 08:17:02 +0000 (09:17 +0100)
committeralexlamsl <alexlamsl@gmail.com>
Tue, 21 Jul 2020 09:22:18 +0000 (17:22 +0800)
fixes #4019

lib/compress.js
test/compress/drop-unused.js
test/compress/ie8.js

index 8ea5d8c..1da4995 100644 (file)
@@ -894,6 +894,7 @@ merge(Compressor.prototype, {
             d.assignments++;
             var fixed = d.fixed;
             if (safe_to_read(tw, d) && safe_to_assign(tw, d)) {
+                if (d.single_use) d.single_use = false;
                 push_ref(d, exp);
                 mark(tw, d);
                 d.fixed = function() {
index 2672175..ee06199 100644 (file)
@@ -1729,7 +1729,7 @@ chained_3: {
     }
     expect: {
         console.log(function(a, b) {
-            var c = 2;
+            var c = b;
             b++;
             return c;
         }(0, 2));
index 2115dbc..8ed2310 100644 (file)
@@ -2634,3 +2634,30 @@ issue_4015: {
     }
     expect_stdout: "1"
 }
+
+issue_4019: {
+    options = {
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    mangle = {
+        ie8: true,
+        toplevel: true,
+    }
+    input: {
+        var a = function() {
+            try {
+                console.log("FAIL");
+            } catch (b) {}
+        }, a = (console.log(a.length), ++a);
+    }
+    expect: {
+        var o = function() {
+            try {
+                console.log("FAIL");
+            } catch (o) {}
+        }, o = (console.log(o.length), ++o);
+    }
+    expect_stdout: "0"
+}