Use same logic for binary chain
parent
1b2127efb6
commit
902f7f0339
|
@ -367,13 +367,22 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
|
||||
const rest = concat(parts.slice(1));
|
||||
|
||||
// Break the closing paren to keep the chain right after it:
|
||||
// (a &&
|
||||
// b &&
|
||||
// c
|
||||
// ).call()
|
||||
const breakClosingParen =
|
||||
parent.type === "MemberExpression" && !parent.computed;
|
||||
|
||||
return group(
|
||||
concat([
|
||||
// Don't include the initial expression in the indentation
|
||||
// level. The first item is guaranteed to be the first
|
||||
// left-most expression.
|
||||
parts.length > 0 ? parts[0] : "",
|
||||
indent(rest)
|
||||
indent(rest),
|
||||
breakClosingParen ? softline : ""
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -1321,7 +1330,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
concat([
|
||||
path.call(print, "test"),
|
||||
forceNoIndent ? concat(parts) : indent(concat(parts)),
|
||||
breakClosingParen ? ifBreak(softline, "") : ""
|
||||
breakClosingParen ? softline : ""
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -3712,9 +3721,7 @@ function printMemberChain(path, options, print) {
|
|||
// render everything concatenated together.
|
||||
if (
|
||||
groups.length <= cutoff &&
|
||||
!hasComment &&
|
||||
// (a || b).map() should be break before .map() instead of ||
|
||||
groups[0][0].node.type !== "LogicalExpression"
|
||||
!hasComment
|
||||
) {
|
||||
return group(oneLine);
|
||||
}
|
||||
|
|
|
@ -66,3 +66,17 @@ const promises = [
|
|||
];
|
||||
|
||||
`;
|
||||
|
||||
exports[`logical.js 1`] = `
|
||||
(veryLongVeryLongVeryLong || e).prop;
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).prop;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
(veryLongVeryLongVeryLong || e).prop;
|
||||
|
||||
(veryLongVeryLongVeryLong ||
|
||||
anotherVeryLongVeryLongVeryLong ||
|
||||
veryVeryVeryLongError
|
||||
).prop;
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
(veryLongVeryLongVeryLong || e).prop;
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).prop;
|
|
@ -572,9 +572,35 @@ Object.keys(
|
|||
exports[`logical.js 1`] = `
|
||||
(veryLongVeryLongVeryLong || e).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString());
|
||||
|
||||
(veryLongVeryLongVeryLong || e).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString()).filter(obj => !!obj);
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString());
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString()).filter(obj => !!obj);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
(veryLongVeryLongVeryLong || e).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString()
|
||||
);
|
||||
|
||||
(veryLongVeryLongVeryLong || e)
|
||||
.map(tickets => TicketRecord.createFromSomeLongString());
|
||||
.map(tickets => TicketRecord.createFromSomeLongString())
|
||||
.filter(obj => !!obj);
|
||||
|
||||
(veryLongVeryLongVeryLong ||
|
||||
anotherVeryLongVeryLongVeryLong ||
|
||||
veryVeryVeryLongError
|
||||
).map(tickets => TicketRecord.createFromSomeLongString());
|
||||
|
||||
(veryLongVeryLongVeryLong ||
|
||||
anotherVeryLongVeryLongVeryLong ||
|
||||
veryVeryVeryLongError
|
||||
)
|
||||
.map(tickets => TicketRecord.createFromSomeLongString())
|
||||
.filter(obj => !!obj);
|
||||
|
||||
`;
|
||||
|
||||
|
|
|
@ -1,2 +1,11 @@
|
|||
(veryLongVeryLongVeryLong || e).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString());
|
||||
|
||||
(veryLongVeryLongVeryLong || e).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString()).filter(obj => !!obj);
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString());
|
||||
|
||||
(veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).map(tickets =>
|
||||
TicketRecord.createFromSomeLongString()).filter(obj => !!obj);
|
||||
|
|
Loading…
Reference in New Issue