Skip to content

Commit 370a8e3

Browse files
jsmechamclaude
andcommitted
fix(formatter): keep JSX expression child flat when fill expands its separator
Fixes #21916 When formatting a JSX child list, the printer's `Fill` correctly determined that an expression entry (e.g. `{toCash(...).display_cents}`) fit in flat mode even though the trailing separator needed to break. While printing that flat entry, however, inner groups re-ran their own `fits` check using `AllPredicate`, which walked past the entry boundary into subsequent fill entries — frequently overshooting `printWidth` and causing the expression group to needlessly expand into `{ \n expr \n }`. This adds an `in_flat_fill_item` flag on the printer state that's set while `print_fill_item` is printing a flat entry. Inner regular groups honor it and skip re-measuring (since the fill already verified the entry fits), while `BestFitting` still goes through its variant selection so JSX child lists with both flat and expanded variants can still pick the right form. Prettier conformance: no regressions (746/753 JS, 591/601 TS — unchanged). Co-authored-by: Claude <[email protected]>
1 parent 4380812 commit 370a8e3

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// JSX expression child whose flat width fits on one line should not be
2+
// expanded just because the surrounding fill needs a separator break.
3+
const Component = () => {
4+
return (
5+
<Outer>
6+
<Inner>
7+
<br />
8+
{format(viewModelData.the_long_property_name_for_test).display_value} (
9+
{translate("labels.the_long_property_name_for_test")})
10+
</Inner>
11+
</Outer>
12+
);
13+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
// JSX expression child whose flat width fits on one line should not be
6+
// expanded just because the surrounding fill needs a separator break.
7+
const Component = () => {
8+
return (
9+
<Outer>
10+
<Inner>
11+
<br />
12+
{format(viewModelData.the_long_property_name_for_test).display_value} (
13+
{translate("labels.the_long_property_name_for_test")})
14+
</Inner>
15+
</Outer>
16+
);
17+
};
18+
19+
==================== Output ====================
20+
------------------
21+
{ printWidth: 80 }
22+
------------------
23+
// JSX expression child whose flat width fits on one line should not be
24+
// expanded just because the surrounding fill needs a separator break.
25+
const Component = () => {
26+
return (
27+
<Outer>
28+
<Inner>
29+
<br />
30+
{format(viewModelData.the_long_property_name_for_test).display_value} (
31+
{translate("labels.the_long_property_name_for_test")})
32+
</Inner>
33+
</Outer>
34+
);
35+
};
36+
37+
-------------------
38+
{ printWidth: 100 }
39+
-------------------
40+
// JSX expression child whose flat width fits on one line should not be
41+
// expanded just because the surrounding fill needs a separator break.
42+
const Component = () => {
43+
return (
44+
<Outer>
45+
<Inner>
46+
<br />
47+
{format(viewModelData.the_long_property_name_for_test).display_value} (
48+
{translate("labels.the_long_property_name_for_test")})
49+
</Inner>
50+
</Outer>
51+
);
52+
};
53+
54+
===================== End =====================

0 commit comments

Comments
 (0)