extend to apply and function references
This commit is contained in:
parent
fb0f8fb899
commit
3bd99ccdd8
|
|
@ -3846,8 +3846,27 @@ merge(Compressor.prototype, {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case "apply":
|
||||
if (self.args[1] instanceof AST_Array) {
|
||||
var expressions = self.args.slice(2);
|
||||
var args = self.args[1].elements.slice();
|
||||
args.unshift(self.args[0]);
|
||||
expressions.unshift(make_node(AST_Call, self, {
|
||||
expression: make_node(AST_Dot, exp, {
|
||||
expression: exp.expression,
|
||||
property: "call"
|
||||
}),
|
||||
args: args
|
||||
}));
|
||||
return make_sequence(self, expressions).optimize(compressor);
|
||||
}
|
||||
break;
|
||||
case "call":
|
||||
if (exp.expression instanceof AST_Function && !exp.expression.contains_this()) {
|
||||
var func = exp.expression;
|
||||
if (func instanceof AST_SymbolRef) {
|
||||
func = func.fixed_value();
|
||||
}
|
||||
if (func instanceof AST_Function && !func.contains_this()) {
|
||||
return make_sequence(this, [
|
||||
self.args[0],
|
||||
make_node(AST_Call, self, {
|
||||
|
|
|
|||
|
|
@ -924,7 +924,67 @@ issue_2604_2: {
|
|||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
unsafe_call: {
|
||||
unsafe_apply_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a, b) {
|
||||
console.log(a, b);
|
||||
}).apply("foo", [ "bar" ]);
|
||||
(function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}).apply("foo", [ "bar" ]);
|
||||
}
|
||||
expect: {
|
||||
console.log("bar", void 0);
|
||||
(function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}).call("foo", "bar");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_apply_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function foo() {
|
||||
console.log(a, b);
|
||||
}
|
||||
var bar = function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}
|
||||
(function() {
|
||||
foo.apply("foo", [ "bar" ]);
|
||||
bar.apply("foo", [ "bar" ]);
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
function foo() {
|
||||
console.log(a, b);
|
||||
}
|
||||
var bar = function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}
|
||||
(function() {
|
||||
foo("bar");
|
||||
bar.call("foo", "bar");
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_call_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
|
|
@ -949,3 +1009,37 @@ unsafe_call: {
|
|||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_call_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function foo() {
|
||||
console.log(a, b);
|
||||
}
|
||||
var bar = function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}
|
||||
(function() {
|
||||
foo.call("foo", "bar");
|
||||
bar.call("foo", "bar");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
function foo() {
|
||||
console.log(a, b);
|
||||
}
|
||||
var bar = function(a, b) {
|
||||
console.log(this, a, b);
|
||||
}
|
||||
(function() {
|
||||
foo("bar");
|
||||
bar.call("foo", "bar");
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user