typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Fix getTokenAtPos in JSDoc trivia position

Open gabritto opened this issue 2 weeks ago • 0 comments

Fixes #2290.

We were scanning into an AST node in getTokenAtPosition, basically because in this JSDoc case:

/**
 * @type {{
 * 'string-property': boolean;
 */*$*/ identifierProperty: boolean;
 * }}
 */
var someVariable;

identifierProperty's position does not include what would typically be its leading trivia. So the positions between the starting * and identifierProperty effectively don't belong to any node or token in the AST, but getTokenAtPosition operated under the assumption that this was impossible, and therefore that we should scan and find a non-tree token in between * and identifierProperty.

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.

gabritto avatar Dec 12 '25 22:12 gabritto