fix corner case in `unused` (#4850)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 7 Apr 2021 22:31:15 +0000 (23:31 +0100)
committerGitHub <noreply@github.com>
Wed, 7 Apr 2021 22:31:15 +0000 (06:31 +0800)
fixes #4849

lib/compress.js
test/compress/exponentiation.js
test/compress/spreads.js

index 5a9c8b7..437baab 100644 (file)
@@ -9393,6 +9393,7 @@ merge(Compressor.prototype, {
             var seq = lift_sequence_in_expression(self, compressor);
             if (seq !== self) return seq.optimize(compressor);
         }
+        if (compressor.option("unused")) drop_unused_call_args(self, compressor);
         if (compressor.option("unsafe")) {
             var exp = self.expression;
             if (is_undeclared_ref(exp)) {
index 1a678f5..e945e13 100644 (file)
@@ -99,8 +99,8 @@ issue_4664: {
     expect: {
         (function f() {
             new function(a) {
-                console.log(typeof f, 2 ** 30, typeof this);
-            }(0, A = 0);
+                console.log(typeof f, 1073741824, typeof this);
+            }(A = 0);
         })();
     }
     expect_stdout: "function 1073741824 object"
index 02bb3f0..4e5d0d9 100644 (file)
@@ -1045,3 +1045,26 @@ issue_4614: {
     expect_stdout: true
     node_version: ">=6"
 }
+
+issue_4849: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        while (function() {
+            while (!console);
+        }(new function(a) {
+            console.log(typeof { ...a });
+        }(function() {})));
+    }
+    expect: {
+        while (function() {
+            while (!console);
+        }(function(a) {
+            console.log(typeof { ...function() {} });
+        }()));
+    }
+    expect_stdout: "object"
+    node_version: ">=8"
+}