diff --git a/lib/compress.js b/lib/compress.js index 22c79b81..9245dccc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3547,9 +3547,8 @@ merge(Compressor.prototype, { if (d.should_replace === undefined) { var init = fixed.evaluate(compressor); if (init !== fixed) { - init = make_node_from_constant(init, fixed).optimize(compressor); - init = best_of_expression(init, fixed); - var value = init.print_to_string().length; + init = make_node_from_constant(init, fixed); + var value = best_of_expression(init.optimize(compressor), fixed).print_to_string().length; var name = d.name.length; var freq = d.references.length; var overhead = d.global || !freq ? 0 : (name + 2 + value) / freq; @@ -3559,7 +3558,7 @@ merge(Compressor.prototype, { } } if (d.should_replace) { - return d.should_replace.clone(true); + return best_of_expression(d.should_replace.clone(true).optimize(compressor), fixed.clone(true)); } } } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index cdc4ef20..f5b16ebe 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -1866,3 +1866,34 @@ delay_def: { } 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" +}