Repository navigation
Fix unstable trailing comment on a nested parenthesized assignment - #19893
Merged
Merged
Conversation
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
✅ Deploy Preview for prettier ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
fisker
approved these changes
Aug 20, 2026
Member
|
Great work! Thank you! |
4 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the remaining case in #19271.
#19276 made
(a = c /* comment */);stable by attaching the trailing comment to theExpressionStatement. The nested form was left out and is still unstable onmain:The second format is already the fixpoint, so this makes the first one produce it too.
handleParenthesizedExpressionTrailingCommentdoes fire here — it just attaches the comment inward toc. Once the parentheses are dropped the comment is at the end of the statement, and the next run attaches it to the statement instead, which is where the instability comes from.Attaching to the statement on the first pass needs the statement, and the handler only had
enclosingNode. For a chain likex = y = (a = c /* comment */)that is the middle assignment, not the outermost, so walking up is the only way to reach it.decorateCommentalready builds the ancestor chain and threads it through the recursion forcanAttachComment, it just wasn't returned, so this returns it and walks up through the right hand side of each enclosing assignment.Scope is deliberately narrow, since #19273 was reverted once already. Only assignment chains that end in an
ExpressionStatementare affected — everywhere else the parentheses are kept, so nothing was unstable to begin with:Two related variants are still unstable, both unchanged by this PR and both failing identically on
main:They need a wider change than this one and I'd rather not fold them in here.
parenthesized-trailing-comment-unstable.jsexisted only for this case, with a TODO to move it back once stable, so it's removed along with itsfailed-format-tests.jsentry and the case is enabled inparenthesized-trailing-comment.js.Full
tests/formatrun has the same failures before and after.Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.