aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index ef032b3f..d055132d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4933,9 +4933,21 @@ merge(Compressor.prototype, {
});
def(AST_Sequence, function(compressor, first_in_statement) {
var expressions = trim(this.expressions, compressor, first_in_statement);
- if (expressions === this.expressions) return this;
if (!expressions) return null;
- return make_sequence(this, expressions);
+ var end = expressions.length - 1;
+ var assign, cond, lhs;
+ if (compressor.option("conditionals")
+ && end > 0
+ && (assign = expressions[end - 1]) instanceof AST_Assign
+ && assign.operator == "="
+ && (lhs = assign.left) instanceof AST_SymbolRef
+ && (cond = to_conditional_assignment(compressor, lhs.definition(), assign.right, expressions[end]))) {
+ assign = assign.clone();
+ assign.right = cond;
+ expressions = expressions.slice(0, -2);
+ expressions.push(assign);
+ }
+ return expressions === this.expressions ? this : make_sequence(this, expressions);
});
def(AST_Sub, function(compressor, first_in_statement) {
if (this.expression.may_throw_on_access(compressor)) return this;
@@ -6390,16 +6402,16 @@ merge(Compressor.prototype, {
function merge_conditional_assignments() {
if (!compressor.option("conditionals")) return;
- for (var i = 0; i < end; i++) {
- var assign = expressions[i];
+ for (var i = 1; i < end; i++) {
+ var assign = expressions[i - 1];
if (!(assign instanceof AST_Assign)) continue;
if (assign.operator != "=") continue;
if (!(assign.left instanceof AST_SymbolRef)) continue;
var def = assign.left.definition();
- var cond = to_conditional_assignment(compressor, def, assign.right, expressions[i + 1]);
+ var cond = to_conditional_assignment(compressor, def, assign.right, expressions[i]);
if (!cond) continue;
assign.right = cond;
- expressions.splice(i + 1, 1);
+ expressions.splice(i, 1);
end--;
}
}