Fix getTokenAtPos in JSDoc trivia position #2371
Draft
+108
−12
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 #2290.
We were scanning into an AST node in
getTokenAtPosition, basically because in this JSDoc case:identifierProperty's position does not include what would typically be its leading trivia. So the positions between the starting*andidentifierPropertyeffectively don't belong to any node or token in the AST, butgetTokenAtPositionoperated under the assumption that this was impossible, and therefore that we should scan and find a non-tree token in between*andidentifierProperty.I added code to explicitly track what the next AST node is (
nodeAfterLeft) whenever we update the scanner starting position (left), so we can then enforce the invariant of scanning only in between AST nodes.