diff --git a/src/printer.js b/src/printer.js index 92725bdde..352241356 100644 --- a/src/printer.js +++ b/src/printer.js @@ -417,7 +417,6 @@ function genericPrintNoParens(path, options, print, args) { !hasLeadingOwnLineComment(options.originalText, n.body) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || - n.body.type === "JSXElement" || n.body.type === "BlockStatement" || isTemplateOnItsOwnLine(n.body, options.originalText) || n.body.type === "ArrowFunctionExpression") @@ -3958,7 +3957,8 @@ function maybeWrapJSXElementInParens(path, elem) { ExpressionStatement: true, CallExpression: true, ConditionalExpression: true, - LogicalExpression: true + LogicalExpression: true, + ArrowFunctionExpression: true }; if (NO_WRAP_PARENTS[parent.type]) { return elem; diff --git a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap index dd9d57878..15ece2aa8 100644 --- a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap @@ -75,31 +75,27 @@ const renderTernary = (props) => {props.showTheOtherThing ?
I am here!!
: null} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -const render1 = ({ styles }) => ( +const render1 = ({ styles }) =>
Keep the wrapping parens. Put each key on its own line. -
-); + ; -const render2 = ({ styles }) => ( +const render2 = ({ styles }) =>
Create wrapping parens. -
-); + ; -const render3 = ({ styles }) => ( -
Bump to next line without parens
-); +const render3 = ({ styles }) => +
Bump to next line without parens
; -const render4 = ({ styles }) => ( +const render4 = ({ styles }) =>
Create wrapping parens and indent all the things. -
-); + ; const render5 = ({ styles }) =>
Keep it on one line.
; -const render6 = ({ styles }) => ( +const render6 = ({ styles }) =>
( {" "} hello
-
-); + ; -const render7 = () => ( +const render7 = () =>
Dont break each elem onto its own line.
-
-); +
; -const render7A = () => ( +const render7A = () =>
-
-); +
; -const render7B = () => ( +const render7B = () =>
Dont break plz Dont break plz Dont break plz -
-); +
; const render8 = props =>
{props.text}
; -const render9 = props => ( -
{props.looooooooooooooooooooooooooooooong_text}
-); -const render10 = props => ( +const render9 = props => +
{props.looooooooooooooooooooooooooooooong_text}
; +const render10 = props =>
{props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents} -
-); +
; const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams( @@ -185,7 +175,7 @@ React.render( document.querySelector("#react-root") ); -const renderTernary = props => ( +const renderTernary = props => ( } {props.showTheOtherThing ?
I am here
:
} {props.showTheOtherThing ?
I am here!!
: null} - -); + ; `; diff --git a/tests/jsx/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/__snapshots__/jsfmt.spec.js.snap index cb8487833..8623ae274 100644 --- a/tests/jsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/__snapshots__/jsfmt.spec.js.snap @@ -89,21 +89,20 @@ exports[`expression.js 1`] = ` />; - {() => ( + {() => + + + } +; + + + {items.map(item => )} ; - - {items.map(item => ( - - - - ))} -; - {function() { return ( @@ -205,28 +204,28 @@ exports[`hug.js 1`] = ` {__DEV__ ? this.renderDevApp() :
- {routes.map(route => ( + {routes.map(route => - ))} + )}
}
;
{__DEV__ &&
- {routes.map(route => ( + {routes.map(route => - ))} + )}
}
; diff --git a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap index c1cec4c04..990e245ea 100644 --- a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap +++ b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap @@ -282,11 +282,11 @@ const els = items.map(item => (
)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -const els = items.map(item => ( +const els = items.map(item =>
{children}
-)); +); `; diff --git a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap index 8168e9ea9..18af0d59f 100644 --- a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap @@ -29,11 +29,10 @@ const MyCoolList = ({ things }) => const MyCoolThing = ({ thingo }) =>
  • {thingo}
  • ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -const MyCoolList = ({ things }) => ( +const MyCoolList = ({ things }) => -); + ; const MyCoolThing = ({ thingo }) =>
  • {thingo}
  • ;