enhance inline (#3760)
This commit is contained in:
@@ -5813,12 +5813,24 @@ merge(Compressor.prototype, {
|
||||
var is_func = fn instanceof AST_Lambda;
|
||||
var stat = is_func && fn.first_statement();
|
||||
var can_inline = compressor.option("inline") && !self.is_expr_pure(compressor);
|
||||
if (exp === fn && can_inline && stat instanceof AST_Return) {
|
||||
if (can_inline && stat instanceof AST_Return) {
|
||||
var value = stat.value;
|
||||
if (!value || value.is_constant_expression()) {
|
||||
if (exp === fn && (!value || value.is_constant_expression())) {
|
||||
var args = self.args.concat(value || make_node(AST_Undefined, self));
|
||||
return make_sequence(self, args).optimize(compressor);
|
||||
}
|
||||
var funarg, pos;
|
||||
if (value instanceof AST_SymbolRef
|
||||
&& (funarg = resolve_funarg(value.definition().orig))
|
||||
&& (pos = fn.argnames.indexOf(funarg)) >= 0
|
||||
&& (pos >= self.args.length - 1 || all(self.args.slice(pos), function(funarg) {
|
||||
return !funarg.has_side_effects(compressor);
|
||||
}))) {
|
||||
var args = self.args.slice();
|
||||
args.push(args.splice(pos, 1)[0] || make_node(AST_Undefined, self));
|
||||
var node = make_sequence(self, args).optimize(compressor);
|
||||
return maintain_this_binding(compressor, compressor.parent(), compressor.self(), node);
|
||||
}
|
||||
}
|
||||
if (is_func) {
|
||||
var def, value, scope, in_loop, level = -1;
|
||||
@@ -5837,7 +5849,8 @@ merge(Compressor.prototype, {
|
||||
&& can_inject_symbols()) {
|
||||
fn._squeezed = true;
|
||||
if (exp !== fn) fn.parent_scope = exp.scope;
|
||||
return make_sequence(self, flatten_fn()).optimize(compressor);
|
||||
var node = make_sequence(self, flatten_fn()).optimize(compressor);
|
||||
return maintain_this_binding(compressor, compressor.parent(), compressor.self(), node);
|
||||
}
|
||||
if (compressor.option("side_effects")
|
||||
&& all(fn.body, is_empty)
|
||||
@@ -5864,6 +5877,14 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
return try_evaluate(compressor, self);
|
||||
|
||||
function resolve_funarg(orig) {
|
||||
var funarg;
|
||||
for (var i = 0; orig[i] instanceof AST_SymbolFunarg; i++) {
|
||||
funarg = orig[i];
|
||||
}
|
||||
return funarg;
|
||||
}
|
||||
|
||||
function return_value(stat) {
|
||||
if (!stat) return make_node(AST_Undefined, self);
|
||||
if (stat instanceof AST_Return) {
|
||||
|
||||
Reference in New Issue
Block a user