Fix break on conditional expressions inside return

Fixes #2777

Since we can't break after `return` and don't add `()` around
ConditionalExpressions' tests, we end up with some weird indentation when
breaking.
master
Lucas Duailibe 2017-09-10 02:18:40 -03:00 committed by Stephen Scott
parent 3db840258b
commit bba7dcf498
3 changed files with 57 additions and 1 deletions

View File

@ -346,7 +346,8 @@ function genericPrintNoParens(path, options, print, args) {
parentParent.type === "JSXAttribute") ||
(n === parent.body && parent.type === "ArrowFunctionExpression") ||
(n !== parent.body && parent.type === "ForStatement") ||
parent.type === "ConditionalExpression";
(parent.type === "ConditionalExpression" &&
parentParent.type !== "ReturnStatement");
const shouldIdentIfInlining =
parent.type === "AssignmentExpression" ||

View File

@ -352,6 +352,46 @@ x & (y >> z);
`;
exports[`return.js 1`] = `
function foo() {
return this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right;
}
function foo() {
return this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right
? true
: false;
}
function foo() {
return this.calculate().compute().first.numberOfThings > this.calculate().compute().last.numberOfThings
? true
: false;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo() {
return (
this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft.right
);
}
function foo() {
return this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft.right
? true
: false;
}
function foo() {
return this.calculate().compute().first.numberOfThings >
this.calculate().compute().last.numberOfThings
? true
: false;
}
`;
exports[`short-right.js 1`] = `
this._cumulativeHeights &&
Math.abs(

View File

@ -0,0 +1,15 @@
function foo() {
return this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right;
}
function foo() {
return this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right
? true
: false;
}
function foo() {
return this.calculate().compute().first.numberOfThings > this.calculate().compute().last.numberOfThings
? true
: false;
}