Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fill wrapping when text starts with whitespace #1666

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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>
);

`;
6 changes: 6 additions & 0 deletions tests/jsx-text-wrap/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>