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

[unicode] Fix trailing nbsp #5165

Merged
merged 1 commit into from
Sep 29, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/doc/doc-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,14 @@ function printDocToString(doc, options) {
while (
out.length > 0 &&
typeof out[out.length - 1] === "string" &&
out[out.length - 1].match(/^[^\S\n]*$/)
out[out.length - 1].match(/^[ \t]*$/)
) {
out.pop();
}

if (out.length && typeof out[out.length - 1] === "string") {
out[out.length - 1] = out[out.length - 1].replace(
/[^\S\n]*$/,
/[ \t]*$/,
""
);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/jsx-whitespace/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ non_breaking_spaces = <div>]   [</div>
em_space = <div>]   [</div>
hair_space = <div>]  [</div>
zero_width_space = <div>]​​​[</div>
real_world_non_breaking_spaces = <p>
Supprimer l’objectif « {goal.name} » ?
</p>
real_world_non_breaking_spaces2 = <p>
Supprimer l’objectif padding padding padding padding padding padding « {goal.name} » ?
</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Treated as whitespace in JSX
spaces = <div>] [</div>;
Expand All @@ -39,5 +45,12 @@ non_breaking_spaces = <div>]   [</div>;
em_space = <div>]   [</div>;
hair_space = <div>]  [</div>;
zero_width_space = <div>]​​​[</div>;
real_world_non_breaking_spaces = <p>Supprimer l’objectif « {goal.name} » ?</p>;
real_world_non_breaking_spaces2 = (
<p>
Supprimer l’objectif padding padding padding padding padding padding « 
{goal.name} » ?
</p>
);

`;
6 changes: 6 additions & 0 deletions tests/jsx-whitespace/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ non_breaking_spaces = <div>]   [</div>
em_space = <div>]   [</div>
hair_space = <div>]  [</div>
zero_width_space = <div>]​​​[</div>
real_world_non_breaking_spaces = <p>
Supprimer l’objectif « {goal.name} » ?
</p>
real_world_non_breaking_spaces2 = <p>
Supprimer l’objectif padding padding padding padding padding padding « {goal.name} » ?
</p>
13 changes: 13 additions & 0 deletions tests/unicode/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ exports[`keys.js - flow-verify 1`] = `
({ この事はつもり素晴らしいことさ: "35jL9V" });

`;

exports[`nbsp-jsx.js - flow-verify 1`] = `
// Note: there are non breaking spaces in the JSX text
x = <p> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa </p>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Note: there are non breaking spaces in the JSX text
x = (
<p>
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 
</p>
);

`;
2 changes: 2 additions & 0 deletions tests/unicode/nbsp-jsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Note: there are non breaking spaces in the JSX text
x = <p> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa </p>;