Repository navigation
fix(core): read the token before an unclosed tag past line comments - #1369
Merged
jonkwheeler merged 1 commit intoNov 18, 2026
Merged
Conversation
The recovery for a tag left open in code (tsrx-org#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
jonkwheeler
marked this pull request as ready for review
November 18, 2026 17:36
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 18, 2026
tsrx-org#1367 is now on main as bd00fda, and tsrx-org#1369 as 4500db9. This merge takes main in with tsrx-org#1367's commit as the base, so the tree is main plus this branch's own commit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Merged
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
Since #1353, a tag left open in code is reported as TSRX1001. But with a line comment between a conditional's
?and the tag, the collecting parse and the editor compile threw TS1012Unexpected token, so Prettier and ESLint showed that instead:compile(strict)parseModule(…, { collect: true })Unexpected token (3:12)<b>compile_to_volar_mappings(…, { loose: true })Unexpected token (3:13)Unclosed tag '<b>'3:13 Unexpected tokenUnclosed tag '<b>'What was wrong. To find what the code goes on with after the tag,
#rereadTrailingCodeOfUnclosedElementscanned back from the<for the token before it, skipping whitespace and block comments only.?, so the text after the tag stayed the tag's text. A line comment after[, or after,in an array, did the same.// why?before<div>: labelmade the text read as code./* a /* b */, becauselastIndexOf('/*')finds the inner/*.The fix. An element that starts in an expression takes the end of the token before its
<from the tokenizer (lastTokEndinjsx_parseElement), which already read the comments between as comments. That position is used only when nothing but whitespace and comments, as the tokenizer skips them (regex_space_and_comments), lies between that token and the<. A no-break space, form feed or byte order mark there still counts as whitespace, as it did before.Not covered
The forward side of the same recovery has a matching gap, and it's the same on main.
goes_on_at(#1353) finds where the code goes on after the tag withskip_whitespace_from, which skips only spaces, tabs and line breaks. So a no-break space or form feed right after the tag (const a = [<b> ];) still throws TS1012 in the collecting parse. That's a one-line follow-up.Tests
UNCLOSED_TAG_RECOVERY(packages/tsrx/tests/shared/compile.js, all five targets), next to the block-comment case:?;/* a /* b */;[, and after,in an array;?doesn't make the text after the tag read as code.?or[) guard the whitespace check. They already pass on main.Unexpected token,Expected identifier,'}' expected) instead of TSRX1001 #1305 tests get the line-comment case.plugin.js, 50 of these tests fail (8 core cases on 6 projects, plus the Prettier and ESLint tests).npx -y [email protected] test: 15,098 passed, 102 skipped.typecheck,format:checkandchangeset:checkpass.<threw. That's fixed above, with tests.Fixes #1366
🤖 Generated with Claude Code
https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Note
Medium Risk
Touches expression-position JSX parsing and error recovery in the core parser; behavior change is localized to unclosed-tag paths but affects all tooling that uses collecting/loose parse.
Overview
Unclosed-tag recovery (TSRX1001) no longer scans backward from
<to guess the preceding token. When a tag starts in an expression, the parser now remembers the tokenizer’slastTokEndbefore that<and, only if nothing but whitespace and comments lies between, uses that to tell whether code continues with?,[,,, etc.Collecting/loose parses, Prettier, and ESLint therefore report Unclosed tag instead of
Unexpected tokenfor patterns likeprops.x ? // cthen<b> : null, and comment text ending in?no longer fools recovery into treating markup text as code (// why?before<div>: label).Tests extend unclosed-tag recovery (line/block comments, CRLF, nested
/*), plus the existing #1305 ESLint/Prettier cases.Reviewed by Cursor Bugbot for commit 21d3f71. Bugbot is set up for automated code reviews on this repo. Configure here.