Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions crates/oxc_formatter/src/write/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
Current usage for X is ${(() => {
// comment
})()}.
</p>
34 changes: 34 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/jsx/text-wrap.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
<p>
Current usage for X is ${(() => {
// comment
})()}.
</p>

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
<p>
Current usage for X is $
{(() => {
// comment
})()}
.
</p>;

-------------------
{ printWidth: 100 }
-------------------
<p>
Current usage for X is $
{(() => {
// comment
})()}
.
</p>;

===================== End =====================
Loading