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 =