diff options
author | Mihai Bazon <mihai@bazon.net> | 2013-11-06 10:47:36 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2013-11-06 10:48:48 +0200 |
commit | eab99a1c3d229f7e73b91b5a28e5ebf53a24671b (patch) | |
tree | 655479057eaedbaee56ead75168ca98ecc7ff5f2 /lib | |
parent | 19e2fb134d1c6d0fdf74b0d008d772c0283afb6e (diff) | |
download | tracifyjs-eab99a1c3d229f7e73b91b5a28e5ebf53a24671b.tar.gz tracifyjs-eab99a1c3d229f7e73b91b5a28e5ebf53a24671b.zip |
Better fix for #343
We can in fact lift sequences, but only if the operation is assignment and
the left-hand side has no side effects nor property access -- that should
guarantee that whatever we place before it cannot affect the sense of the
assignment.
Dropped contrived test case (too hard to support it now), added a more
meaningful one.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 59caa15c..f44277cd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1865,6 +1865,14 @@ merge(Compressor.prototype, { return self.evaluate(compressor)[0]; }); + function has_side_effects_or_prop_access(node, compressor) { + var save_pure_getters = compressor.option("pure_getters"); + compressor.options.pure_getters = false; + var ret = node.has_side_effects(compressor); + compressor.options.pure_getters = save_pure_getters; + return ret; + } + AST_Binary.DEFMETHOD("lift_sequences", function(compressor){ if (compressor.option("sequences")) { if (this.left instanceof AST_Seq) { @@ -1875,6 +1883,16 @@ merge(Compressor.prototype, { seq = AST_Seq.from_array(x).transform(compressor); return seq; } + if (this.right instanceof AST_Seq + && this instanceof AST_Assign + && !has_side_effects_or_prop_access(this.left, compressor)) { + var seq = this.right; + var x = seq.to_array(); + this.right = x.pop(); + x.push(this); + seq = AST_Seq.from_array(x).transform(compressor); + return seq; + } } return this; }); |