fix(formatter): Fix line comment after : inside ternary JSX#16315
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #16315 will not alter performanceComparing Summary
Footnotes
|
: inside ternary JSX
|
Handling comments is complicated, so I will take a careful look. |
6223678 to
cffca8c
Compare
a1f7bec to
ac8fcaf
Compare
cffca8c to
a0624a8
Compare
|
Yes, I just appreciate. 🙏🏻 |
There was a problem hiding this comment.
Pull request overview
This PR fixes formatting of line comments appearing after the : operator in ternary expressions within JSX elements. The fix addresses issue #16258 where such comments were not being handled correctly by the formatter.
Key changes:
- Unified comment handling logic for JSX elements and fragments
- Refactored conditional expression formatting to improve code clarity
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_formatter/src/write/jsx/element.rs |
Simplified format_trailing_comments to use end_of_line_comments_after uniformly for non-arrow function cases |
crates/oxc_formatter/src/utils/conditional.rs |
Refactored format_test to compute span values outside the formatting closure for better readability |
crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx |
Added test case for nested ternary with comment after : operator |
crates/oxc_formatter/tests/fixtures/js/jsx/ternary-with-comment.jsx.snap |
Updated snapshot with expected formatting output for new test case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I found out that this should be fixed on the JSX side, and I re-implemented it. Please take a look! |
Merge activity
|
5931c84 to
7b7acef
Compare
|
Thank you so much...! (I never thought of that. 🤯) |
7b7acef to
5ad5435
Compare

Fixes #16258