Repository navigation
Fix range formatting expanding to a non-source-element node - #19880
Merged
Merged
Conversation
findSiblingAncestors walked the start node's ancestor chain comparing only offsets, so it could settle on a node that isSourceElement rejects. Printing an expression as a standalone element appended a semicolon after the closing brace, and object/class methods threw outright.
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for prettier ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
fisker
reviewed
Aug 18, 2026
fisker
approved these changes
Aug 18, 2026
commit: |
4 of 6 tasks
This was referenced Sep 27, 2026
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 #19795.
findSiblingAncestorswalks up from the start node looking for a wider node that still ends inside the range, but it only compares offsets and never re-checks that what it lands on is somethingisSourceElementaccepts. On the input from the issue it settles on theArrowFunctionExpression, so the range ends up covering an expression, which prints as a standalone element and picks up a trailing semicolon:Adding the
isSourceElementcheck to that loop fixes it. The same shape of bug hits object and class methods, except there the range lands onObjectMethod/ClassMethodand formatting throwsMissing semicolonrather than producing bad output. Fixtures for all three.To check the blast radius I formatted 10 small sources at every possible start/end pair (about 7k ranges) and asserted the result reparses. On
main, 280 ranges produced unparseable output and 154 threw; with this change both are zero, and every range that already worked produces byte-identical output.The end-node loop just below has the same unchecked promotion. I couldn't find an input where it lands on anything but the root
File, so I've left it as is.Unrelated, but noticed while in here:
calculateRangepassesoptstofindSiblingAncestorswhilefindNodeAtOffsetand the return value uselocFunctions, which for JS islocEndWithFullText. Making that consistent changed nothing in the sweep, so I didn't fold it into this PR.Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.