Repository navigation
fix: keep AST locations aligned for multiline spread attributes - #119
Conversation
…ons aligned
Inside a template body, eating the `{` of a spread attribute read `...`
as raw template text up to the closing brace, advancing the line counter.
The parser then rewound `pos` and re-tokenized the ellipsis, counting the
line breaks a second time. Diagnostics landed on the wrong line and Volar
mapping generation threw `Location line or line offsets length is out of
bounds`.
Set the raw-text suppression flag before eating the brace when `...`
follows it, so the ellipsis tokenizes directly and the rewind branch is
no longer needed.
Fixes #118
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit d26f1a5. Configure here.
| this.pos = this.start + 3; | ||
| this.nextToken(); | ||
| } | ||
| this.expect(tt.ellipsis); |
There was a problem hiding this comment.
Spread peek misses comments before ellipsis
Medium Severity
The new ... check only skips ASCII whitespace after {, so a comment or non-ASCII space before the ellipsis leaves #suppressTemplateRawTextToken unset. Eating the brace then swallows the spread as raw template text, and without the old rewind fallback the parser rejects a valid spread attribute inside a template body.
Reviewed by Cursor Bugbot for commit d26f1a5. Configure here.
…#120) PR #119 replaced the raw-text rewind fallback for spread attributes with a peek that sets the raw-text suppression flag only when `...` directly follows the `{` (after ASCII whitespace). A comment or non-ASCII space before the ellipsis left the flag unset, so `next()` read `...props` as raw template text and the parser rejected a valid spread attribute with `Unexpected token`. This affected plain TSX as well as `@{ }` bodies, since the raw-text lexer keys off the enclosing native element. An attribute brace is only ever followed by JavaScript (a spread or a shorthand name), so set the flag unconditionally and let acorn's `skipSpace` handle comments and Unicode whitespace. This also lets shorthand attributes like `{/* c */ id}` parse. Addresses the Bugbot review comment on #119. Co-authored-by: Claude Fable 5.1 <[email protected]>


Fixes #118
Problem
A spread attribute whose
{...spans multiple lines inside a TSRX template body produced correct offsets but inflatedlocline numbers for the argument and every node after it. Injsx_parseAttribute, eating the{read the next token while the one-shot raw-text suppression flag was still off, so the tokenizer swallowed...\n\tprops\nas raw template text up to the closing brace and advanced the line counter. The parser then rewoundposto just past the ellipsis and re-tokenized, counting the line breaks a second time.This misplaced diagnostics and, once a corrupted location exceeded the source line count, made
compile_to_volar_mappingsthrowLocation line or line offsets length is out of bounds.Fix
The attribute parser already peeks past the
{for the shorthand-attribute check. It now also checks for...there and sets#suppressTemplateRawTextTokenbefore eating the brace, so the ellipsis tokenizes directly. The rewind branch is removed since it is no longer reachable.This is a root-cause fix rather than the line-state restoration suggested in the issue: it avoids the double scan and removes a second place where lexer line state had to be kept in sync by hand.
Tests
locis checked against its offset for a template with a multiline spread, an adjacent single-line spread, a multiline call-expression spread, a following attribute, and a nested multiline spread, under LF and CRLF. A single-line control asserts nothing shifted.Validation
pnpm vitest runfor core, all four targets, language-server, typescript-plugin, prettier-plugin, eslint-parser: 53 files passpnpm prettier --checkon touched filespnpm changeset:checktsgo --noEmit -p packages/tsrx/tsconfig.jsonPatch changeset added for
@tsrx/core.🤖 Generated with Claude Code
Note
Medium Risk
Changes TSRX JSX attribute tokenization in the parser plugin; scope is narrow but lexer/parser behavior affects all template compilation and source maps.
Overview
Fixes AST
locline/column drift when a JSX spread attribute’s{...breaks across lines inside a TSRX template. The lexer used to treat...\n\tprops\nas raw template text (counting newlines once), then rewind and re-tokenize the spread (counting them again), which inflated line numbers for the spread argument and everything after it—breaking diagnostics and causing Volar source-map generation to throw “Location line or line offsets length is out of bounds”.In
jsx_parseAttribute, the existing peek after{now also detects...and sets#suppressTemplateRawTextTokenbefore consuming the brace, so the ellipsis is tokenized as JS directly. The old manual...slice/rewind branch is removed.Tests cover full-AST location alignment (LF/CRLF), a single-line spread control, and Volar mappings for tokens after a multiline spread. A patch changeset is added for
@tsrx/core.Reviewed by Cursor Bugbot for commit d26f1a5. Bugbot is set up for automated code reviews on this repo. Configure here.