diff --git a/src/printer.js b/src/printer.js index 420e8726..6b333463 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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" || diff --git a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap index fd0d05c8..5c4ba464 100644 --- a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap @@ -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( diff --git a/tests/binary-expressions/return.js b/tests/binary-expressions/return.js new file mode 100644 index 00000000..44ba5b06 --- /dev/null +++ b/tests/binary-expressions/return.js @@ -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; +}