about
aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-12-18 16:23:39 +0800
committerGitHub <noreply@github.com>2017-12-18 16:23:39 +0800
commit8ddcbc39e617a3ce53a340303fd9ef3226ee0065 (patch)
treedfbd32b8dbd6f2471ff164256c9af084b0e60c9e /lib
parent0b0eac1d5dc6e1cc1e9bf3682871cafdda59066d (diff)
downloadtracifyjs-8ddcbc39e617a3ce53a340303fd9ef3226ee0065.tar.gz
tracifyjs-8ddcbc39e617a3ce53a340303fd9ef3226ee0065.zip
compress `apply()` & `call()` of `function` (#2613)
- `fn.apply(a, [ ... ])` => `fn.call(a, ...)` - `fn.call(a, ... )` => `a, fn(...)` where `fn` can be `function` literal or symbol reference linked through `reduce_vars`
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 735b4d2d..af1195d4 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3857,6 +3857,34 @@ merge(Compressor.prototype, {
}
}
break;
+ case "apply":
+ if (self.args.length == 2 && self.args[1] instanceof AST_Array) {
+ var args = self.args[1].elements.slice();
+ args.unshift(self.args[0]);
+ return make_node(AST_Call, self, {
+ expression: make_node(AST_Dot, exp, {
+ expression: exp.expression,
+ property: "call"
+ }),
+ args: args
+ }).optimize(compressor);
+ }
+ break;
+ case "call":
+ 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, {
+ expression: exp.expression,
+ args: self.args.slice(1)
+ })
+ ]).optimize(compressor);
+ }
+ break;
}
}
if (compressor.option("unsafe_Func")