Skip to content

Commit 10dedac

Browse files
committed
fix(formatter): expand the parent if the member chain will break
1 parent 8c441c0 commit 10dedac

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

crates/oxc_formatter/src/utils/member_chain/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ impl<'a> Format<'a> for MemberChain<'a, '_> {
235235
if has_comment || has_new_line_or_comment_between || self.groups_should_break(f) {
236236
write!(f, [group(&format_expanded)])
237237
} else {
238+
let has_empty_line_before_tail =
239+
self.tail.first().is_some_and(MemberChainGroup::needs_empty_line);
240+
241+
if has_empty_line_before_tail || self.last_group().will_break(f) {
242+
write!(f, [expand_parent()])?;
243+
}
244+
238245
write!(f, [best_fitting!(format_one_line, format_expanded)])
239246
}
240247
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id === null
2+
? null
3+
: internal.getSuspenseCache(client).getFragmentRef(
4+
[id, options.fragment, cache.canonicalStringify(variables)],
5+
client,
6+
tslib.__assign(tslib.__assign({}, options), {
7+
variables: variables,
8+
from: id,
9+
}),
10+
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
id === null
6+
? null
7+
: internal.getSuspenseCache(client).getFragmentRef(
8+
[id, options.fragment, cache.canonicalStringify(variables)],
9+
client,
10+
tslib.__assign(tslib.__assign({}, options), {
11+
variables: variables,
12+
from: id,
13+
}),
14+
);
15+
16+
==================== Output ====================
17+
id === null
18+
? null
19+
: internal.getSuspenseCache(client).getFragmentRef(
20+
[id, options.fragment, cache.canonicalStringify(variables)],
21+
client,
22+
tslib.__assign(tslib.__assign({}, options), {
23+
variables: variables,
24+
from: id,
25+
}),
26+
);
27+
28+
===================== End =====================

0 commit comments

Comments
 (0)