diff --git a/crates/oxc_formatter/src/write/jsx/mod.rs b/crates/oxc_formatter/src/write/jsx/mod.rs index 31fadea8aec0d..bb37b1e11f42e 100644 --- a/crates/oxc_formatter/src/write/jsx/mod.rs +++ b/crates/oxc_formatter/src/write/jsx/mod.rs @@ -197,24 +197,26 @@ impl<'a> FormatWrite<'a> for AstNode<'a, JSXExpressionContainer<'a>> { let should_inline = !has_comment(f) && (is_conditional_or_binary || should_inline_jsx_expression(self)); - if should_inline { - write!(f, ["{", self.expression(), line_suffix_boundary(), "}"]); - } else { - write!( - f, - [group(&format_args!( - "{", + let format_expression = format_with(|f| { + if should_inline { + write!(f, self.expression()); + } else { + write!( + f, soft_block_indent(&format_with(|f| { write!(f, [self.expression()]); let comments = f.context().comments().comments_before(self.span.end); write!(f, [FormatTrailingComments::Comments(comments)]); - })), - line_suffix_boundary(), - "}" - ))] - ); - } + })) + ); + } + }); + + write!( + f, + [group(&format_args!("{", format_expression, line_suffix_boundary(), "}"))] + ); } } else { // JSXAttributeValue diff --git a/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx b/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx new file mode 100644 index 0000000000000..ec51dc59a1965 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx @@ -0,0 +1,5 @@ +

+ Current usage for X is ${(() => { + // comment + })()}. +

diff --git a/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx.snap b/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx.snap new file mode 100644 index 0000000000000..6bffe2e8afa67 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx.snap @@ -0,0 +1,34 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +

+ Current usage for X is ${(() => { + // comment + })()}. +

+ +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +

+ Current usage for X is $ + {(() => { + // comment + })()} + . +

; + +------------------- +{ printWidth: 100 } +------------------- +

+ Current usage for X is $ + {(() => { + // comment + })()} + . +

; + +===================== End =====================