fix(jsx): do not move trailing char to the next line as leading char (#5354)
This commit is contained in:
3 files changed
+46
-14
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -452,6 +452,13 @@ this_really_should_split_across_lines =
|
||||
<div>
|
||||
before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after
|
||||
</div>
|
||||
|
||||
let myDiv = ReactTestUtils.renderIntoDocument(
|
||||
<div>
|
||||
<div key="theDog" className="dog" />,
|
||||
<div key="theBird" className="bird" />
|
||||
</div>
|
||||
);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Wrapping text
|
||||
x = (
|
||||
@@ -773,11 +780,7 @@ line_after_br = (
|
||||
|
||||
line_after_br_2 = (
|
||||
<div>
|
||||
A
|
||||
<br />
|
||||
B
|
||||
<br />
|
||||
C
|
||||
A<br />B<br />C
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -967,8 +970,7 @@ x = (
|
||||
|
||||
x = (
|
||||
<div>
|
||||
<strong>text here</strong>.
|
||||
<br />
|
||||
<strong>text here</strong>.<br />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -988,8 +990,7 @@ x = (
|
||||
<span>
|
||||
<strong>{name}</strong>’s{" "}
|
||||
</span>
|
||||
Hello <strong>world</strong>.
|
||||
<br />
|
||||
Hello <strong>world</strong>.<br />
|
||||
<Text>You {type}ed this shipment to</Text>
|
||||
</div>
|
||||
);
|
||||
@@ -1023,4 +1024,11 @@ this_really_should_split_across_lines = (
|
||||
</div>
|
||||
);
|
||||
|
||||
let myDiv = ReactTestUtils.renderIntoDocument(
|
||||
<div>
|
||||
<div key="theDog" className="dog" />,
|
||||
<div key="theBird" className="bird" />
|
||||
</div>
|
||||
);
|
||||
|
||||
`;
|
||||
@@ -449,3 +449,10 @@ this_really_should_split_across_lines =
|
||||
<div>
|
||||
before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after
|
||||
</div>
|
||||
|
||||
let myDiv = ReactTestUtils.renderIntoDocument(
|
||||
<div>
|
||||
<div key="theDog" className="dog" />,
|
||||
<div key="theBird" className="bird" />
|
||||
</div>
|
||||
);
|
||||
Reference in new issue
Block a user