Skip to content

fix: always tokenize the token after an attribute brace as JavaScript - #120

Merged
leonidaz merged 1 commit into
mainfrom
fix/spread-attribute-comments
Sep 16, 2026
Merged

leonidaz merged 1 commit into
mainfrom
fix/spread-attribute-comments

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #119, addressing the Bugbot review comment that landed after merge.

The peek added in #119 sets the raw-text suppression flag only when ... directly follows the attribute { 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. Before #119 the rewind fallback covered this, so it is a regression.

It affects plain TSX as well as @{ } bodies, since the raw-text lexer keys off the enclosing native element:

<div {/* c */ ...props} />   // failed on main
<div { ...props} />      // failed on main

Fix

An attribute brace is only ever followed by JavaScript (a spread or a shorthand name), so the flag is now set unconditionally and acorn's skipSpace handles comments and Unicode whitespace. This also lets shorthand attributes like {/* c */ id} parse, which failed both before and after #119.

Tests

  • New parser cases for block, multiline block, and line comments, a non-ASCII space, and a plain-TSX block comment before the ellipsis, asserting every node's loc matches acorn.getLineInfo so the fix: keep AST locations aligned for multiline spread attributes #119 location fix still holds.
  • New shorthand cases with a comment and a non-ASCII space before the name.
  • pnpm vitest run --project tsrx-utils --project tsrx-analyze --project tsrx-react --project tsrx-vue --project tsrx-solid --project language-server --project prettier-plugin pass locally.

🤖 Generated with Claude Code


Note

Low Risk
Targeted tokenizer fix in JSX attribute parsing with broad regression tests; no runtime API or security surface changes.

Overview
Fixes a parser regression where JSX spread attributes like <div {/* c */ ...props} /> or <div { ...props} /> (non-ASCII space) failed with Unexpected token because the post-#119 peek only skipped ASCII whitespace before deciding to suppress raw template text.

In jsx_parseAttribute, #suppressTemplateRawTextToken is now set unconditionally whenever an attribute opens with {, so the token after the brace is always lexed as JavaScript and Acorn’s skipSpace handles comments and Unicode whitespace. The same change allows shorthand attributes such as {/* c */ id} to parse.

Tests add parameterized cases for comments, multiline comments, line comments, non-ASCII space, plain TSX, and shorthand attributes, with loc checks across the AST. A patch changeset documents the @tsrx/core fix.

Reviewed by Cursor Bugbot for commit cdd320b. Bugbot is set up for automated code reviews on this repo. Configure here.

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]>
@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:51pm UTC
tsrx-website-mcp Ready Ready Preview Sep 16, 2026 2:51pm UTC

Request Review

This branch was successfully deployed

2 active deployments
Preview – tsrx-website — cdd320b7 Deployed Sep 16, 2026 by vercel[bot]
Preview – tsrx-website-mcp — cdd320b7 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.

1 participant