Skip to content

Commit 4b41305

Browse files
committed
fix(formatter): avoid conditional being broken in arguments by trailing comments
1 parent 7b92413 commit 4b41305

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

crates/oxc_formatter/src/utils/conditional.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ impl<'a> FormatConditionalLike<'a, '_> {
464464

465465
let format_alternative = format_with(|f| match self.conditional {
466466
ConditionalLike::ConditionalExpression(conditional) => {
467-
write!(f, [conditional.alternate()])
467+
write!(f, [FormatNodeWithoutTrailingComments(conditional.alternate())])
468468
}
469469
ConditionalLike::TSConditionalType(conditional) => {
470-
write!(f, [conditional.false_type()])
470+
write!(f, [FormatNodeWithoutTrailingComments(conditional.false_type())])
471471
}
472472
});
473473
let format_alternative = format_with(|f| {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cb(
2+
overflowing ? 'absolute top-0' : 'relative', // sidebar custom changes - to contain the absolute sidebar below
3+
parameter
4+
)
5+
6+
cb(
7+
overflowing ? 'absolute top-0' : 'relative' /* */, // sidebar custom changes - to contain the absolute sidebar below
8+
parameter
9+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
cb(
6+
overflowing ? 'absolute top-0' : 'relative', // sidebar custom changes - to contain the absolute sidebar below
7+
parameter
8+
)
9+
10+
cb(
11+
overflowing ? 'absolute top-0' : 'relative' /* */, // sidebar custom changes - to contain the absolute sidebar below
12+
parameter
13+
)
14+
==================== Output ====================
15+
cb(
16+
overflowing ? "absolute top-0" : "relative", // sidebar custom changes - to contain the absolute sidebar below
17+
parameter,
18+
);
19+
20+
cb(
21+
overflowing ? "absolute top-0" : "relative" /* */, // sidebar custom changes - to contain the absolute sidebar below
22+
parameter,
23+
);
24+
25+
===================== End =====================

0 commit comments

Comments
 (0)