fix incorrect context in variable substitution
`AST_Node.optimize()` is context-aware, so don't cache its results to be used elsewhere.
This commit is contained in:
parent
06cdb74279
commit
1a8c9dfdc4
|
|
@ -3547,9 +3547,8 @@ merge(Compressor.prototype, {
|
||||||
if (d.should_replace === undefined) {
|
if (d.should_replace === undefined) {
|
||||||
var init = fixed.evaluate(compressor);
|
var init = fixed.evaluate(compressor);
|
||||||
if (init !== fixed) {
|
if (init !== fixed) {
|
||||||
init = make_node_from_constant(init, fixed).optimize(compressor);
|
init = make_node_from_constant(init, fixed);
|
||||||
init = best_of_expression(init, fixed);
|
var value = best_of_expression(init.optimize(compressor), fixed).print_to_string().length;
|
||||||
var value = init.print_to_string().length;
|
|
||||||
var name = d.name.length;
|
var name = d.name.length;
|
||||||
var freq = d.references.length;
|
var freq = d.references.length;
|
||||||
var overhead = d.global || !freq ? 0 : (name + 2 + value) / freq;
|
var overhead = d.global || !freq ? 0 : (name + 2 + value) / freq;
|
||||||
|
|
@ -3559,7 +3558,7 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d.should_replace) {
|
if (d.should_replace) {
|
||||||
return d.should_replace.clone(true);
|
return best_of_expression(d.should_replace.clone(true).optimize(compressor), fixed.clone(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1866,3 +1866,34 @@ delay_def: {
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
booleans: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
if (a != 0);
|
||||||
|
switch (a) {
|
||||||
|
case 0:
|
||||||
|
return "FAIL";
|
||||||
|
case false:
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}(false));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
if (!1);
|
||||||
|
switch (!1) {
|
||||||
|
case 0:
|
||||||
|
return "FAIL";
|
||||||
|
case !1:
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}(!1));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user