diff --git a/crates/oxc_formatter/src/utils/conditional.rs b/crates/oxc_formatter/src/utils/conditional.rs index 58f6e1ea49ee4..4224edede7adc 100644 --- a/crates/oxc_formatter/src/utils/conditional.rs +++ b/crates/oxc_formatter/src/utils/conditional.rs @@ -464,10 +464,10 @@ impl<'a> FormatConditionalLike<'a, '_> { let format_alternative = format_with(|f| match self.conditional { ConditionalLike::ConditionalExpression(conditional) => { - write!(f, [conditional.alternate()]) + write!(f, [FormatNodeWithoutTrailingComments(conditional.alternate())]) } ConditionalLike::TSConditionalType(conditional) => { - write!(f, [conditional.false_type()]) + write!(f, [FormatNodeWithoutTrailingComments(conditional.false_type())]) } }); let format_alternative = format_with(|f| { diff --git a/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js b/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js new file mode 100644 index 0000000000000..7f7951edc66b1 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js @@ -0,0 +1,9 @@ +cb( + overflowing ? 'absolute top-0' : 'relative', // sidebar custom changes - to contain the absolute sidebar below + parameter +) + +cb( + overflowing ? 'absolute top-0' : 'relative' /* */, // sidebar custom changes - to contain the absolute sidebar below + parameter +) \ No newline at end of file diff --git a/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js.snap b/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js.snap new file mode 100644 index 0000000000000..6a638c3d9a60a --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/conditional/argument.js.snap @@ -0,0 +1,25 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +cb( + overflowing ? 'absolute top-0' : 'relative', // sidebar custom changes - to contain the absolute sidebar below + parameter +) + +cb( + overflowing ? 'absolute top-0' : 'relative' /* */, // sidebar custom changes - to contain the absolute sidebar below + parameter +) +==================== Output ==================== +cb( + overflowing ? "absolute top-0" : "relative", // sidebar custom changes - to contain the absolute sidebar below + parameter, +); + +cb( + overflowing ? "absolute top-0" : "relative" /* */, // sidebar custom changes - to contain the absolute sidebar below + parameter, +); + +===================== End =====================