@@ -5727,6 +5727,18 @@ merge(Compressor.prototype, {
|
|||||||
consequent
|
consequent
|
||||||
]).optimize(compressor);
|
]).optimize(compressor);
|
||||||
}
|
}
|
||||||
|
// x ? (y, w) : (z, w) --> x ? y : z, w
|
||||||
|
if ((consequent instanceof AST_Sequence || alternative instanceof AST_Sequence)
|
||||||
|
&& consequent.tail_node().equivalent_to(alternative.tail_node())) {
|
||||||
|
return make_sequence(self, [
|
||||||
|
make_node(AST_Conditional, self, {
|
||||||
|
condition: self.condition,
|
||||||
|
consequent: pop_seq(consequent),
|
||||||
|
alternative: pop_seq(alternative)
|
||||||
|
}),
|
||||||
|
consequent.tail_node()
|
||||||
|
]).optimize(compressor);
|
||||||
|
}
|
||||||
// x ? y || z : z --> x && y || z
|
// x ? y || z : z --> x && y || z
|
||||||
if (consequent instanceof AST_Binary
|
if (consequent instanceof AST_Binary
|
||||||
&& consequent.operator == "||"
|
&& consequent.operator == "||"
|
||||||
@@ -5829,6 +5841,13 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pop_seq(node) {
|
||||||
|
if (!(node instanceof AST_Sequence)) return make_node(AST_Number, node, {
|
||||||
|
value: 0
|
||||||
|
});
|
||||||
|
return make_sequence(node, node.expressions.slice(0, -1));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_Boolean, function(self, compressor){
|
OPT(AST_Boolean, function(self, compressor){
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ cond_7: {
|
|||||||
x = 'foo';
|
x = 'foo';
|
||||||
x = 'foo';
|
x = 'foo';
|
||||||
x = (condition(), 20);
|
x = (condition(), 20);
|
||||||
x = z ? 'fuji' : (condition(), 'fuji');
|
x = (z || condition(), 'fuji');
|
||||||
x = (condition(), 'foobar');
|
x = (condition(), 'foobar');
|
||||||
x = y ? a : b;
|
x = y ? a : b;
|
||||||
x = y ? 'foo' : 'fo';
|
x = y ? 'foo' : 'fo';
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ if_return: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(w, x, y, z) {
|
function f(w, x, y, z) {
|
||||||
@@ -124,7 +125,7 @@ if_return: {
|
|||||||
if (w) {
|
if (w) {
|
||||||
if (y) return;
|
if (y) return;
|
||||||
} else if (z) return;
|
} else if (z) return;
|
||||||
return x == y || (x && w(), y && z(), !0);
|
return x == y || (x && w(), y && z()), !0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user