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
Lucas Duailibe 2017-09-10 12:34:55 -03:00 committed by Christopher Chedeau
parent bba7dcf498
commit 955a2c1472
3 changed files with 33 additions and 1 deletions

View File

@ -3705,7 +3705,9 @@ function printMemberChain(path, options, print) {
groups.length <= cutoff &&
!hasComment &&
// (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);
}

View File

@ -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`] = `
export default function theFunction(action$, store) {
return action$.ofType(THE_ACTION).switchMap(action => Observable

View File

@ -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());