Repository navigation
fix(core): report an unclosed tag without a later error from the code after it - #1353
Merged
jonkwheeler merged 7 commits intoNov 14, 2026
Merged
Conversation
… after it A collecting or loose parse recorded TSRX1001 for a tag left open, then threw a later error the unclosed tag caused, which Prettier, ESLint and the editor showed instead: - A tag left open in code read the code after it as its text (`return (<div>);`, `c ? <b> : null`, `[<div>]`). Text that starts with `)`, `]`, `:`, `,` or `;` is read again as code. - An unclosed `<style>` or `<script>` body ran to the end of the file in a collecting parse. Its body now ends at the next tag inside a template or at the `}` that closes its block, in a collecting parse as in a loose one, and an unclosed `<style>` body is read as partial CSS. An unclosed element is no longer moved to a static, where it lost the closing tag the editor's code adds. Fixes tsrx-org#1305 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es on
Codex review of the first commit:
- Text after an unclosed tag that starts with `:` or `,` is code only
where the code around the tag goes on with it: `)` or `,` in
parentheses, `]` or `,` in brackets opened in the statement, `:` after
a conditional's `?`. `@{ <div>: label }` keeps its text again.
- The `}` that ends an unclosed `<style>` or `<script>` body skips braces
in strings and comments, and in a script's template literals.
- An unclosed fragment isn't hoisted either.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex's second review:
- The code can go on right after the opening tag (`f(<div>, x)` in a
`@{ … }` setup statement), where the children read the code; that is
tried before the text after the last child.
- `]` or `,` goes on an element right after `[` or `,`, not any element
while a `[` is open, which made text in a directive body inside an
array read as code (`[@if (c) { <div>, label }]`).
- `}` goes on an element in a template literal's `${…}`, and `:` after a
`?` with a block comment between.
- An element in a `@{ … }` body's setup code is in code.
- The `}` scan skips an escaped CRLF in a string and a template literal's
`${…}`, nested templates included.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed templates iteratively Codex's third review: - When the code after an unclosed tag starts right after it, the children read in between are dropped and read again as code, so the errors they recorded (`f(<div>, <b>)`: TSRX1001 for `<b>`) are dropped too instead of being reported twice. - The `}` scan follows nested template literals with a stack instead of recursion, which deep nesting could run out of. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex's fourth review: shortening the collected errors outside the undo
log made a speculative parse around the element throw when it rolled
back (`async <T>(a = [<div>, <style>.a {}]) => a`).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
tsrx-org#1344 on main parses a <style> body strictly and, on a CSS syntax error, throws it or records it and reparses loosely. This branch parsed an unclosed <style>'s partial body loosely. Keeps tsrx-org#1344's handling and treats an unclosed <style> like a loose parse there: it gets its TSRX1001 alone, in every mode. Keeps both sides' new tests in the ESLint parser and Prettier plugin test files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cb1dcf9. Configure here.
…ment Cursor Bugbot on cb1dcf9: the code after a tag left open was read again only when no `//` or `/*` appeared from it to the end of the template, often the rest of the function, so a later comment, or `http://` in a string, kept it the element's text, and the parse still threw the later error instead of reporting TSRX1001 alone. Comments no longer stop it. The plugin records each span it reads again (`textReadAsCode`), and the parser then keeps the comments there as the code reads them: one copy of each, and none that the text read where the code has a string, a template literal or a regular expression (`'a // b'`), or inside a comment (`/* b */` in `a;// /* b */`, where the text reads the `//` as text). A comment also splits the text after the element's last child into pieces, so where its last piece doesn't go on with the code, the code is looked for where that text starts, past whitespace and comments (`<div><b>x</b> );` and a comment after it). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
marked this pull request as ready for review
November 14, 2026 16:10
This was referenced Nov 17, 2026
jonkwheeler
added a commit
that referenced
this pull request
Nov 18, 2026
…1369) * fix(core): read the token before an unclosed tag past line comments The recovery for a tag left open in code (#1353) looked back from its `<` for the token before it, past whitespace and block comments only. A line comment between a conditional's `?` and the tag (`c ? // note`, a line break, then `<b> : null`) hid the `?`, so the text after the tag stayed the tag's text, and a collecting or loose parse threw TS1012 `Unexpected token` at the `:`, which Prettier, ESLint and the editor showed instead of TSRX1001. A line comment after `[`, or after `,` in an array, did the same. An element that starts in an expression now takes the end of the token before its `<` from the tokenizer, which read the comments between as comments. It is used where only whitespace and comments, as the tokenizer skips them (`regex_space_and_comments`), lie between that token and the `<`: a no-break space, a form feed or a byte order mark there counts as whitespace, as it did before. Comment text is no longer taken for that token either: a `// why?` before `<div>: label` made the text read as code, and a block comment with `/*` in it (`/* a /* b */`) hid the `?` before it. 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.

Summary
Fixes #1305. For the unclosed tags in the issue, a strict compile throws TSRX1001, but a collecting parse (what Prettier and
@tsrx/eslint-parserrun) and a loose one (the editor's) recorded TSRX1001 and then threw a later error that the unclosed tag caused, which the tools showed instead. Now each reports TSRX1001 and goes on.),]or:. When the text after its last child starts with what the code around it goes on with, that text is read again as code:)or,in parentheses,]or,in brackets opened in the statement,:after a conditional's?. Other text stays the element's, as before (@{ <div>: label }). A comment later in the code doesn't stop this: the comments in the code read again are kept as the code reads them, one copy of each, without those the text read where the code has a string, a template literal, a regular expression or a comment ('a // b',a;// /* b */).<style>or<script>body ran to the end of the file in a collecting parse (and in a loose one outside a template). It now ends at the next tag inside a template, as a loose parse did, or at the}that closes the block it's in (braces in strings and comments don't count), in both modes; an unclosed<style>body is read as partial CSS.const App__static1 = <b>;, found while testing the conditional row; it happened on main for<p>{ok && <b>}</p>too).Results with
@tsrx/reacton main (8d2b839) and on this branch. Positions are line:column, 0-based for the parse and the editor, 1-based for Prettier and ESLint, as each prints them:return (↵<div>↵);after: TSRX1001 at 3:3
after: TSRX1001
Unexpected token (5:1)after:
Unclosed tag '<div>' … (3:4)0:0 … Unexpected token (5:0)after:
3:4 Parsing error: Unclosed tag '<div>'…return <div>{props.x ? <b> : null}</div>;after: TSRX1001 at 2:25
after: TSRX1001
Unclosed tag '<b>' … (2:26)2:26 … Unclosed tag '<b>'…return [<div>];after: TSRX1001 at 2:10
after: TSRX1001
… (2:11)2:11 …@{ <style>.a {} }Expected identifierafter: TSRX1001
'}' expectedat the endafter: TSRX1001, and TSRX3009 (a
<style>as the block's output, also reported when it's closed)Expected identifierafter:
Unclosed tag '<style>' … (2:2)2:2 … Unclosed tag '<style>'…@{ <div><style>.a { color: red; }</div> }after: TSRX1001
… (3:3)3:3 …@{ <script>const a = 1; }after: TSRX1001
after: TSRX1001
return (↵<div>↵);↵// laterafter: TSRX1001 at 3:3, and the comment once
after: TSRX1001
Unexpected token (6:1)after:
Unclosed tag '<div>' … (3:4)6:1 Parsing error: Unexpected tokenafter:
3:4 Parsing error: Unclosed tag '<div>'…return [<div>];↵/* later */after: TSRX1001 at 2:10, and the comment once
after: TSRX1001
… (2:11)2:11 …return (↵<div>↵<b>x</b>↵);↵// laterafter: TSRX1001 at 3:3, and the comment once
after: TSRX1001
… (3:4)3:4 …return [<div>, 'a // b'];after: TSRX1001 at 2:10, and no comment
after: TSRX1001
… (2:11)2:11 …ESLint's positions come out right here because the error is now a collected one; a thrown error's
0:0is #1308. The last four rows' before is main at a0f7749 (where #1308 is fixed) and this branch at cb1dcf9, which threw the same errors: a comment, or//or/*anywhere, from the code to the end of the template kept the code the element's text.Not covered, and as on main: an unclosed tag in an
@forheader or in a dynamic tag's expression, which another element parser reads (@for (const x of [<b>]),<{c ? <b> : 'div'} />); a line comment between?and the tag; a function parameter's default (function f(x = <b>) {}, whose children read the body's{}); an object literal's comma ({ a: <b>, c }, where, cstays text); a regular expression with a}in an unclosed<script>body; and, after a child of the element, a string or regular expression with/*and then a),]or,in it, as the last text ([<div><b />, 'a /* b */ ] c']), where the code is read again from that closer. An unclosed<>inside{…}now reaches the printer's TypeError that #1304 is about ({c ? <> : null}threw TS1012 before).Tests
packages/tsrx/tests/shared/compile.js, for each of the five targets: the editor's compile reports TSRX1001 where a collecting parse records it, and nothing else, with valid TSX, for the issue's six shapes plus[<div>, 1],@{ <div>: label },@{ <div>, hello }, and<style>/<script>bodies with a}in a string or comment.async <T,>(a = [<div>, 1]) => a; // later), after a division, a line comment that touches the code, and//or/*in a string, a template literal or a regular expression.packages/prettier-plugin/tests/tsrx.test.jsandpackages/eslint-parser/tests/index.test.ts: the issue's shapes report TSRX1001 at the tag, and so do two with a comment later in the function.packages/tsrx/tests/utils/closing-brace.test.js: a collecting parse now recovers an unclosed<style>body like a loose one, so it stops at the missing}at the end, not at: red.plugin.jsandjsx-hoist.jschanges reverted and the tests kept, 93 tests fail: 15 of the 18 shared cases on each of the six harnesses that run them (React, Preact, Solid, Vue, Hono and@tsrx/hono/dom), the closing-brace test, and the Prettier and ESLint tests. The 18 that pass are the three cases that guard text that must stay text (@{ <div>: label },@{ <div>, hello },[@if (c) { <div>, label }]), which pass on main too.plugin.js,parse/index.jsandparse.d.tschanges reverted and the tests kept, 92 tests fail: 15 of its 17 shared cases on each of the six harnesses, and the Prettier and ESLint tests. The two that pass pin what this branch did before, a)in the element's text before the real one ((<div><b />) y /* d */ );). Reverting each part alone, on the React harness: keeping every comment the text and the code read fails 14 shared cases, keeping those in strings, template literals and regular expressions 5, keeping a comment inside another 1, and not looking where the text after the last child starts 3.format:check,typecheckandchangeset:checkpass locally on 7757322.@{ <div>: label }read as code, unclosed fragments hoisted, and the parsers noted above as not covered. dfe6a31: setup statements in@{ … }(f(<div>, x)), template literals, an outer[leaking into directive bodies, a comment before?, an escaped CRLF and nested templates in the scanner (plus object commas and function parameter defaults, which behave as on main). 83ab11b: errors of dropped children reported twice, recursion depth. 33129e9: shortening the errors outside the undo log. d100faa: no findings. Each finding is fixed in the next commit with a test, except those noted as not covered or as on main. 7757322, for Cursor Bugbot's finding on cb1dcf9, took five rounds before the commit. Round 1: a first version that still refused where//or/*sat in a string or in what might be a regular expression misjudged division ("x" / 2,x++ / 2) and regular expressions (afterdefault), and refused for strings in JSX attributes and${…}, so it was replaced by dropping, after the parse, the comments the text read inside a literal of the code. Rounds 2 to 4: each order of trying the text pieces picked a)or]that isn't the code's in one source ((<div>x /* c */ ) y /* d */ );,[<div><b />, 'a /* b */ ] c'];,(<div><b />) y /* d */ );); now this branch's earlier candidates come first, then where the text after the last child starts, and the case left is listed above as not covered. Round 5: no findings.🤖 Generated with Claude Code