fix(formatting): recover from token spans outside property children#63629
Open
ahfoysal wants to merge 1 commit into
Open
fix(formatting): recover from token spans outside property children#63629ahfoysal wants to merge 1 commit into
ahfoysal wants to merge 1 commit into
Conversation
Handle recovery cases where a token ends after the current child while formatting invalid syntax, to avoid entering invalid scanner state. Fixes microsoft#63598.
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a formatter debug assertion in processChildNode by improving the scanner/AST synchronization logic when recovery parsing produces tokens whose scanned spans exceed the current child node’s end boundary. Adds a fourslash regression test reproducing the invalid type-literal property syntax from #63598.
Changes:
- Update
processChildNode’s pre-child token consumption loop to rewind the formatting scanner when the current scanned token overruns the child’send. - Add a fourslash regression test that formats an invalid type-literal property and asserts formatting completes without crashing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/cases/fourslash/formattingTokenEndChildEnd.ts | New regression test covering the recovery scenario that previously triggered the formatter assertion. |
| src/services/formatting/formatting.ts | Adjusts scanner rewind conditions to handle tokens spanning beyond a child node in recovery parsing, preventing Debug.assert(tokenInfo.token.end === child.end) failures. |
Contributor
|
@ahfoysal You should read this: https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md |
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.
Summary
processChildNodeto handle scanner tokens that overrun the current child node boundary in recovery scenarios.type X = { prop: = \${abc}`xyz }) that triggeredDebug Failure. False expression: Token end is child end`.Validation
npx hereby runtests --tests formattingTokenEndChildEnd --light=falseFixes #63598.