Repository navigation
fix(grammars): end a <style> body at </style >, and parse TypeScript generics in tree-sitter - #1180
Merged
jonkwheeler merged 9 commits intoNov 12, 2026
Conversation
tsrx-org#792) The compiler ends a `<script>` body at `</script`, optional HTML whitespace, then `>` (tsrx-org#790). Both grammars ended it only at the exact `</script>`, so `</script >` was read as script, and in the TextMate grammar everything after it, the following elements included, was highlighted as TypeScript. - tree-sitter: `scan_raw_text` skips HTML whitespace after `</script` and ends the body before the `<` when a `>` follows. A `<style>` body still ends only at `</style>`, which is what the compiler accepts there. - TextMate: the script element ends at `(</)(script)\s*(>)` and its body at `(?=</script\s*(?:>|$))`. A TextMate rule matches one line at a time, so a closing tag with a line break before its `>` ends the element at `</script` on its line; the `>` on the next line is then JSX text and the code after it is highlighted normally. The tokens of the repository's 78 .tsrx files are unchanged in both grammars. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tsrx-org#455) The parser, compilers and formatter accept `using` and `await using` declarations (TypeScript 5.2), but the tree-sitter grammar parsed them as errors, and the TextMate grammar highlighted `using` in an `@for` head as a plain identifier. - tree-sitter: a `using_declaration` node, named as in tree-sitter-javascript, in statements, `@{ … }` scopes, fragment bodies, `for…of` heads and `@for` heads. It binds identifiers only, as TypeScript requires, so `using [i]` stays an index expression. `using` is a keyword where a declaration can start, so it is aliased to `identifier` in expressions and assignment targets: `using(x)`, `using.dispose()`, `using = x` and `for (using of items)` parse to the same trees as before. `using` is highlighted as `@keyword.storage`. - TextMate: the directive header and the `for (…; index …)` head now take `using` and `await using`, with the lookahead TypeScript-TmLanguage uses, so `@for (using of items)` keeps `using` as the loop variable. The tree-sitter parse trees and TextMate tokens of the repository's 78 .tsrx files are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… labels and for…in heads
`using` is a keyword wherever a `using` declaration can start, so it has to be
aliased to `identifier` everywhere else a variable name can go at those
positions. The previous commit covered expressions and assignment targets but
not the rest, so these parsed with errors where main had none:
- `using => 1;` and `(using) => using` (an arrow parameter)
- `[using] = arr;` (a pattern)
- `using: for (;;) { break using; }` (a label)
- `for (using in obj) {}` (a `for…in` head)
`_using_identifier` now sits next to `identifier` in `pattern`,
`required_parameter`, the arrow's single parameter, `labeled_statement` and the
`for…in` head, and these parse to the same trees as on main.
In an `@for` head a `using` declaration now takes only `of`, as in TypeScript
(the compiler reports TS1493 for `@for (using item in items)`); `using` as the
loop variable still takes `of` or `in`.
The parse trees of the repository's 78 .tsrx files are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eclaration The directive header pattern marked `using` as a declaration keyword before any name, so `@for (using item in items)`, which the compiler rejects (TS1493), and `@if (using instanceof Foo)` showed it as `storage.type`. It now needs to follow the `(` and come before `<name> of`, the one place a `using` declaration can be in a directive head. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck their tokens Zed builds the grammar at the `rev` pinned in `packages/zed-plugin/extension.toml` and loads the extension's own queries against it. A query that names a node or a token the grammar lacks fails to load, and Zed then highlights nothing. The previous commit copied a `"using"` capture into Zed's `highlights.scm`, but the grammar at the pin (aa13392) has no `using` token, so Zed built from main (`pnpm zed:stage-dev`) would lose highlighting until Version Packages moved the pin. `check-zed-grammar-rev.js` checked only named nodes, so it did not notice. - `copy-tree-sitter-queries.js` updates Zed's copy only with `--zed`, and `sync-zed-grammar-rev.js`, which Version Packages runs when the extension version changes, moves the pin to HEAD and then copies the queries with `--zed`. Zed's queries and the grammar it builds now move together. Neovim builds the grammar from the default branch and still takes every change. - `check-zed-grammar-rev.js` also checks quoted tokens against the anonymous node types at the pin, with a small query reader (`tree-sitter-query-nodes.js`) that skips comments and predicate arguments. It fails on the previous commit's Zed copy (`missing token "using"`) and passes with this one. - Zed's `highlights.scm` is back to main's. `"using"` reaches it with the next Version Packages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moving the rev on a pull request branch pins Zed to a commit that a squash merge drops. Version Packages already moves the rev and copies the queries together, so the message now points there only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…srx-org#1156) tsrx-org#1138 makes the compiler end a `<style>` body at `</style`, optional HTML whitespace, then `>`, as a `<script>` body already ends. Both grammars still ended it only at the exact `</style>`, so in `<style>…</style >` the closing tag was read as CSS: tree-sitter parsed the file as an error from the start, and the TextMate grammar highlighted everything after it as CSS. - tree-sitter: `scan_raw_text` allows whitespace before the `>` for both raw text elements, and the closing tag is one token, `</style`, whitespace and `>`, aliased to `</style>`. The node types and queries are unchanged. - TextMate: the style element ends at `(</)(style)\s*(>)` and its body at `(?=</style\s*(?:>|$))`, as tsrx-org#1104 did for `<script>`. A closing tag with a line break before its `>` ends the element at `</style` on its line. The trees and tokens of the repository's 78 .tsrx files are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…[]` (tsrx-org#1155) The tree-sitter grammar misread common TypeScript expressions: - `<T,>(x: T) => x` and `<T extends U>(x: T) => x` were an `ERROR` over the statement and the lines after it: `arrow_function` had no type parameters. - `useState<T>([])` was `useState < T > ([])`, and `useState<T[]>([])` added a `MISSING` identifier for `T[` as an index: `call_expression` had no type arguments. - `value as T[]` was `(value as T)[<MISSING>]`: `as` (PREC.REL) outranked the postfix array type (4), so the expression was reduced before the `[`. Now: - `arrow_function` takes optional `type_parameters` before its parameter list, as in tree-sitter-typescript. `extends` is a keyword after `<T` there, so it is also accepted as a JSX attribute name, keeping `<Foo extends={x} />` and `<Foo extends />` tags. - `call_expression` has a second form with `type_arguments`. Its callee is a hidden `_type_arguments_callee` (a primary expression), declared as a conflict with `expression`, so the parser keeps both `f<T>(x)` and `f < T > (x)` until one fails; dynamic precedence takes the call when both parse, as TypeScript does. Since the callee is a primary expression, a prefix operator applies to the whole call (`!f<T>(x)`, `await f<T>(x)`), and `new Foo<T>()` keeps its own type arguments. - The postfix type precedence is above PREC.REL, so `as T[]`, `satisfies T[]` and `as T[K]` keep the brackets in the type. The 6 repository .tsrx files that had `MISSING` nodes now parse without errors. Their trees change only at those statements and at the generic calls `useState<'section' | 'article'>(…)` and `ref<HTMLInputElement | null>(…)`; the other 72 files get identical trees. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
This PR is too large for Bugbot to review. It changes 104,866 lines and 4,076,299 characters. Split the change into smaller pull requests to get a review. |
jonkwheeler
marked this pull request as ready for review
October 27, 2026 16:38
This was referenced Oct 27, 2026
main now has tsrx-org#1104's squash commit; merged against the parent commit this branch has so git doesn't redo that work. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 12, 2026
main now has tsrx-org#1180's squash commit; merged against the parent commit this branch has so git doesn't redo that work. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1104; review the commits after 92402cc; merge after #1104.
The
</style >half matches the compiler once #1138 merges. Until then, the grammars accept a closing tag that the compiler still reports asUnclosed tag '<style>'.Summary
Two grammar fixes for the TextMate grammar (VS Code, JetBrains IDEs, Sublime Text) and the tree-sitter grammar (Zed, Neovim).
</style >ends a<style>block (#1156). #1138 makes the compiler end a style body at</style, optional whitespace, then>. #1104 did this for<script>, and this PR does the same for<style>.<style>.a { color: red; }</style >, the closing tag was read as CSS. TextMate highlighted the rest of the file as CSS,<p class="a">{text}</p>included. tree-sitter parsed the file asERRORfrom the start.>. As with<script>in fix(grammars): end a <script> body at </script >, and parse using declarations #1104, TextMate can't see the next line, so it ends the element at</styleand reads the>on the next line as JSX text.</style>token, now matched as</style, whitespace,>. Node types and queries don't change, so Zed's pinned queries are unaffected.TypeScript generics and
as T[]in tree-sitter (#1155).<T,>(x: T) => x,<T extends U>(x: T) => x,async <T, U = T>(x: T): U => xERRORover the statement and the lines after itarrow_functionwithtype_parametersuseState<T[]>([])useState < T[<MISSING>] > ([])call_expressionwithtype_arguments(array_type)useState<T>(x),obj.m<A, B>(x),sql<Row>`…`,ref<A | null>(null)<and>comparisonscall_expressionwithtype_arguments!f<T>(x),await f<T>(x)value as T[],value satisfies T[],value as T[K](value as T)[<MISSING>]as_expression/satisfies_expressionwitharray_type/lookup_type@function.call/@function.method.call), as in any other call.expression, so the parser keeps bothf<T>(x)andf < T > (x)until one fails. Dynamic precedence picks the call when both parse, as TypeScript does.a < b > canda < b && c > dstay comparisons.new Foo<T>()keeps its owntype_arguments.extendsis now a keyword after<T, where an arrow's type parameters can start. It is also accepted as a JSX attribute name, so<Foo extends={x} />,<Foo extends />and<Foo extends bar />still parse as tags, with the same trees as before.as/satisfies(their precedence is nowPREC.REL + 1; it was 4). Their order relative to the other type operators doesn't change.Known limits:
x as A | Bandx as A & Bare still read as(x as A) | B, with no error. TypeScript reads the whole union as the type. The issue didn't cover this.await f(x)without type arguments is still(await f)(x), becauseawaithas call precedence. This is a separate, pre-existing gap.await f<T>(x)is now correct.<const T,>(x) => x, andconsttype parameters in general, are stillERROR:type_parameterhas noconstmodifier.<T>(x: T) => xas an arrow function. The compiler reads it as a tag, and after refactor(core): read generic arrows by TypeScript's TSX rule (#183) #1124 it reports TSRX1001 there, so the error now comes only from the language server.content: "</style >", the body therefore continues past the closing tag, where the compiler (after fix(core): end a style body at</style >, and name</>in a mismatch #1138) and tree-sitter end it. This was already the case for</style>and</script>.Generated
src/files come fromtree-sitter generate(tree-sitter-cli 0.26.6) and the plist frompnpm regenerate-textmate. No query changed:copy-tree-sitter-queriesleaves the Neovim copy as is, and Zed's copy stays at its pin.Verification
tree-sitter test --rebuild: 104/104. New corpus cases: "Style Element Closing Tag With Whitespace", "Call Expressions With Type Arguments", "As And Satisfies With Array Types", "Generic Arrow Functions", and "Tags That Start Like Generic Arrows" (a regression guard). With fix(grammars): end a <script> body at </script >, and parse using declarations #1104's grammar, the first four fail and the guard passes.packages/vscode-plugin/tests/grammar.test.js: 2 new<style>closing-tag tests (same-line</style >, and</stylethen>on the next line). Both fail on fix(grammars): end a <script> body at </script >, and parse using declarations #1104's grammar and pass here, 44/44..tsrxfiles, comparing fix(grammars): end a <script> body at </script >, and parse using declarations #1104 (92402cc7) with this branch:--lib-path, with ranges): 72 files are identical. The 6 that differ are the 6 that hadMISSINGnodes, and now have none. In them, the only changes are atuseState<X[]>(…)and) as HTMLInputElement[](theMISSINGsites) and atuseState<'section' | 'article'>(…),createSignal<…>(…)andref<HTMLInputElement | null>(…), which were comparisons and are now calls withtype_arguments.conststatements around the oldMISSINGnodes change fromlexical_declarationtovariable_declaration. That is the node every otherconstin those files already gets; the old one came from error recovery.a * b < c,!a < b,i++ < n,a < b + c,x < y >> z); and tags such as<b>(i) => i</b>and<Foo>(text)</Foo>. Every difference is one of the fixes above.npx vitest run: 10,001 passed, 82 skipped, 18 failed, at load average 60–100. Of the 18, 16 are timeouts and 2 are Shiki'sreading 'startIndex'(its per-line time limit, the same failure fix(grammars): end a <script> body at </script >, and parse using declarations #1104 saw on main's grammar). The failing files pass when re-run:--project vscode-plugin --project website(169/169), and the other 7 files with--testTimeout=120000(51/51).pnpm typecheckis clean, Prettier passes on the changed files, andpnpm changeset:checkpasses (Zed grammar rev check included).generate,regenerate-textmate,copy-tree-sitter-queries) leaves no diff.Changesets: one for the TextMate editors and one for the tree-sitter editors, as #1104 split them.
Related
Fixes #1155
Fixes #1156
🤖 Generated with Claude Code