Fix fill wrapping when text starts with whitespace (#1666)

master
Karl O'Keeffe 2017-05-22 23:32:57 +01:00 committed by Christopher Chedeau
parent d608b7ba28
commit 4083d92ad1
3 changed files with 32 additions and 0 deletions

View File

@ -3585,6 +3585,11 @@ function printJSXElement(path, options, print) {
multilineChildren.push(rawJsxWhitespace);
return;
} else if (i === 0) {
// Fill expects alternating content & whitespace parts
// always starting with content.
// So we add a dummy content element if we would otherwise start
// with whitespace.
multilineChildren.push("");
multilineChildren.push(concat([rawJsxWhitespace, hardline]));
return;
} else if (i === children.length - 1) {

View File

@ -96,6 +96,12 @@ x =
Second
</div> Third
</div>
leading_whitespace =
<div> First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth</div>
no_leading_whitespace =
<div>First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Wrapping text
x = (
@ -241,4 +247,19 @@ x = (
</div>
);
leading_whitespace = (
<div>
{" "}
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh
Twelfth Thirteenth Fourteenth
</div>
);
no_leading_whitespace = (
<div>
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh
Twelfth Thirteenth Fourteenth
</div>
);
`;

View File

@ -93,3 +93,9 @@ x =
Second
</div> Third
</div>
leading_whitespace =
<div> First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth</div>
no_leading_whitespace =
<div>First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth</div>