diff --git a/lib/compress.js b/lib/compress.js index f09f2b9b..cfe63e54 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4230,26 +4230,13 @@ merge(Compressor.prototype, { } } if (init) { - var value_length = init.optimize(compressor).print_to_string().length; - var fn; - if (has_symbol_ref(fixed)) { - fn = function() { - var result = init.optimize(compressor); - return result === init ? result.clone(true) : result; - }; - } else { - value_length = Math.min(value_length, fixed.print_to_string().length); - fn = function() { - var result = best_of_expression(init.optimize(compressor), fixed); - return result === init || result === fixed ? result.clone(true) : result; - }; - } - var name_length = d.name.length; - var overhead = 0; - if (compressor.option("unused") && !compressor.exposed(d)) { - overhead = (name_length + 2 + value_length) / d.references.length; - } - d.should_replace = value_length <= name_length + overhead ? fn : false; + d.should_replace = has_symbol_ref(fixed) ? function() { + var result = init.optimize(compressor); + return result === init ? result.clone(true) : result; + } : function() { + var result = best_of_expression(init.optimize(compressor), fixed); + return result === init || result === fixed ? result.clone(true) : result; + }; } else { d.should_replace = false; } diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index b5b97d24..1e44e6e1 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -47,25 +47,23 @@ collapse_vars_side_effects_1: { } expect: { function f1() { - var s = "abcdef", i = 2; - console.log.bind(console)(s.charAt(i++), s.charAt(i++), s.charAt(i++), 7); + var i = 2; + console.log.bind(console)("abcdef".charAt(i++), "abcdef".charAt(i++), "abcdef".charAt(i++), 7); } function f2() { var log = console.log.bind(console), - s = "abcdef", i = 2, - x = s.charAt(i++), - y = s.charAt(i++), - z = s.charAt(i++); + x = "abcdef".charAt(i++), + y = "abcdef".charAt(i++), + z = "abcdef".charAt(i++); log(x, i, y, z, 7); } function f3() { - var s = "abcdef", - i = 2, + var i = 2, log = console.log.bind(console), - x = s.charAt(i++), - y = s.charAt(i++); - log(x, s.charAt(i++), y, 7); + x = "abcdef".charAt(i++), + y = "abcdef".charAt(i++); + log(x, "abcdef".charAt(i++), y, 7); } function f4() { var i = 10, diff --git a/test/compress/issue-1609.js b/test/compress/issue-1609.js index dffa54a5..86617e19 100644 --- a/test/compress/issue-1609.js +++ b/test/compress/issue-1609.js @@ -44,8 +44,7 @@ chained_evaluation_2: { expect: { (function() { (function() { - var b = "long piece of string"; - f(b).bar = b; + f("long piece of string").bar = "long piece of string"; })(); })(); }