eliminate noop calls more aggressively (#2559)
This commit is contained in:
@@ -3460,11 +3460,11 @@ merge(Compressor.prototype, {
|
|||||||
OPT(AST_Call, function(self, compressor){
|
OPT(AST_Call, function(self, compressor){
|
||||||
var exp = self.expression;
|
var exp = self.expression;
|
||||||
var fn = exp;
|
var fn = exp;
|
||||||
|
if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
|
||||||
|
fn = fn.fixed_value();
|
||||||
|
}
|
||||||
if (compressor.option("unused")
|
if (compressor.option("unused")
|
||||||
&& (fn instanceof AST_Function
|
&& fn instanceof AST_Function
|
||||||
|| compressor.option("reduce_vars")
|
|
||||||
&& fn instanceof AST_SymbolRef
|
|
||||||
&& (fn = fn.fixed_value()) instanceof AST_Function)
|
|
||||||
&& !fn.uses_arguments
|
&& !fn.uses_arguments
|
||||||
&& !fn.uses_eval) {
|
&& !fn.uses_eval) {
|
||||||
var pos = 0, last = 0;
|
var pos = 0, last = 0;
|
||||||
@@ -3683,14 +3683,15 @@ merge(Compressor.prototype, {
|
|||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exp instanceof AST_Function) {
|
if (fn instanceof AST_Function) {
|
||||||
if (compressor.option("inline")
|
if (compressor.option("inline")
|
||||||
&& !exp.name
|
&& exp === fn
|
||||||
&& !exp.uses_arguments
|
&& !fn.name
|
||||||
&& !exp.uses_eval
|
&& !fn.uses_arguments
|
||||||
&& exp.body.length == 1
|
&& !fn.uses_eval
|
||||||
&& !exp.contains_this()
|
&& fn.body.length == 1
|
||||||
&& all(exp.argnames, function(arg) {
|
&& !fn.contains_this()
|
||||||
|
&& all(fn.argnames, function(arg) {
|
||||||
return arg.__unused;
|
return arg.__unused;
|
||||||
})
|
})
|
||||||
&& !self.has_pure_annotation(compressor)) {
|
&& !self.has_pure_annotation(compressor)) {
|
||||||
@@ -3708,7 +3709,7 @@ merge(Compressor.prototype, {
|
|||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (compressor.option("side_effects") && all(exp.body, is_empty)) {
|
if (compressor.option("side_effects") && all(fn.body, is_empty)) {
|
||||||
var args = self.args.concat(make_node(AST_Undefined, self));
|
var args = self.args.concat(make_node(AST_Undefined, self));
|
||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -652,3 +652,23 @@ issue_2531_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "Greeting: Hello"
|
expect_stdout: "Greeting: Hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
empty_body: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function noop() {}
|
||||||
|
noop();
|
||||||
|
return noop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function noop() {}
|
||||||
|
return noop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user