aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-18 20:53:53 +0000
committerGitHub <noreply@github.com>2020-12-19 04:53:53 +0800
commit0f55bd92f18bd27628f1cfd10c9fb5d70f4d4d29 (patch)
treedaec0309f0365633f7afedcb0af146814d916769
parent7d9dad02899fdc0a46ab030f9663e7f5bec2003b (diff)
downloadtracifyjs-0f55bd92f18bd27628f1cfd10c9fb5d70f4d4d29.tar.gz
tracifyjs-0f55bd92f18bd27628f1cfd10c9fb5d70f4d4d29.zip
fix corner case in `arguments` (#4411)
fixes #4410
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/arguments.js71
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index ab68c45d..f33b97bc 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -9905,6 +9905,7 @@ merge(Compressor.prototype, {
} else if (argname instanceof AST_Destructured) {
argname = null;
} else if (argname && (compressor.has_directive("use strict")
+ || fn.name
|| !(fn_parent instanceof AST_Call && index < fn_parent.args.length)
|| !all(fn.argnames, function(argname) {
return !(argname instanceof AST_Destructured);
diff --git a/test/compress/arguments.js b/test/compress/arguments.js
index c3ef226e..39628b50 100644
--- a/test/compress/arguments.js
+++ b/test/compress/arguments.js
@@ -871,3 +871,74 @@ issue_4397: {
}
expect_stdout: "string"
}
+
+issue_4410_1: {
+ options = {
+ arguments: true,
+ conditionals: true,
+ evaluate: true,
+ reduce_vars: true,
+ }
+ input: {
+ (function(a) {
+ console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+ })(1);
+ }
+ expect: {
+ (function(a) {
+ console.log(a === (a = 0) ? "FAIL" : "PASS");
+ })(1);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_4410_2: {
+ options = {
+ arguments: true,
+ conditionals: true,
+ evaluate: true,
+ reduce_vars: true,
+ }
+ input: {
+ (function f(a) {
+ console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+ })(1);
+ }
+ expect: {
+ (function f(a) {
+ console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+ })(1);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_4410_3: {
+ options = {
+ arguments: true,
+ }
+ input: {
+ var a = 1;
+ (function f(b) {
+ a-- && f();
+ for (var c = 2; c--;)
+ switch (arguments[0]) {
+ case b = 42:
+ case 42:
+ console.log("PASS");
+ }
+ })(null);
+ }
+ expect: {
+ var a = 1;
+ (function f(b) {
+ a-- && f();
+ for (var c = 2; c--;)
+ switch (arguments[0]) {
+ case b = 42:
+ case 42:
+ console.log("PASS");
+ }
+ })(null);
+ }
+ expect_stdout: "PASS"
+}