Allow breaking for logical expressions in member chains (#827)

I'm not really sure what a general rule is for those, but starting with LogicalExpressions should be good. Outside of identifiers, function calls and logical expressions, there aren't a lot of things you'd put there in real code anyway.

Fixes #822
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-02-28 09:31:04 -08:00
1 parent 25340671d3
commit d6e3815c19
3 files changed
+15 -1

No files matched your search

+4 -1
View File
@@ -2394,7 +2394,10 @@ function printMemberChain(path, options, print) {
// If we only have a single `.`, we shouldn't do anything fancy and just
// render everything concatenated together.
if (groups.length <= (shouldMerge ? 3 : 2) && !hasComment) {
if (groups.length <= (shouldMerge ? 3 : 2) &&
!hasComment &&
// (a || b).map() should be break before .map() instead of ||
groups[0][0].node.type !== "LogicalExpression") {
return group(oneLine);
}
@@ -224,6 +224,15 @@ Object.keys(
"
`;
exports[`logical.js 1`] = `
"(veryLongVeryLongVeryLong || e).map(tickets =>
TicketRecord.createFromSomeLongString());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(veryLongVeryLongVeryLong || e)
.map(tickets => TicketRecord.createFromSomeLongString());
"
`;
exports[`multiple-members.js 1`] = `
"if (testConfig.ENABLE_ONLINE_TESTS === \\"true\\") {
describe(\\"POST /users/me/pet\\", function() {
+2
View File
@@ -0,0 +1,2 @@
(veryLongVeryLongVeryLong || e).map(tickets =>
TicketRecord.createFromSomeLongString());