diff options
author | Dan Wolff <dan.d.wolff@gmail.com> | 2014-07-01 00:51:42 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2014-07-01 11:06:51 +0300 |
commit | 8511e80f489b4b7e3de8122009d492123a314ca8 (patch) | |
tree | d7b841c436e6d2d7e008ddafeeb832c4cec4e82d /lib/compress.js | |
parent | 91bc3f1f92b0d4e75ff40364458121e3df961cd0 (diff) | |
download | tracifyjs-8511e80f489b4b7e3de8122009d492123a314ca8.tar.gz tracifyjs-8511e80f489b4b7e3de8122009d492123a314ca8.zip |
Evaluate "foo".length ==> 3
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index b589aca5..fd3f7a21 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -775,6 +775,14 @@ merge(Compressor.prototype, { if (d && d.constant && d.init) return ev(d.init, compressor); throw def; }); + def(AST_Dot, function(compressor){ + if (compressor.option("unsafe") && this.property == "length") { + var str = ev(this.expression, compressor); + if (typeof str == "string") + return str.length; + } + throw def; + }); })(function(node, func){ node.DEFMETHOD("_eval", func); }); @@ -2349,7 +2357,7 @@ merge(Compressor.prototype, { return make_node(AST_Dot, self, { expression : self.expression, property : prop - }); + }).optimize(compressor); } var v = parseFloat(prop); if (!isNaN(v) && v.toString() == prop) { @@ -2361,6 +2369,10 @@ merge(Compressor.prototype, { return self; }); + OPT(AST_Dot, function(self, compressor){ + return self.evaluate(compressor)[0]; + }); + function literals_in_boolean_context(self, compressor) { if (compressor.option("booleans") && compressor.in_boolean_context()) { return make_node(AST_True, self); |