handle negated constants correctly in collapse_vars (#2975)
fixes #2974
This commit is contained in:
@@ -778,8 +778,7 @@ merge(Compressor.prototype, {
|
||||
lhs = lhs.fixed_value();
|
||||
}
|
||||
if (!lhs) return true;
|
||||
if (lhs instanceof AST_RegExp) return false;
|
||||
if (lhs instanceof AST_Constant) return true;
|
||||
if (lhs.is_constant()) return true;
|
||||
return is_lhs_read_only(lhs);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -5207,3 +5207,39 @@ collapse_rhs_undefined: {
|
||||
}
|
||||
expect_stdout: "true true true"
|
||||
}
|
||||
|
||||
issue_2974: {
|
||||
options = {
|
||||
booleans: true,
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
loops: true,
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var c = 0;
|
||||
(function f(b) {
|
||||
var a = 2;
|
||||
do {
|
||||
b && b[b];
|
||||
b && (b.null = -4);
|
||||
c++;
|
||||
} while (b.null && --a > 0);
|
||||
})(true);
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = 0;
|
||||
(function(b) {
|
||||
var a = 2;
|
||||
for (; b.null = -4, c++, b.null && --a > 0;);
|
||||
})(!0),
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user