@@ -12865,19 +12865,17 @@ Compressor.prototype.compress = function(node) {
|
|||||||
var alt_tail = alternative.tail_node();
|
var alt_tail = alternative.tail_node();
|
||||||
// x ? y : y ---> x, y
|
// x ? y : y ---> x, y
|
||||||
// x ? (a, c) : (b, c) ---> x ? a : b, c
|
// x ? (a, c) : (b, c) ---> x ? a : b, c
|
||||||
if (seq_tail.equals(alt_tail)) {
|
if (seq_tail.equals(alt_tail)) return make_sequence(self, consequent.equals(alternative) ? [
|
||||||
return make_sequence(self, consequent.equals(alternative) ? [
|
condition,
|
||||||
condition,
|
consequent,
|
||||||
consequent,
|
] : [
|
||||||
] : [
|
make_node(AST_Conditional, self, {
|
||||||
make_node(AST_Conditional, self, {
|
condition: condition,
|
||||||
condition: condition,
|
consequent: pop_seq(consequent),
|
||||||
consequent: pop_seq(consequent),
|
alternative: pop_seq(alternative),
|
||||||
alternative: pop_seq(alternative),
|
}),
|
||||||
}),
|
alt_tail,
|
||||||
seq_tail,
|
]).optimize(compressor);
|
||||||
]).optimize(compressor);
|
|
||||||
}
|
|
||||||
// x ? y.p : z.p ---> (x ? y : z).p
|
// x ? y.p : z.p ---> (x ? y : z).p
|
||||||
// x ? y(a) : z(a) ---> (x ? y : z)(a)
|
// x ? y(a) : z(a) ---> (x ? y : z)(a)
|
||||||
// x ? y.f(a) : z.f(a) ---> (x ? y : z).f(a)
|
// x ? y.f(a) : z.f(a) ---> (x ? y : z).f(a)
|
||||||
|
|||||||
@@ -2878,3 +2878,53 @@ issue_5546_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5666_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
(function() {
|
||||||
|
var b = a;
|
||||||
|
a ? a = b : (b++, a = b);
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
(function() {
|
||||||
|
var b = a;
|
||||||
|
a = (a ? 0 : b++, b);
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5666_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "foo";
|
||||||
|
(function() {
|
||||||
|
var b = a;
|
||||||
|
a ? (b++, a = b) : a = b;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "foo";
|
||||||
|
(function() {
|
||||||
|
var b = a;
|
||||||
|
a = (a ? b++ : 0, b);
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user