Skip to content

fix: keep AST locations aligned for multiline spread attributes - #119

Merged
leonidaz merged 1 commit into
mainfrom
fix/multiline-spread-locations
Sep 16, 2026
Merged

leonidaz merged 1 commit into
mainfrom
fix/multiline-spread-locations

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #118

Problem

A spread attribute whose {... spans multiple lines inside a TSRX template body produced correct offsets but inflated loc line numbers for the argument and every node after it. In jsx_parseAttribute, eating the { read the next token while the one-shot raw-text suppression flag was still off, so the tokenizer swallowed ...\n\tprops\n as raw template text up to the closing brace and advanced the line counter. The parser then rewound pos to 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_mappings throw Location 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 #suppressTemplateRawTextToken before 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

  • Parser: every node's loc is 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.
  • Shared Volar mappings (React, Preact, Solid, Vue): the crash variant from the issue compiles, and mappings for the attributes after the spread point at the authored tokens.

Validation

  • pnpm vitest run for core, all four targets, language-server, typescript-plugin, prettier-plugin, eslint-parser: 53 files pass
  • pnpm prettier --check on touched files
  • pnpm changeset:check
  • tsgo --noEmit -p packages/tsrx/tsconfig.json

Patch 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 loc line/column drift when a JSX spread attribute’s {... breaks across lines inside a TSRX template. The lexer used to treat ...\n\tprops\n as 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 #suppressTemplateRawTextToken before 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.

…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]>
@vercel

vercel Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website Ready Ready Preview Sep 16, 2026 2:29pm UTC
tsrx-website-mcp Ready Ready Preview Sep 16, 2026 2:29pm UTC

Request Review

@leonidaz
leonidaz merged commit 33d6093 into main Sep 16, 2026
11 checks passed
@leonidaz
leonidaz deleted the fix/multiline-spread-locations branch September 16, 2026 14:32

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d26f1a5. Configure here.

@github-actions github-actions Bot mentioned this pull request Sep 16, 2026
leonidaz added a commit that referenced this pull request Sep 16, 2026
…#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]>

This branch was successfully deployed

2 active deployments
Preview – tsrx-website — d26f1a51 Deployed Sep 16, 2026 by vercel[bot]
Preview – tsrx-website-mcp — d26f1a51 Deployed Sep 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Multiline spread attributes corrupt AST locations and can break Volar mappings

1 participant