aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-06-01 00:56:28 +0800
committerGitHub <noreply@github.com>2017-06-01 00:56:28 +0800
commit17e73121fa641c14fd9f4cdd3310bf3e8ec037d0 (patch)
treed24c9fdaf9789f97bf611a01fda99ba4061f8bfd /lib
parentf71e8fd9488b28b92e6897254b7a54cf51471557 (diff)
downloadtracifyjs-17e73121fa641c14fd9f4cdd3310bf3e8ec037d0.tar.gz
tracifyjs-17e73121fa641c14fd9f4cdd3310bf3e8ec037d0.zip
enhance `unsafe` `evaluate` (#2037)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 32a4d603..a928d7b7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1665,6 +1665,26 @@ merge(Compressor.prototype, {
}
throw def;
});
+ def(AST_Call, function(compressor){
+ var exp = this.expression;
+ if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
+ var key = exp.property;
+ if (key instanceof AST_Node) {
+ key = ev(key, compressor);
+ }
+ var val = ev(exp.expression, compressor);
+ var fn = val[key];
+ if (typeof fn == "function") {
+ return fn.apply(val, this.args.map(function(arg) {
+ return ev(arg, compressor);
+ }));
+ }
+ }
+ throw def;
+ });
+ def(AST_New, function(compressor){
+ throw def;
+ });
})(function(node, func){
node.DEFMETHOD("_eval", func);
});
@@ -3144,6 +3164,11 @@ merge(Compressor.prototype, {
&& is_iife_call(self)) {
return self.negate(compressor, true);
}
+ var ev = self.evaluate(compressor);
+ if (ev !== self) {
+ ev = make_node_from_constant(ev, self).optimize(compressor);
+ return best_of(compressor, ev, self);
+ }
return self;
});