8000 Handle JSX whitespace separately from fbt whitespace by karl · Pull Request #4717 · prettier/prettier · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Possible improvement of single character text
  • Loading branch information
karl committed Jun 24, 2018
commit 0df189993a6702bc7f439a6401e1f9f3c20bee84
8 changes: 4 additions & 4 deletions src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4774,7 +4774,7 @@ function printJSXChildren(
isFacebookTranslationTag
? hardline
: words[1].length === 1
? ""
? softline
: hardline
);
} else {
Expand Down Expand Up @@ -4809,15 +4809,15 @@ function printJSXChildren(
isFacebookTranslationTag
? hardline
: getLast(children).length === 1
? ""
? softline
: hardline
);
} else {
children.push(jsxWhitespace);
}
} else {
children.push(
getLast(children).length === 1 ? "" : textAndTagSeparator
getLast(children).length === 1 ? softline : textAndTagSeparator
);
}
} else if (/\n/.test(text)) {
Expand All @@ -4842,7 +4842,7 @@ function printJSXChildren(
const firstWord = rawText(next)
.trim()
.split(matchJsxWhitespaceRegex)[0];
children.push(firstWord.length === 1 ? "" : textAndTagSeparator);
children.push(firstWord.length === 1 ? softline : textAndTagSeparator);
} else {
children.push(hardline);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ regression_extra_newline = (

regression_extra_newline_2 = (
<div>
(<FormattedMessage
(
<FormattedMessage
id="some-id"
defaultMessage="some loooooooooooooooooooooooooooong default"
/>)
/>
)
</div>
);

Expand Down
3 changes: 2 additions & 1 deletion tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ long_open_long_children = (
colour="blue"
size="large"
submitLabel="Sign in with Google"
/>d
/>
d
</BaseForm>
<BaseForm
url="/auth/google"
Expand Down
20 changes: 13 additions & 7 deletions tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ function DiffOverview(props) {
<div className="alert alert-info">
<p>
This diff overview is computed against the current list of records in
this collection and the list it contained on <b>{humanDate(since)}</b>.
this collection and the list it contained on <b>{humanDate(since)}</b>
.
</p>
<p>
<b>Note:</b> <code>last_modified</code> and <code>schema</code> record
Expand Down Expand Up @@ -554,9 +555,8 @@ facebook_translation_leave_text_around_tag = (

x = (
<div>
<span>First second third fourth fifth sixth seventh</span>, (<span>
Second
</span>)
<span>First second third fourth fifth sixth seventh</span>, (
<span>Second</span>)
</div>
);

Expand Down Expand Up @@ -853,7 +853,9 @@ x = (
<div>
<div className="first" tabIndex="1">
First
</div>-<div className="second" tabIndex="2">
</div>
-
<div className="second" tabIndex="2">
Second
</div>
</div>
Expand All @@ -863,7 +865,9 @@ x = (
<div>
<div className="first" tabIndex="1">
First
</div>-<div className="second" tabIndex="2">
</div>
-
<div className="second" tabIndex="2">
Second
</div>
</div>
Expand All @@ -873,7 +877,9 @@ x = (
<div>
<div className="first" tabIndex="1">
First
</div>-<div className="second" tabIndex="2">
</div>
-
<div className="second" tabIndex="2">
Second
</div>
</div>
Expand Down
0