aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-09 00:38:51 +0000
committerGitHub <noreply@github.com>2021-01-09 08:38:51 +0800
commit770f3ba5fe6bba0768e881dd3fe46b2a21d4a5df (patch)
tree8ef6840f4e640039366031cbb68cf54dc78f953d
parent553034fe52e8c5c07aeaca7a9c97c9fcc3e2435e (diff)
downloadtracifyjs-770f3ba5fe6bba0768e881dd3fe46b2a21d4a5df.tar.gz
tracifyjs-770f3ba5fe6bba0768e881dd3fe46b2a21d4a5df.zip
fix corner cases with rest parameters (#4526)
fixes #4525
-rw-r--r--lib/compress.js6
-rw-r--r--test/compress/rests.js40
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8652d6e4..8aef5a71 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5669,8 +5669,9 @@ merge(Compressor.prototype, {
}
if (node.rest) {
node.rest = node.rest.transform(trimmer);
- if (node.rest instanceof AST_DestructuredArray && node.rest.elements.length == 0
- || node.rest instanceof AST_DestructuredObject && node.rest.properties.length == 0) {
+ if (!(node.uses_arguments && !tt.has_directive("use strict"))
+ && (node.rest instanceof AST_DestructuredArray && node.rest.elements.length == 0
+ || node.rest instanceof AST_DestructuredObject && node.rest.properties.length == 0)) {
node.rest = null;
}
}
@@ -10467,6 +10468,7 @@ merge(Compressor.prototype, {
argname = null;
} else if (compressor.has_directive("use strict")
|| fn.name
+ || fn.rest
|| !(fn_parent instanceof AST_Call && index < fn_parent.args.length)
|| !all(fn.argnames, function(argname) {
return argname instanceof AST_SymbolFunarg;
diff --git a/test/compress/rests.js b/test/compress/rests.js
index 1a27860d..f3c2af95 100644
--- a/test/compress/rests.js
+++ b/test/compress/rests.js
@@ -485,3 +485,43 @@ keep_arguments: {
expect_stdout: "PASS"
node_version: ">=6"
}
+
+issue_4525_1: {
+ options = {
+ arguments: true,
+ }
+ input: {
+ console.log(function(a, ...[]) {
+ a = "FAIL";
+ return arguments[0];
+ }("PASS"));
+ }
+ expect: {
+ console.log(function(a, ...[]) {
+ a = "FAIL";
+ return arguments[0];
+ }("PASS"));
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+issue_4525_2: {
+ options = {
+ unused: true,
+ }
+ input: {
+ console.log(function(a, ...[]) {
+ a = "FAIL";
+ return arguments[0];
+ }("PASS"));
+ }
+ expect: {
+ console.log(function(a, ...[]) {
+ a = "FAIL";
+ return arguments[0];
+ }("PASS"));
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}