@@ -5278,6 +5278,20 @@ merge(Compressor.prototype, {
|
|||||||
consequent
|
consequent
|
||||||
]).optimize(compressor);
|
]).optimize(compressor);
|
||||||
}
|
}
|
||||||
|
// x ? y || z : z --> x && y || z
|
||||||
|
if (consequent instanceof AST_Binary
|
||||||
|
&& consequent.operator == "||"
|
||||||
|
&& consequent.right.equivalent_to(alternative)) {
|
||||||
|
return make_node(AST_Binary, self, {
|
||||||
|
operator: "||",
|
||||||
|
left: make_node(AST_Binary, self, {
|
||||||
|
operator: "&&",
|
||||||
|
left: self.condition,
|
||||||
|
right: consequent.left
|
||||||
|
}),
|
||||||
|
right: alternative
|
||||||
|
}).optimize(compressor);
|
||||||
|
}
|
||||||
var in_bool = compressor.in_boolean_context();
|
var in_bool = compressor.in_boolean_context();
|
||||||
if (is_true(self.consequent)) {
|
if (is_true(self.consequent)) {
|
||||||
if (is_false(self.alternative)) {
|
if (is_false(self.alternative)) {
|
||||||
|
|||||||
@@ -1224,3 +1224,46 @@ hoist_decl: {
|
|||||||
x() ? y() : z();
|
x() ? y() : z();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
to_and_or: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var values = [
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"foo",
|
||||||
|
false,
|
||||||
|
-1 / 0,
|
||||||
|
void 0,
|
||||||
|
];
|
||||||
|
values.forEach(function(x) {
|
||||||
|
values.forEach(function(y) {
|
||||||
|
values.forEach(function(z) {
|
||||||
|
console.log(x ? y || z : z);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var values = [
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"foo",
|
||||||
|
false,
|
||||||
|
-1 / 0,
|
||||||
|
void 0,
|
||||||
|
];
|
||||||
|
values.forEach(function(x) {
|
||||||
|
values.forEach(function(y) {
|
||||||
|
values.forEach(function(z) {
|
||||||
|
console.log(x && y || z);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user