-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js_formatter): fix JSX text wrapping and empty line handling (#1075)
- Loading branch information
1 parent
b237ffe
commit 6260bad
Showing
7 changed files
with
376 additions
and
1,332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
crates/biome_js_formatter/tests/specs/jsx/text_children.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Short, textual children can collapse onto the same line as self-closing | ||
// elements if they start or end with a single character word or a space. | ||
// Elements containing children will also remove all empty lines within them. | ||
// This tests various permutations of that. | ||
|
||
<> | ||
a<div />b | ||
</>; | ||
<> | ||
a<div />bb | ||
</>; | ||
<> | ||
aa<div />b | ||
</>; | ||
<> | ||
aa<div />bb | ||
</>; | ||
|
||
// As long as the first/last word of the text has a single character, | ||
// it can stay on the same line. | ||
<> | ||
a b<div />c | ||
</>; | ||
<> | ||
a bb<div />c | ||
</>; | ||
<> | ||
aa b<div />c | ||
</>; | ||
<> | ||
aa bb<div />c | ||
</>; | ||
<> | ||
a<div />b c | ||
</>; | ||
<> | ||
a<div />b ccc | ||
</>; | ||
<> | ||
a<div />bb cc | ||
</>; | ||
<> | ||
aa<div />b c | ||
</>; | ||
<> | ||
aa<div />b ccc | ||
</>; | ||
<> | ||
aa<div />bb cc | ||
</>; | ||
<> | ||
longword doesntmatter a<div />b | ||
</>; | ||
<> | ||
a<div />b longword doesntmatter | ||
</>; | ||
|
||
|
||
// Any character counts | ||
<> | ||
1<div />b | ||
</>; | ||
<> | ||
11<div />b | ||
</>; | ||
<> | ||
ม<div />b | ||
</>; | ||
<> | ||
มม<div />b | ||
</>; | ||
<> | ||
!<div />b | ||
</>; | ||
<> | ||
!!<div />b | ||
</>; | ||
|
||
// Spaces also count | ||
<> | ||
a <div />b | ||
</>; | ||
<> | ||
aa <div />b | ||
</>; | ||
|
||
// Blank lines aren't kept if the children contain meaningful text | ||
<> | ||
line | ||
|
||
|
||
2 | ||
</>; | ||
<> | ||
first | ||
|
||
|
||
<div>second</div> | ||
|
||
|
||
<div>third</div> | ||
</>; |
Oops, something went wrong.