diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 998d9dd7b39c..b3b2ea4ee52c 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -5078,19 +5078,27 @@ function separatorNoWhitespace( (childNode.type === "JSXElement" && !childNode.closingElement) || (nextNode && (nextNode.type === "JSXElement" && !nextNode.closingElement)) ) { - return hardline; + return child.length === 1 ? softline : hardline; } return softline; } -function separatorWithWhitespace(isFacebookTranslationTag, child) { +function separatorWithWhitespace( + isFacebookTranslationTag, + child, + childNode, + nextNode +) { if (isFacebookTranslationTag) { return hardline; } if (child.length === 1) { - return softline; + return (childNode.type === "JSXElement" && !childNode.closingElement) || + (nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) + ? hardline + : softline; } return hardline; @@ -5133,8 +5141,14 @@ function printJSXChildren( children.push(""); words.shift(); if (/\n/.test(words[0])) { + const next = n.children[i + 1]; children.push( - separatorWithWhitespace(isFacebookTranslationTag, words[1]) + separatorWithWhitespace( + isFacebookTranslationTag, + words[1], + child, + next + ) ); } else { children.push(jsxWhitespace); @@ -5164,10 +5178,13 @@ function printJSXChildren( if (endWhitespace !== undefined) { if (/\n/.test(endWhitespace)) { + const next = n.children[i + 1]; children.push( separatorWithWhitespace( isFacebookTranslationTag, - getLast(children) + getLast(children), + child, + next ) ); } else { diff --git a/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap index 254ad4e43f38..e4e839bcdd00 100644 --- a/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap @@ -452,6 +452,13 @@ this_really_should_split_across_lines =
before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after
+ +let myDiv = ReactTestUtils.renderIntoDocument( +
+
, +
+
+); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Wrapping text x = ( @@ -773,11 +780,7 @@ line_after_br = ( line_after_br_2 = (
- A -
- B -
- C + A
B
C
); @@ -967,8 +970,7 @@ x = ( x = (
- text here. -
+ text here.
); @@ -988,8 +990,7 @@ x = ( {name}’s{" "} - Hello world. -
+ Hello world.
You {type}ed this shipment to
); @@ -1023,4 +1024,11 @@ this_really_should_split_across_lines = (
); +let myDiv = ReactTestUtils.renderIntoDocument( +
+
, +
+
+); + `; diff --git a/tests/jsx-text-wrap/test.js b/tests/jsx-text-wrap/test.js index 82be1c422e8b..f8cb62554435 100644 --- a/tests/jsx-text-wrap/test.js +++ b/tests/jsx-text-wrap/test.js @@ -449,3 +449,10 @@ this_really_should_split_across_lines =
before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after
+ +let myDiv = ReactTestUtils.renderIntoDocument( +
+
, +
+
+);