This commit is contained in:
Alex Lam S.L 2017-11-03 18:00:50 +00:00 committed by GitHub
commit ca2dadf1d7
3 changed files with 17 additions and 33 deletions

View File

@ -4230,26 +4230,13 @@ merge(Compressor.prototype, {
} }
} }
if (init) { if (init) {
var value_length = init.optimize(compressor).print_to_string().length; d.should_replace = has_symbol_ref(fixed) ? function() {
var fn;
if (has_symbol_ref(fixed)) {
fn = function() {
var result = init.optimize(compressor); var result = init.optimize(compressor);
return result === init ? result.clone(true) : result; return result === init ? result.clone(true) : result;
}; } : function() {
} else {
value_length = Math.min(value_length, fixed.print_to_string().length);
fn = function() {
var result = best_of_expression(init.optimize(compressor), fixed); var result = best_of_expression(init.optimize(compressor), fixed);
return result === init || result === fixed ? result.clone(true) : result; 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;
} else { } else {
d.should_replace = false; d.should_replace = false;
} }

View File

@ -47,25 +47,23 @@ collapse_vars_side_effects_1: {
} }
expect: { expect: {
function f1() { function f1() {
var s = "abcdef", i = 2; var i = 2;
console.log.bind(console)(s.charAt(i++), s.charAt(i++), s.charAt(i++), 7); console.log.bind(console)("abcdef".charAt(i++), "abcdef".charAt(i++), "abcdef".charAt(i++), 7);
} }
function f2() { function f2() {
var log = console.log.bind(console), var log = console.log.bind(console),
s = "abcdef",
i = 2, i = 2,
x = s.charAt(i++), x = "abcdef".charAt(i++),
y = s.charAt(i++), y = "abcdef".charAt(i++),
z = s.charAt(i++); z = "abcdef".charAt(i++);
log(x, i, y, z, 7); log(x, i, y, z, 7);
} }
function f3() { function f3() {
var s = "abcdef", var i = 2,
i = 2,
log = console.log.bind(console), log = console.log.bind(console),
x = s.charAt(i++), x = "abcdef".charAt(i++),
y = s.charAt(i++); y = "abcdef".charAt(i++);
log(x, s.charAt(i++), y, 7); log(x, "abcdef".charAt(i++), y, 7);
} }
function f4() { function f4() {
var i = 10, var i = 10,

View File

@ -44,8 +44,7 @@ chained_evaluation_2: {
expect: { expect: {
(function() { (function() {
(function() { (function() {
var b = "long piece of string"; f("long piece of string").bar = "long piece of string";
f(b).bar = b;
})(); })();
})(); })();
} }