fix: Improve comma appending logic to handle nested template literals correctly#1630
Merged
dsherret merged 1 commit intoMay 19, 2025
Conversation
kingston
commented
Apr 30, 2025
| } | ||
|
|
||
| const pos = scanner.getStartPos(); | ||
| const pos = scanner.getTokenFullStart(); |
Contributor
Author
There was a problem hiding this comment.
Replaced this since getStartPos is deprecated and has been replaced by getTokenFullStart (that is identical in functionality) https://github.com/microsoft/TypeScript/blob/main/src/compiler/scanner.ts#L53
1 task
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.
Fixes #1603
This PR fixes the comma‐appending logic so it correctly skips over nested template‐literal content (e.g. “${expr}/*”) and appends commas in the right place. Previously, when inserting into comma-separated nodes, the scanner would misinterpret sequences like /* inside a template literal as the start of a comment and place the comma inside the template literal incorrectly.
This PR mimics the logic found in classifier.ts (https://github.com/microsoft/TypeScript/blob/11e79327598db412a161616849041487673fadab/src/services/classifier.ts#L217) and keeps track of the template stack so that we skip any text values inside template literals using the
reScanTemplateTokenfunction of the scanner.I also added a test to capture this case.