Keep conditional expressions in one line on method chains (#2784)
Fixes #2775. This commit will make conditional expressions to match the behavior of logical expression in method chains: ```js (a ? b : c).map() // if the conditional fits in oneline (a ? b : c) .map() // if the conditional doesn't fit (a ? b : c) .map() ```master
parent
bba7dcf498
commit
955a2c1472
|
@ -3705,7 +3705,9 @@ function printMemberChain(path, options, print) {
|
||||||
groups.length <= cutoff &&
|
groups.length <= cutoff &&
|
||||||
!hasComment &&
|
!hasComment &&
|
||||||
// (a || b).map() should be break before .map() instead of ||
|
// (a || b).map() should be break before .map() instead of ||
|
||||||
groups[0][0].node.type !== "LogicalExpression"
|
groups[0][0].node.type !== "LogicalExpression" &&
|
||||||
|
// (a ? b : c).map() should be break before .map() instead of ?
|
||||||
|
groups[0][0].node.type !== "ConditionalExpression"
|
||||||
) {
|
) {
|
||||||
return group(oneLine);
|
return group(oneLine);
|
||||||
}
|
}
|
||||||
|
|
|
@ -416,6 +416,27 @@ exports[`computed-merge.js 1`] = `
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`conditional.js 1`] = `
|
||||||
|
(valid
|
||||||
|
? helper.responseBody(this.currentUser)
|
||||||
|
: helper.response(401))
|
||||||
|
.map(res => res.json());
|
||||||
|
|
||||||
|
(valid
|
||||||
|
? helper.responseBody(this.currentUser)
|
||||||
|
: helper.responseBody(defaultUser))
|
||||||
|
.map(res => res.json());
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
(valid ? helper.responseBody(this.currentUser) : helper.response(401))
|
||||||
|
.map(res => res.json());
|
||||||
|
|
||||||
|
(valid
|
||||||
|
? helper.responseBody(this.currentUser)
|
||||||
|
: helper.responseBody(defaultUser))
|
||||||
|
.map(res => res.json());
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`first_long.js 1`] = `
|
exports[`first_long.js 1`] = `
|
||||||
export default function theFunction(action$, store) {
|
export default function theFunction(action$, store) {
|
||||||
return action$.ofType(THE_ACTION).switchMap(action => Observable
|
return action$.ofType(THE_ACTION).switchMap(action => Observable
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
(valid
|
||||||
|
? helper.responseBody(this.currentUser)
|
||||||
|
: helper.response(401))
|
||||||
|
.map(res => res.json());
|
||||||
|
|
||||||
|
(valid
|
||||||
|
? helper.responseBody(this.currentUser)
|
||||||
|
: helper.responseBody(defaultUser))
|
||||||
|
.map(res => res.json());
|
Loading…
Reference in New Issue