fix corner case in `unused` (#3963)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 7 Jun 2020 05:48:29 +0000 (06:48 +0100)
committerGitHub <noreply@github.com>
Sun, 7 Jun 2020 05:48:29 +0000 (13:48 +0800)
fixes #3962

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

index 6aa81a5..749abef 100644 (file)
@@ -4521,7 +4521,7 @@ merge(Compressor.prototype, {
                         var index = indexOf_assign(sym, def);
                         if (index >= 0) assign_in_use[sym.id][index] = assign;
                         sym.eliminated++;
-                        return assign.transform(tt);
+                        return assign;
                     }));
                 } else if (head.length > 0 || tail.length > 0) {
                     node.definitions = head.concat(tail);
index a4a8595..8c912a5 100644 (file)
@@ -2690,3 +2690,68 @@ issue_3956: {
         "1",
     ]
 }
+
+issue_3962_1: {
+    options = {
+        evaluate: true,
+        keep_fargs: "strict",
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 0;
+        function f(b, c) {
+            do {
+                var d = console + e, e = 0..toString() === b;
+            } while (0);
+            if (c) console.log("PASS");
+        }
+        var a = f(a--, 1);
+        a;
+    }
+    expect: {
+        var a = 0;
+        a = (function(c) {
+            do {
+                console;
+                0..toString();
+            } while (0);
+            if (c) console.log("PASS");
+        })((a--, 1));
+        void 0;
+    }
+    expect_stdout: "PASS"
+}
+
+issue_3962_2: {
+    options = {
+        keep_fargs: "strict",
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 0;
+        function f(b, c) {
+            do {
+                var d = console + e, e = 0..toString() === b;
+            } while (0);
+            if (c) console.log("PASS");
+        }
+        var a = f(a--, 1);
+        a;
+    }
+    expect: {
+        var a = 0;
+        a = (function(c) {
+            do {
+                console;
+                0..toString();
+            } while (0);
+            if (c) console.log("PASS");
+        })((a--, 1));
+    }
+    expect_stdout: "PASS"
+}