diff options
-rw-r--r-- | lib/compress.js | 15 | ||||
-rw-r--r-- | test/compress/conditionals.js | 26 |
2 files changed, 30 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index 43ee1126..26d17295 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6673,7 +6673,7 @@ merge(Compressor.prototype, { && alt_tail instanceof AST_Assign && seq_tail.operator == alt_tail.operator && seq_tail.left.equivalent_to(alt_tail.left) - && (is_eq && !seq_tail.left.has_side_effects(compressor) + && (is_eq && seq_tail.left instanceof AST_SymbolRef || !condition.has_side_effects(compressor) && can_shift_lhs_of_tail(consequent) && can_shift_lhs_of_tail(alternative))) { @@ -6842,16 +6842,9 @@ merge(Compressor.prototype, { } function can_shift_lhs_of_tail(node) { - if (node === node.tail_node()) return true; - var exprs = node.expressions; - for (var i = exprs.length - 1; --i >= 0;) { - var expr = exprs[i]; - if (!(expr instanceof AST_Assign) && expr.has_side_effects(compressor) - || expr.operator != "=" - || expr.left.has_side_effects(compressor) - || expr.right.has_side_effects(compressor)) return false; - } - return true; + return node === node.tail_node() || all(node.expressions.slice(0, -1), function(expr) { + return !expr.has_side_effects(compressor); + }); } function pop_lhs(node) { diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index 27536b9f..3e7a0927 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -1489,3 +1489,29 @@ angularjs_chain: { } } } + +issue_3576: { + options = { + conditionals: true, + evaluate: true, + pure_getters: "strict", + reduce_vars: true, + } + input: { + var c = "FAIL"; + (function(a) { + (a = -1) ? (a && (a.a = 0)) : (a && (a.a = 0)); + a && a[c = "PASS"]++; + })(); + console.log(c); + } + expect: { + var c = "FAIL"; + (function(a) { + a = -1, a, a.a = 0; + a, a[c = "PASS"]++; + })(); + console.log(c); + } + expect_stdout: "PASS" +} |