fix corner case in evaluate (#5139)

fixes #5138
This commit is contained in:
Alex Lam S.L
2021-09-30 19:52:21 +01:00
committed by GitHub
parent 0b2573c3fa
commit 940887f20f
2 changed files with 42 additions and 4 deletions

View File

@@ -4805,10 +4805,11 @@ merge(Compressor.prototype, {
if (!all(fn.argnames, function(sym, index) {
if (sym instanceof AST_DefaultValue) {
if (!args) return false;
if (args[index] !== undefined) return false;
if (args[index] === undefined) {
var value = sym.value._eval(compressor, ignore_side_effects, cached, depth);
if (value === sym.value) return false;
args[index] = value;
}
sym = sym.name;
}
return !(sym instanceof AST_Destructured);
@@ -4842,6 +4843,9 @@ merge(Compressor.prototype, {
if (!args || all(fn.argnames, function(sym, i) {
return assign(sym, args[i]);
}) && !(fn.rest && !assign(fn.rest, args.slice(fn.argnames.length))) || ignore_side_effects) {
if (ignore_side_effects) fn.argnames.forEach(function(sym) {
if (sym instanceof AST_DefaultValue) sym.value.walk(scan_modified);
});
fn.evaluating = true;
val = val._eval(compressor, ignore_side_effects, cached, depth);
delete fn.evaluating;

View File

@@ -1904,3 +1904,37 @@ issue_5065: {
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5138_1: {
options = {
evaluate: true,
}
input: {
console.log(function(a, b = a = "FAIL") {
return a;
}() && "PASS");
}
expect: {
console.log(function(a, b = a = "FAIL") {
return a;
}() && "PASS");
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5138_2: {
options = {
evaluate: true,
}
input: {
console.log(function(a, b = a = "FAIL 1") {
return a;
}(null, "FAIL 2") || "PASS");
}
expect: {
console.log((null, "PASS"));
}
expect_stdout: "PASS"
node_version: ">=6"
}