@@ -4500,6 +4500,8 @@ merge(Compressor.prototype, {
|
|||||||
&& alternative.TYPE === consequent.TYPE
|
&& alternative.TYPE === consequent.TYPE
|
||||||
&& consequent.args.length == 1
|
&& consequent.args.length == 1
|
||||||
&& alternative.args.length == 1
|
&& alternative.args.length == 1
|
||||||
|
&& !(consequent.args[0] instanceof AST_Expansion)
|
||||||
|
&& !(alternative.args[0] instanceof AST_Expansion)
|
||||||
&& consequent.expression.equivalent_to(alternative.expression)
|
&& consequent.expression.equivalent_to(alternative.expression)
|
||||||
&& !consequent.expression.has_side_effects(compressor)) {
|
&& !consequent.expression.has_side_effects(compressor)) {
|
||||||
consequent.args[0] = make_node(AST_Conditional, self, {
|
consequent.args[0] = make_node(AST_Conditional, self, {
|
||||||
|
|||||||
@@ -26,3 +26,46 @@ expand_parameters: {
|
|||||||
expect_exact: "(function(a,...b){});(function(...args){});"
|
expect_exact: "(function(a,...b){});(function(...args){});"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avoid_spread_in_ternary: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function print(...x) {
|
||||||
|
console.log(...x);
|
||||||
|
}
|
||||||
|
var a = [1, 2], b = [3, 4];
|
||||||
|
|
||||||
|
if (Math)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (Math)
|
||||||
|
print(...a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (Math.no_such_property)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(...b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function print(...x) {
|
||||||
|
console.log(...x);
|
||||||
|
}
|
||||||
|
var a = [ 1, 2 ], b = [ 3, 4 ];
|
||||||
|
print(Math ? a : b);
|
||||||
|
Math ? print(...a) : print(b);
|
||||||
|
Math.no_such_property ? print(a) : print(...b);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 1, 2 ]",
|
||||||
|
"1 2",
|
||||||
|
"3 4",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user