fix corner case in `rests` (#5129)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 19 Sep 2021 21:02:35 +0000 (22:02 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Sep 2021 21:02:35 +0000 (05:02 +0800)
fixes #5128

lib/compress.js
test/compress/rests.js

index 1c4df6c..99d9b9c 100644 (file)
@@ -5563,6 +5563,7 @@ merge(Compressor.prototype, {
                     fn = fn.fixed_value();
                 }
                 if (!(fn instanceof AST_Defun || fn instanceof AST_Function)) break;
+                if (fn.rest) break;
                 if (fn.uses_arguments) break;
                 if (fn === call.expression) {
                     if (fn.parent_scope !== self) break;
index 24c6f87..7b793c5 100644 (file)
@@ -1109,3 +1109,45 @@ issue_5108: {
     expect_stdout: "PASS"
     node_version: ">=6"
 }
+
+issue_5128_1: {
+    options = {
+        inline: true,
+    }
+    input: {
+        console.log(function() {
+            return function f(...[ a ]) {
+                return a;
+            }("PASS");
+        }());
+    }
+    expect: {
+        console.log(function f(...[ a ]) {
+            return a;
+        }("PASS"));
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}
+
+issue_5128_2: {
+    options = {
+        inline: true,
+        keep_fnames: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            return function f(...[ a ]) {
+                return a;
+            }("PASS");
+        }());
+    }
+    expect: {
+        console.log(function f(...[ a ]) {
+            return a;
+        }("PASS"));
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}