fix corner case in collapse_vars (#4048)

fixes #4047
This commit is contained in:
Alex Lam S.L
2020-08-09 22:48:56 +01:00
committed by GitHub
parent e2237d8cd2
commit 49670d216b
2 changed files with 62 additions and 3 deletions

View File

@@ -1984,9 +1984,12 @@ merge(Compressor.prototype, {
if (expr.name instanceof AST_SymbolFunarg) { if (expr.name instanceof AST_SymbolFunarg) {
var index = compressor.self().argnames.indexOf(expr.name); var index = compressor.self().argnames.indexOf(expr.name);
var args = compressor.parent().args; var args = compressor.parent().args;
if (args[index]) args[index] = make_node(AST_Number, args[index], { if (args[index]) {
args[index] = make_node(AST_Number, args[index], {
value: 0 value: 0
}); });
expr.name.definition().fixed = false;
}
return true; return true;
} }
var end = hit_stack.length - 1; var end = hit_stack.length - 1;

View File

@@ -8391,3 +8391,59 @@ issue_4040: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_4047_1: {
options = {
collapse_vars: true,
evaluate: true,
inline: true,
reduce_vars: true,
sequences: true,
toplevel: true,
unused: true,
}
input: {
var b = 1;
console.log(+function(a) {
b = a;
(a >>= 0) && console.log("PASS");
}(--b + (0 !== typeof A)));
}
expect: {
var b = 1;
var a;
console.log((a = --b + ((a = 0) !== typeof A), +void ((a >>= 0) && console.log("PASS"))));
}
expect_stdout: [
"PASS",
"NaN",
]
}
issue_4047_2: {
options = {
collapse_vars: true,
evaluate: true,
inline: true,
passes: 2,
reduce_vars: true,
sequences: true,
toplevel: true,
unused: true,
}
input: {
var b = 1;
console.log(+function(a) {
b = a;
(a >>= 0) && console.log("PASS");
}(--b + (0 !== typeof A)));
}
expect: {
var a;
console.log((a = +(0 !== typeof A), +void ((a >>= 0) && console.log("PASS"))));
}
expect_stdout: [
"PASS",
"NaN",
]
}