fix corner case in arguments (#4411)

fixes #4410
This commit is contained in:
Alex Lam S.L
2020-12-18 20:53:53 +00:00
committed by GitHub
parent 7d9dad0289
commit 0f55bd92f1
2 changed files with 72 additions and 0 deletions

View File

@@ -9905,6 +9905,7 @@ merge(Compressor.prototype, {
} else if (argname instanceof AST_Destructured) { } else if (argname instanceof AST_Destructured) {
argname = null; argname = null;
} else if (argname && (compressor.has_directive("use strict") } else if (argname && (compressor.has_directive("use strict")
|| fn.name
|| !(fn_parent instanceof AST_Call && index < fn_parent.args.length) || !(fn_parent instanceof AST_Call && index < fn_parent.args.length)
|| !all(fn.argnames, function(argname) { || !all(fn.argnames, function(argname) {
return !(argname instanceof AST_Destructured); return !(argname instanceof AST_Destructured);

View File

@@ -871,3 +871,74 @@ issue_4397: {
} }
expect_stdout: "string" 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"
}