Skip to content

Commit 8f4137d

Browse files
committed
fix(formatter): output is incorrect when using comments inside JSX which is the right hand-side of LogicalExpression (#16156)
* close #16138
1 parent ac9ae95 commit 8f4137d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

crates/oxc_formatter/src/write/binary_like_expression.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ impl<'a> Format<'a> for BinaryLeftOrRightSide<'a, '_> {
443443

444444
if should_inline {
445445
write!(f, [space()]);
446-
if f.comments().has_leading_own_line_comment(right.span().start) {
446+
447+
if !right.is_jsx()
448+
&& f.comments().has_leading_own_line_comment(right.span().start)
449+
{
447450
return write!(f, soft_line_indent_or_space(right));
448451
}
449452
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
xxxxxxxxxxxx === 'xxxxxxxxxxxxxxxxx' && (
2+
// test
3+
<div></div>
4+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
xxxxxxxxxxxx === 'xxxxxxxxxxxxxxxxx' && (
6+
// test
7+
<div></div>
8+
)
9+
10+
==================== Output ====================
11+
------------------
12+
{ printWidth: 80 }
13+
------------------
14+
xxxxxxxxxxxx === "xxxxxxxxxxxxxxxxx" && (
15+
// test
16+
<div></div>
17+
);
18+
19+
-------------------
20+
{ printWidth: 100 }
21+
-------------------
22+
xxxxxxxxxxxx === "xxxxxxxxxxxxxxxxx" && (
23+
// test
24+
<div></div>
25+
);
26+
27+
===================== End =====================

0 commit comments

Comments
 (0)