Compare commits

..

3 Commits

Author SHA1 Message Date
Mihai Bazon
eab99a1c3d 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.
2013-11-06 10:48:48 +02:00
Mihai Bazon
19e2fb134d v2.4.3 2013-11-06 10:21:29 +02:00
Mihai Bazon
f4919e3a25 Do not lift sequence from right-hand side of binary operation. Fix #343 2013-11-06 10:18:28 +02:00
3 changed files with 15 additions and 5 deletions

View File

@@ -1865,6 +1865,14 @@ merge(Compressor.prototype, {
return self.evaluate(compressor)[0]; 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){ AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
if (compressor.option("sequences")) { if (compressor.option("sequences")) {
if (this.left instanceof AST_Seq) { if (this.left instanceof AST_Seq) {
@@ -1876,8 +1884,8 @@ merge(Compressor.prototype, {
return seq; return seq;
} }
if (this.right instanceof AST_Seq if (this.right instanceof AST_Seq
&& !(this.operator == "||" || this.operator == "&&") && this instanceof AST_Assign
&& !this.left.has_side_effects(compressor)) { && !has_side_effects_or_prop_access(this.left, compressor)) {
var seq = this.right; var seq = this.right;
var x = seq.to_array(); var x = seq.to_array();
this.right = x.pop(); this.right = x.pop();

View File

@@ -3,7 +3,7 @@
"description": "JavaScript parser, mangler/compressor and beautifier toolkit", "description": "JavaScript parser, mangler/compressor and beautifier toolkit",
"homepage": "http://lisperator.net/uglifyjs", "homepage": "http://lisperator.net/uglifyjs",
"main": "tools/node.js", "main": "tools/node.js",
"version": "2.4.2", "version": "2.4.3",
"engines": { "node" : ">=0.4.0" }, "engines": { "node" : ">=0.4.0" },
"maintainers": [{ "maintainers": [{
"name": "Mihai Bazon", "name": "Mihai Bazon",

View File

@@ -101,10 +101,12 @@ lift_sequences_1: {
lift_sequences_2: { lift_sequences_2: {
options = { sequences: true, evaluate: true }; options = { sequences: true, evaluate: true };
input: { input: {
q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5); foo.x = (foo = {}, 10);
bar = (bar = {}, 10);
} }
expect: { expect: {
foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36 foo.x = (foo = {}, 10),
bar = {}, bar = 10;
} }
} }