apply reduce_vars regardless of name length
Reverts #1459 back to simple replacements
This commit is contained in:
parent
c8b6f4733d
commit
958af035b6
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
})();
|
||||
})();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user