From ac3a92e66edf6c7fb7bd8b244ff6ab8daec83ae9 Mon Sep 17 00:00:00 2001
From: leaysgur <6259812+leaysgur@users.noreply.github.com>
Date: Fri, 28 Nov 2025 07:12:23 +0000
Subject: [PATCH] fix(formatter): Print comment in ternary jsx (#16224)
Fixes #16194
Just prints `self.expression`, instead of `FormatNodeWithoutTrailingComments`.
Aligned with Prettier 3.7.1 outputs:
```tsx
{
isVideo ? (
) : (
// eslint-disable-line
);
}
<>
{isVideo ? (
) : (
// eslint-disable-line
)}
>;
```
https://prettier.io/playground/#N4Igxg9gdgLgprEAuEwCWBnAamgJnCAAgH5CAKAHSkMIB4d8jgA6VgBwCcI2MBfQgPQA+KgEpCSclRq0AkgFsAhgHM4hFuy49+wwQMJwMAGzSwAtLkyKARkbhmTUOGN5UqtEVHTY8BElOo6Bj8NZk5uPkFPcUlKQLklVXVWMK1I3QF9Q0cYCytbe0dnKFFXKFphEAAaEG4YNGgMZFBFDi4AdwAFVoQmlEUjdsUATyaa6w5FMABrOBgAZUV5OAAZUzhkADMBjDgaiGsAKzgwGAB1SbZkEE5DOA4ANw3xyZm5+bYp02VkGA4AVz2IF28jQvwBQLgAA82Pc0MtYAMAPKwyYwCAcToQDBoerQa4IXDVEDQ1HwhAwAYAFXuUFaaEMWx2QJxUGUdgAiv8IPAmUZdjVDhgofNvpzubykNt+UCAI4SuCdNLXRQYMxOOD4Ik1P6KNCOZQAYQg8iUKqMRmJrPZcAAgjA-mhrP94J17msnHyBSAABYweRGM4+3GGT5gODzXq4tAPXHDa5gDBjEAPQGyKD4WDzMAcNBsGC2jPzGDDOxeoHhXYXRRXFC3XaPZ4gUwNmBKlRmqXMmqfDgN67WGxwS093OwM54GA+5AADgADDUOHB5Wgl+3lJ3pd7KdYJ7gp8gAEw1f67Kk2PpbyHyayarUrRRs-4qOAAMQxSgd3xVLogIF4vBAA
---
crates/oxc_formatter/src/utils/conditional.rs | 2 +-
.../fixtures/js/jsx/ternary-with-comment.jsx | 13 +++++
.../js/jsx/ternary-with-comment.jsx.snap | 58 +++++++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx
create mode 100644 crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap
diff --git a/crates/oxc_formatter/src/utils/conditional.rs b/crates/oxc_formatter/src/utils/conditional.rs
index df4458b7d4895..a4808f902fc55 100644
--- a/crates/oxc_formatter/src/utils/conditional.rs
+++ b/crates/oxc_formatter/src/utils/conditional.rs
@@ -647,7 +647,7 @@ impl<'a> Format<'a> for FormatJsxChainExpression<'a, '_> {
}
.fmt(f);
} else {
- FormatNodeWithoutTrailingComments(self.expression).fmt(f);
+ self.expression.fmt(f);
}
});
diff --git a/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx b/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx
new file mode 100644
index 0000000000000..195cbed0f00af
--- /dev/null
+++ b/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx
@@ -0,0 +1,13 @@
+{isVideo ? (
+
+) : (
+ // eslint-disable-line
+)}
+
+<>
+{isVideo ? (
+
+) : (
+ // eslint-disable-line
+)}
+>
diff --git a/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap b/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap
new file mode 100644
index 0000000000000..a6bc26738587c
--- /dev/null
+++ b/crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap
@@ -0,0 +1,58 @@
+---
+source: crates/oxc_formatter/tests/fixtures/mod.rs
+---
+==================== Input ====================
+{isVideo ? (
+
+) : (
+ // eslint-disable-line
+)}
+
+<>
+{isVideo ? (
+
+) : (
+ // eslint-disable-line
+)}
+>
+
+==================== Output ====================
+------------------
+{ printWidth: 80 }
+------------------
+{
+ isVideo ? (
+
+ ) : (
+ // eslint-disable-line
+ );
+}
+
+<>
+ {isVideo ? (
+
+ ) : (
+ // eslint-disable-line
+ )}
+>;
+
+-------------------
+{ printWidth: 100 }
+-------------------
+{
+ isVideo ? (
+
+ ) : (
+ // eslint-disable-line
+ );
+}
+
+<>
+ {isVideo ? (
+
+ ) : (
+ // eslint-disable-line
+ )}
+>;
+
+===================== End =====================