fix(formatter): incorrect indentation of long assignment pattern in object#16709
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 #16709 will not alter performanceComparing Summary
Footnotes
|
49229c7 to
e4c1bda
Compare
e4c1bda to
c71b369
Compare
aceb727 to
2a63d74
Compare
c71b369 to
dd0057b
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect indentation of assignment patterns in shorthand object binding properties. The issue occurred when destructuring function parameters with default values (e.g., function f({ a = defaultValue }) {}). The formatter was incorrectly treating these as having both a left-hand side (key) and right-hand side (value), when in fact the entire assignment pattern should be treated as the left-hand side only.
Key Changes:
- Updated
write_leftto format the entirevalue(which includes the assignment pattern) instead of just thekeyfor shorthand binding properties with assignment patterns - Extended
has_only_left_hand_sideto recognizeAssignmentPatternas a "left-hand side only" case with detailed explanatory comments - Removed duplicate shorthand handling code that was made obsolete by the fix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_formatter/src/utils/assignment_like.rs |
Fixed the logic for formatting shorthand binding properties with assignment patterns by treating AssignmentPattern values as left-hand side only, and cleaned up duplicate code |
crates/oxc_formatter/tests/fixtures/js/assignments/issue-16704.js |
Added test case demonstrating the fix for assignment patterns in object destructuring parameters |
crates/oxc_formatter/tests/fixtures/js/assignments/issue-16704.js.snap |
Snapshot showing expected formatting output for the test case at different print widths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
dd0057b to
e973965
Compare

close: #16704