Repository navigation
fix(core): read a <script> body as raw text and print it from content in every target (#708) - #790
Merged
Merged
Conversation
…prints from `content` (#708) A `<script>` body is raw text, like a `<style>` body, in templates and in plain JSX: `content`, taken as written, with no comments, no character references, and no `{…}` expressions. The parser no longer mirrors it as a `JSXText` child, which compiled to JSX text: its lines were joined, so a `// c` line commented out the rest of the script, `&` rendered `&`, and `<script>{code}</script>` became an expression container. Each target prints the body in the form that renders it exactly, on the client and in server HTML: React a string child, Preact and Hono `dangerouslySetInnerHTML`, Solid `innerHTML`, and Vue `v-html` (vue-jsx-vapor writes a string `innerHTML` into its template as an attribute). Whether a script runs stays each target's decision. A body ends where HTML ends it, at `</script`, optional whitespace, and `>`. Any other `</script` in the body, in any letter case, is the new `tsrx-script-end-tag-in-body` error, with a hint to write `<\/script`. The JSX text printer no longer escapes braces, which only reached it from script bodies. Both formatters, the TypeScript plugin's fallback script extraction, the specification, llms.txt, the Hono README, and the MCP docs follow the new rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 26, 2026
This was referenced Sep 26, 2026
This was referenced Sep 27, 2026
leonidaz
added a commit
that referenced
this pull request
Sep 30, 2026
Conflicts, resolved to this branch's design: - packages/typescript-plugin/src/language.js: keep the removal of the `<script>` fallback extractor (071421a); main's end-tag tweak to it (#790) has no counterpart here. - packages/typescript-plugin/tests/tsc.test.js: keep this branch's TypeScript 7 tests and add main's new tests after them. - website-tsrx/src/pages/getting-started.tsrx: keep this branch's text about TypeScript 7, formatted by main's formatter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 26, 2026
Merged
jonkwheeler
added a commit
that referenced
this pull request
Nov 12, 2026
…larations (#1104) * fix(grammars): end a <script> body at </script >, as the compiler does (#792) The compiler ends a `<script>` body at `</script`, optional HTML whitespace, then `>` (#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. * fix(grammars): parse and highlight using and await using declarations (#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. * fix(tree-sitter): keep using a variable name in parameters, patterns, 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. * fix(textmate): highlight using in a directive head only as a for…of declaration 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. * fix(zed): keep the Zed queries matched to the pinned grammar, and check 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. * chore(scripts): stop suggesting a manual Zed rev sync on query drift 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]>
jonkwheeler
added a commit
that referenced
this pull request
Nov 12, 2026
…eep raw script bodies (#1121) * fix(core): leave static JSX in place when its tag reads an uninitialized binding Static JSX is hoisted to a module-level const placed before the top-level statement it came from, so its tag is read when the module loads. A tag that reads the class the JSX is in (`<Screen.Tag>` in a method of `class Screen`), a const or class declared later, or `this` then threw on import: "Cannot access 'Screen' before initialization". Hoisting now skips JSX whose tag reads `this` or a name that a top-level statement binds at or after the one the JSX is in. Function declarations and imports are initialized before the module body runs, so tags that read them are still hoisted. Fixes #204 * fix(core): keep raw script bodies in hoisted static JSX Since #790 a raw `<script>` keeps its body in `content`, and the walk lowers it when it reaches the element. An element in an expression container or attribute value of static JSX is reached only in the render output the walk returns, which a hoisted static has already left. So `<div>{<script type="application/json">{"a":1}</script>}</div>` and a script passed as a prop rendered an empty script on every target. Hoisting now lowers those scripts with the platform's element transform, as the walk would. Fixes #845 * fix(core): hoist static JSX only when each tag resolves to a stable module binding The #204 fix checked tags only against top-level declarations, by position. It still hoisted `<super.Tag>` (a module that fails to parse), `<Screen.Tag>` in `const C = class Screen { … }` (`Screen is not defined`), tags that read a static block's or block's bindings, and member tags such as `<Menu.Item>` whose property is assigned after the module loads, along with tags that read a `let` or `var` assigned later. Each tag now resolves through the scopes it is written in, and static JSX is hoisted only when every tag that reads a binding resolves to an import, a function declaration, or a `const` or class declared in an earlier statement. A member tag that starts with a function or class declared in the module is read at render time, as is a tag that reads `this`, `super`, a local binding, a `let`, `var`, enum, namespace or import alias, or a name the module does not declare. Intrinsic tags like `<div>` read no binding, so a later `const div` no longer stops them from being hoisted. Related: #204 * fix(core): keep static JSX in place in a component inside another function A component's statics and helper components go to module level through the top-level statement that holds it, and `expand_component_helpers` finds them only through nodes that are not functions. A component declared inside another function (`function outer() { function App() { return <div>hi</div> } }`) still hoisted its JSX, so it returned `App__static1`, which was never declared, and threw a ReferenceError when it rendered. Such a component now gets no helper state, so it lowers its statics and helpers in place, as code outside a component does. * fix(core): hoist a member tag only when it starts with an import A member tag on a `const` declared earlier was still hoisted, so the compound-component pattern `const Menu = …; <Menu.Item />` with `Menu.Item = …` (or `Object.assign(Menu, { Item })`) after it read `Menu.Item` when the module loaded and rendered an undefined type. A member tag now stays at render time unless it starts with an import (named, default or namespace). Plain tags keep the earlier rules. Related: #204 * fix(core): keep the helper state of a component inside another function Giving such a component no helper state, to keep its statics and helper components in place, also moved its spread temporary to the fallback name `_tsrx_spread_props_N`, which can shadow or redeclare a user variable of that name. The component now gets a local helper state again: it names things as it did on main and keeps its statics and helper components in place. The spread temporary, in core and in Solid, also skips any name the module source already uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #708.
A
<script>element is now a raw-text element, like<style>, in templates and in plain JSX, as #708 decided on 2026-09-26. Its body iscontent, taken as written, and each core target prints it in the form that renders it exactly, on the client and in server HTML. Whether a script runs stays each target's decision.The bug
The parser kept the body on
contentand also mirrored it as oneJSXTextchild, which the targets printed as JSX text. A JSX compiler joins the lines of JSX text and decodes its character references, so this script:rendered
// c run(); if (a < b) x = "&";in React, all one comment, and// c run(); if (a < b) x = "&";in Solid's and Vue's HTML templates.<script>{code}</script>printed back as an expression container, and static hoisting then threwReferenceError: code is not defined. The body also ended only at an exact</script>:</script >was reported as unclosed, and</SCRIPT>stayed in the body, where a browser ends the script.The fix
Parser (
#parseScriptElement,#findScriptBodyEndinpackages/tsrx/src/plugin.js). The element has no children;contentis its only body,""for<script></script>. The body ends at</script, optional HTML whitespace, then>. Any other</script, in any letter case, is the newtsrx-script-end-tag-in-bodyerror, collected in collect and loose mode:That includes
</scripts>and</script-x>, which a browser doesn't treat as an end tag. The rule stays the one [Bug]: tsrx-core: A<script>body compiles to JSX text, so its line breaks collapse and its character references decode #708 states: every other</script.Targets. A new
JsxPlatform.jsx.scriptBodyoption picks the form, andcreateScriptBodybuilds it, for core'sto_jsx_elementand Solid's own:<script>{"…"}</script><script dangerouslySetInnerHTML={{ __html: "…" }} /><script innerHTML={"…"} /><script v-html={"…"} />Vue uses
v-html, not theinnerHTMLin [Bug]: tsrx-core: A<script>body compiles to JSX text, so its line breaks collapse and its character references decode #708's table. [Bug]: tsrx-core: A<script>body compiles to JSX text, so its line breaks collapse and its character references decode #708's check usedinnerHTML={code}, a variable. With a string literal, vue-jsx-vapor writes the value into its HTML template as an attribute,<script innerHTML="…">, so the client's script is empty.v-htmlsets the sameinnerHTMLwhen the element is created (_setHtml(el, "…")), and the server renders it asinnerHTML. A dynamic body in Vue is stillinnerHTML={code}, which vue-jsx-vapor sets at runtime.A body of only whitespace outputs an empty script, as both formatters print it. The type-only editor output still leaves the body out; the embedded document from
scriptMappingscovers it.JSX text printer.
escape_jsx_textno longer writes{and}as{and}: only script bodies brought braces to it. fix(core): write a>in text as>, read it as text in containers, and print JSX text fromraw(#694, #693) #711's pending changeset said script braces compile to references, so I removed that sentence from.changeset/core-text-escaping.md.@tsrx/prettier-plugin.embed()formats the body fromcontenton the element and records the doc forprintJSXElement, which prints it, or the body's lines as written. WithembeddedLanguageFormatting: 'off'the body was printed as JSX text before, with its lines joined; it keeps its lines now.tsrx-prettier-pluginalready printed fromcontentand needed no change.@tsrx/typescript-plugin. The fallback script extraction for a file that doesn't compile ends a body at</script, whitespace,>, as the parser does.ESLint parser and plugin, language server,
segments.js. Nothing read the child:scriptMappingsand the language server usecontent. ESLint no longer visits the body as aJSXTextnode.Docs. The specification has a new 4.6 Script Elements (Server Extensions is now 4.7), a 5.2 early error, a host-defined item in 6, and the AST appendix's
content.llms.txthas a Scripts section with each target's dynamic-body property and whether a client render and server HTML run a script. The Hono README has a Scripts section. The React, Preact, Solid, and Vue compiler packages have no README, so their notes are only inllms.txt. The MCP docs' text section describes the rule and includes the grammar.Changeset.
minorfor@tsrx/core,@tsrx/react,@tsrx/preact,@tsrx/hono,@tsrx/solid, and@tsrx/vue, since it changes what<script>{…}</script>means and what existing scripts render.patchfor@tsrx/prettier-plugin,@tsrx/typescript-plugin, and@tsrx/mcp.Overrides
None.
Verification
.tsrxfile, the input and output of all 2,040 Prettier snapshot cases (readSnapshotEntries/readFormatCase), and 15,663 string literals from test files, 19,820 inputs frommain(9c2f24f8) and this branch, parsed strict, with{ collect: true, errors: [], comments: [], preserveParens: true }, and with{ loose: true }, in 4 workers with a 15 s kill. No hangs. 55 inputs change, 46 of them onmain:JSXTextchild, in all three modes: after dropping script children frommain's AST, both ASTs and their errors are the same. All 46 onmainare among them.</script\n\t>test, now parses;mainreportsUnclosed tag '<script>'.<script(86 onmain), compiled with each target onmainand this branch. Onmain's inputs, 41 change for every target, each script body now a string; 15 are the same (self-closing scripts, empty bodies, bodies of only whitespace); 30 fail to compile on both for other reasons. Every output of both revisions parses with TypeScript's TSX parser and builds with esbuild.playwright, a body with a// cline,<,>,&, and a block, a JSON body, and<script>{window.__ran = …, window.__amp = typeof code}</script >in a plain function. In every target the script'stextContentis the body as written, on a client render and from server HTML. React, Solid, and Vue don't run it on a client render; Preact andhono/jsx/domdo; server HTML runs it in React, Preact, Hono, Solid, and Vue.typeof codereads"undefined": the component'scodeisn't inserted.vitest run --maxWorkers=4passes fortsrx-utils,tsrx-analyze,tsrx-react,tsrx-preact,tsrx-solid,tsrx-vue,tsrx-hono, the five runtime projects,vite-plugin-*,prettier-plugin,tsrx-prettier-plugin,tsrx-mcp,typescript-plugin,language-server,eslint-parser, andeslint-plugin. The Prettier known-failures list is unchanged. New tests:parse_in_worker_with_ast: no children; comments, references, and braces as text, in a template, a plain function, and at the module level;</script >,</script\n\t>, and</script\t\f\r >close the body;</SCRIPT>,</Script >,</script/>,</script foo>, and</scripts>are reported, strict and collected;<\/scriptis text;runSharedScriptBodyTests): the form and exact string for a code body, plain JSX, a JSON body, an import map,{code}, a closing tag with a line break, and<\/script; a body of only whitespace; a self-closing script with the target's dynamic-body property;script-body-components.tsrx: each script'stextContentin React, Preact, Solid, Vue, andhono/jsx/dom(jsdom);runScriptBodyServerTests), through a Vite SSR server: Hono'shono/jsxand Solid'sgenerate: 'ssr'.pnpm typecheckandpnpm format:checkpass.Downstream
Ripple-TS/ripplemainat83ed5615,@tsrx/corelinked through a pnpm override).tsrx-ripple,ripple-client,ripple-server, andripple-hydrationgive the same results withmain's core and this branch's: 2,113 of 2,129 pass, and the same 4 fail on both (style-identifier/scoped-styles, the assigned-style change tracked in Adopt @tsrx/core's rule that assigned style blocks keep every selector (tsrx-org/tsrx#251) Ripple-TS/ripple#1516). The client and server output for scripts is unchanged: both readcontent.compile_to_volar_mappingsprinted the mirrored child into the TS view as JSX text,<script>if (a < b) { x = "&"; }</script>and<script>{code}</script>, which TypeScript reads as markup; it now prints<script></script>, andscriptMappingsstill carries each body. No Ripple change is needed. [Bug]: An inline<script>in<head>runs again after hydration, and the client drops its attributes (type="module",type="application/json") Ripple-TS/ripple#1521, filed from [Bug]: tsrx-core: A<script>body compiles to JSX text, so its line breaks collapse and its character references decode #708, is a bug today and independent of this PR.octanejs/octanemainate813fc0e, same override). Theoctaneproject, 13,357 tests, gives the same results except tests that also fail or pass by timing onmain's core:behavior-root.test.ts's textarea retirement tests fail 0 to 7 times per run with either core. Its client and server output and TS view for scripts are unchanged. On Node, Octane parses with@tsrx/oxcfirst, so it follows oxc;<script>{code}</script >in a plain function, which failed with both parsers, now compiles through the fallback to core, with{code}as text. No Octane change is needed.@tsrx/oxc. A<script>body in a plain function's JSX is parsed as JSX children with nocontent, where@tsrx/corereads it as raw text oxc#114, filed from [Bug]: tsrx-core: A<script>body compiles to JSX text, so its line breaks collapse and its character references decode #708, covers a plain function's body and the removed child. A<script>body ends only at an exact</script>, where@tsrx/coreends it as HTML does and reports any other</scriptoxc#116, filed for this PR, covers the end-tag rule:tsrx-core-compatfails on</script >and keeps</SCRIPT>without the error.Findings
<script>(i) => i</script>, still fails to parse: [Bug]: tsrx-core: An element whose text starts like an arrow function, such as<b>(i) => i</b>or<script>(i) => i</script>, is read as a generic arrow function and fails to parse #734, a separate cause. The new tests avoid it.innerHTML="…"string on a host element into its template as an attribute, so the element is empty on the client, for any element, not only<script>. The Vue target avoids it withv-html. It's upstream in vuejs/vue-jsx-vapor, which I haven't filed.<script>or<style>body only at an exact closing tag, so</script >highlights the rest of the file as script #792: the TextMate and tree-sitter grammars end a script body only at an exact</script>, so after this PR<script>go();</script >highlights the rest of the file as script.<style>body ends only at an exact</style>, so</style >is reported as an unclosed tag #793: a<style>body still ends only at an exact</style>, so</style >is reported as unclosed.🤖 Generated with Claude Code
Note
Medium Risk
Semantically changes how every inline
<script>compiles and renders across all targets; incorrect migration could affect script execution and XSS-sensitive output, though the change aligns behavior with HTML and is heavily tested.Overview
<script>bodies are now raw text (like<style>): the parser stores verbatim source oncontentand stops mirroring it as aJSXTextchild, so JSX text rules no longer join lines, decode entities, or treat{…}as expressions. Closing tags follow HTML rules (</script >, case-insensitive ends) with a newtsrx-script-end-tag-in-bodydiagnostic for stray</scriptsequences.Each JSX target emits the body so it renders exactly via new
JsxPlatform.jsx.scriptBodyandcreateScriptBody: React uses a string child; Preact/Hono usedangerouslySetInnerHTML; Solid usesinnerHTML; Vue usesv-htmlfor static bodies. Whitespace-only bodies compile to empty scripts.Tooling and docs move with the model: Prettier formats from
content, the TypeScript plugin’s script fallback regex matches the parser,escape_jsx_textno longer escapes braces (scripts aren’t JSX text), plus spec/MCP/Hono README updates and shared compile/runtime/server tests.Reviewed by Cursor Bugbot for commit aa8f18c. Bugbot is set up for automated code reviews on this repo. Configure here.