From b12379d465621a3297a6459fbcffa89bee5eebed Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Mon, 18 Dec 2017 14:07:21 +0800 Subject: [PATCH] ensure order of execution --- lib/compress.js | 8 +++----- test/compress/functions.js | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index c3c710f4..41614f94 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3847,18 +3847,16 @@ merge(Compressor.prototype, { } break; case "apply": - if (self.args[1] instanceof AST_Array) { - var expressions = self.args.slice(2); + if (self.args.length == 2 && self.args[1] instanceof AST_Array) { var args = self.args[1].elements.slice(); args.unshift(self.args[0]); - expressions.unshift(make_node(AST_Call, self, { + return 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); + }).optimize(compressor); } break; case "call": diff --git a/test/compress/functions.js b/test/compress/functions.js index 28419d17..23ed22df 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -940,12 +940,18 @@ unsafe_apply_1: { (function(a, b) { console.log(this, a, b); }).apply("foo", [ "bar" ]); + (function(a, b) { + console.log(a, b); + }).apply("foo", [ "bar" ], "baz"); } expect: { console.log("bar", void 0); (function(a, b) { console.log(this, a, b); }).call("foo", "bar"); + (function(a, b) { + console.log(a, b); + }).apply("foo", [ "bar" ], "baz"); } expect_stdout: true }