compress function.call()

This commit is contained in:
alexlamsl 2017-12-18 05:14:11 +08:00
parent b29fc8b27c
commit fb0f8fb899
2 changed files with 37 additions and 0 deletions

View File

@ -3846,6 +3846,17 @@ merge(Compressor.prototype, {
}
}
break;
case "call":
if (exp.expression instanceof AST_Function && !exp.expression.contains_this()) {
return make_sequence(this, [
self.args[0],
make_node(AST_Call, self, {
expression: exp.expression,
args: self.args.slice(1)
})
]).optimize(compressor);
}
break;
}
}
if (compressor.option("unsafe_Func")

View File

@ -923,3 +923,29 @@ issue_2604_2: {
}
expect_stdout: "PASS"
}
unsafe_call: {
options = {
inline: true,
passes: 2,
reduce_vars: true,
side_effects: true,
unsafe: true,
unused: true,
}
input: {
(function(a, b) {
console.log(a, b);
}).call("foo", "bar");
(function(a, b) {
console.log(this, a, b);
}).call("foo", "bar");
}
expect: {
console.log("bar", void 0);
(function(a, b) {
console.log(this, a, b);
}).call("foo", "bar");
}
expect_stdout: true
}