diff --git a/crates/oxc_formatter/src/write/call_arguments.rs b/crates/oxc_formatter/src/write/call_arguments.rs index db7a760d13dae..e015133930765 100644 --- a/crates/oxc_formatter/src/write/call_arguments.rs +++ b/crates/oxc_formatter/src/write/call_arguments.rs @@ -139,7 +139,30 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> { ] ); } else { - format_all_args_broken_out(self, false, f); + let interned = f.intern(&format_args!( + "(", + soft_block_indent(&format_with(move |f| { + let separator = format_with(|f| write!(f, [",", soft_line_break_or_space()])); + f.join_with(&separator).entries(self.iter()); + write!( + f, + [(!matches!(self.parent, AstNodes::ImportExpression(_))) + .then_some(FormatTrailingCommas::All)] + ); + })), + ")", + )); + + if let Some(element) = interned { + let should_expand = element.will_break(); + write!( + f, + group(&format_once(|f| { + f.write_element(element); + })) + .should_expand(should_expand) + ); + } } } } diff --git a/crates/oxc_formatter/tests/fixtures/ts/union/issue-16902.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/union/issue-16902.ts.snap index 313d9e0b3d03f..cc2e40f2443f7 100644 --- a/crates/oxc_formatter/tests/fixtures/ts/union/issue-16902.ts.snap +++ b/crates/oxc_formatter/tests/fixtures/ts/union/issue-16902.ts.snap @@ -59,10 +59,12 @@ Math.random< string | number | undefined >0; -console.log(< +console.log( + < // comment string | number | undefined - >0); + >0, +); ------------------- { printWidth: 100 } @@ -89,9 +91,11 @@ Math.random< string | number | undefined >0; -console.log(< +console.log( + < // comment string | number | undefined - >0); + >0, +); ===================== End =====================