fix(formatter): use soft indent for empty objects in JSX spread attributes#18063
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes formatting of empty objects with dangling comments inside JSX spread attributes and JSX spread children. The change ensures that constructs like <div {...{/* comment */}} /> remain on one line if they fit, while maintaining the existing behavior of expanding empty objects with comments in other contexts (e.g., var a = {/* comment */} still expands to multiple lines).
Changes:
- Added
is_inside_jsx_spread()method to detect when an object is inside a JSX spread attribute or JSX spread child - Updated empty object formatting logic to use soft indent instead of block indent for JSX spread contexts
- Fixed one failing Prettier conformance test (
jsx/ignore/spread.js)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_formatter/src/print/object_like.rs |
Added is_inside_jsx_spread() method and conditional formatting logic for empty objects with dangling comments |
tasks/prettier_conformance/snapshots/prettier.js.snap.md |
Updated JS compatibility score from 737/761 to 738/761, removed jsx/ignore/spread.js from failed tests |
tasks/prettier_conformance/snapshots/prettier.ts.snap.md |
Updated TS compatibility score from 579/607 to 580/607, removed jsx/ignore/spread.js from failed tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e466376 to
d43e945
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
…butes (#18063) ## Summary - Fix `jsx/ignore/spread.js` Prettier conformance test - Empty objects with dangling comments inside JSX spread attributes now stay on one line if they fit - For example, `<div {...{/* comment */}} />` remains on one line, while `var a = {/* comment */}` still expands ## Test plan - [x] `cargo run -p oxc_prettier_conformance -- --filter "jsx/ignore/spread.js"` passes - [x] `cargo run -p oxc_prettier_conformance -- --filter "js/comments/dangling.js"` still passes (no regression) - [x] `cargo test -p oxc_formatter` passes - [x] JS compatibility: 737/761 → 738/761 (+1) - [x] TS compatibility: 579/607 → 580/607 (+1) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
d43e945 to
9b902b6
Compare
Summary
jsx/ignore/spread.jsPrettier conformance test<div {...{/* comment */}} />remains on one line, whilevar a = {/* comment */}still expandsTest plan
cargo run -p oxc_prettier_conformance -- --filter "jsx/ignore/spread.js"passescargo run -p oxc_prettier_conformance -- --filter "js/comments/dangling.js"still passes (no regression)cargo test -p oxc_formatterpasses🤖 Generated with Claude Code