Skip to content

fix: accept bare ampersands in JSX text - #388

Open
pmeredit wants to merge 1 commit into
tree-sitter:masterfrom
pmeredit:366-jsx-text-ampersand
Open

pmeredit wants to merge 1 commit into
tree-sitter:masterfrom
pmeredit:366-jsx-text-ampersand

Conversation

@pmeredit

Copy link
Copy Markdown

<p>Shipping & Handling</p> is valid JSX (React renders the ampersand), but scan_jsx_text stopped at every & and the grammar only accepts a full character reference there, so a bare & was a parse error.

The scanner now looks past an &: if what follows is the rest of an HTML character reference as html_character_reference defines it (&amp;, &#38;, &#x26;), the text ends before it and the reference is its own token as before; otherwise the ampersand is text. The calls to mark_end are there to handle the lookahead, specifically so that text after a bare & is included in the token.

I had Fable 5.1 write the code, but I've manually looked over it. It does not break any existing tests, and this is pretty straight forward for manually written parsers: it was just a need to lookahead one token before "putting the parsing machine in a different state". I'm opening a similar PR against typescript.

Fixes #366

`<p>Shipping & Handling</p>` is valid JSX (React renders the ampersand),
but scan_jsx_text stopped at every `&` and the grammar only accepts a full
character reference there, so a bare `&` was a parse error.

The scanner now looks past an `&`: if what follows is the rest of an HTML
character reference as html_character_reference defines it (`&amp;`,
`&tree-sitter#38;`, `&#x26;`), the text ends before it and the reference is its own
token as before; otherwise the ampersand is text.

Fixes tree-sitter#366

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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: Ampersand breaks jsx_text

1 participant