Repository navigation
fix(core): require esrap 2.4 and map editor output through its tokens - #1085
Conversation
esrap 2.4 removed `boundaryTokens`, and fresh installs of @tsrx/core already resolve `^2.3.2` to it. Pass the parser's tokens to esrap's new `tokens` option for type-only prints, and correct the mappings its new per-node start/end markers misplace (program start, interface bodies, lowered dynamic tags). Print `<T,>` only on one-parameter generic arrows, where TSX needs it (tsrx-org#707), and drop the parameter-property override esrap now covers (tsrx-org#606). Tagged-template type arguments come back with the bump (tsrx-org#272). Pin esrap 2.3.2 for the published Ripple compiler, which still passes `boundaryTokens`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ff7a08d. Configure here.
| } else { | ||
| context.write('<'); | ||
| context.visit(node.name); | ||
| } |
There was a problem hiding this comment.
Closing dynamic tags keep bad mappings
Medium Severity
Generated closing names still print after a separate </, so esrap's tokens mapping can attach the source {tag} span onto TsrxDynamic in </TsrxDynamic>. The opening-tag path already avoids that leftover mapping by writing the angle bracket and generated name together; JSXClosingElement does not.
Reviewed by Cursor Bugbot for commit ff7a08d. Configure here.
esrap 2.4 prints an array pattern's type annotation itself, and the
wrapper that added the annotation esrap 2.3 left out printed it again:
`function f([a]: number[]) {}` compiled to
`function f([a]: number[]: number[]) {}`, which does not parse. This
hits every target's compiled output and type view, and also published
`@tsrx/core` (which allows `esrap@^2.3.2`) on a fresh install.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
TypeScript applies a directive to the first line after it that is neither blank nor a line comment. The type view lost that in three ways: - A plain block comment between a directive and its code was dropped, so the directive covered the code. The comment now stays when it follows a directive, for the line form too. - Comments that share a line were split over several lines, which put a JSDoc comment between a directive and its code. They now stay on one line. - A directive on the line where its statement starts was kept on that line, but it covers the source line after it, and the printer splits or joins the lines of the statement. It is now left out, as before tsrx-org#866's fix. A block directive is now recognized as TypeScript does, from its last line, so `/* explanation\n@ts-expect-error */` applies too. The changeset no longer lists the array pattern fix, which tsrx-org#1085 describes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now has tsrx-org#1085'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
…#1093) * fix(eslint-parser): stop @switch cases crashing ESLint ESLint's code path analysis treats every `SwitchCase` node as a case of a `switch` statement. A `@case` or `@default` inside `@switch` has no enclosing switch context, so linting any file with `@switch` threw "Cannot read properties of null (reading 'hasCase')", even with no rules enabled. The parser now hands ESLint those cases as `JSXSwitchCase` nodes, visited like `SwitchCase`. `@case` bodies never fall through, so they need no switch code paths, the same way `@if` branches get none. Fixes #913 * feat(core): record every token on a keywordTokens parse A parse with `keywordTokens` now also stores every token the lexer reports on the program as `tsrx_tokens`. The ESLint parser reads them to give ESLint a token list. This is the same change as the parser hunk of #1085, which records the tokens for esrap's `tokens` option, so the two merge cleanly in either order. * fix(eslint-parser): give ESLint the comments and tokens The parser collected comments but returned the program with empty `comments` and `tokens`. ESLint therefore ignored every `eslint-disable` and other directive comment in a `.tsrx` file, and rules that read tokens broke: `no-unused-vars` crashed on an unused function parameter while it built its suggestion. The program now carries the comments, with `range` and `loc`, and a token list converted from the TSRX lexer's tokens in espree's shape: template chunks merged, JSX attribute strings as `JSXText`, and the tokens the lexer reports twice after a lookahead removed. The lexer reports no token for the `@` of a template directive or the body of a raw `<style>` or `<script>` element, so those become `Punctuator` and `JSXText` tokens; every character outside whitespace and comments is in a token. Fixes #454 Fixes #228 * fix(eslint-parser): start and end every node on a token Rules that look up a node's first or last token crashed on nodes with no token at their ends: - `TemplateElement` kept acorn's range, which leaves out the delimiters, so `template-curly-spacing` threw on `` `x${y}z` ``. It now spans its delimiters, as in espree. - The lexer reports no token for whitespace-only JSX text, so `indent` threw on a JSX child list with line breaks. Every `JSXText` node is now one `JSXText` token. This also fixes text right after a template directive's block, which the lexer read as code (`Identifier " hello"`). - A comment in JSX text kept a `JSXExpressionContainer` placeholder spanning just the comment, so `indent` threw on it. ESLint already gets the comment itself, so the placeholder is dropped from the children. * fix(eslint-parser): show ESLint a @for loop as a for statement `semi --fix` rewrote `@for (const item of items)` into `@for (const item; of items)`, which does not parse. `semi`, like `init-declarations` and other loop-aware rules, only treats a declaration as a loop head when its parent is a for statement, and the parent was `JSXForExpression`. ESLint's scope analysis also declared no `@for` index, so core `no-undef` reported it. The loop of a `@for` is now a real `ForOfStatement`, `ForInStatement` or `ForStatement` in the new `loop` field of `JSXForExpression`. ESLint's code path analysis allows a for statement no children of its own beyond its standard fields, so `index`, `key` and the `@empty` branch stay on `JSXForExpression`, and visitor keys still reach every part. The parser now returns its own scope manager, built with `eslint-scope` (a new dependency, the version `eslint` already installs). It declares the loop's `index` and resolves its `key` in the loop's scope, next to the loop variable, and the `@empty` branch outside it. `valid-for-of-key` no longer needs its own exception for the index, and `control-flow-jsx` reads the loop body from `loop`. Related: #559 * chore(changeset): make the @for AST change a minor bump A `@for`'s loop fields move from the `JSXForExpression` into a real for statement in `loop`, and `@switch` arms become `JSXSwitchCase` nodes. Earlier AST field moves in this repo released as minor. The changeset now says which fields moved and what tools read instead. The `@tsrx/eslint-plugin` and `@tsrx/core` entries stay at patch: the plugin's change is a fix, and core's `tsrx_tokens` is an addition. The fixed group still takes the plugin, with the parser, language server, Prettier plugin and TypeScript plugin, to 0.7.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now has tsrx-org#1085, tsrx-org#1086'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
main now has tsrx-org#1085, tsrx-org#1086'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
main now has tsrx-org#1085, tsrx-org#1086'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
…s it Since main's tsrx-org#1085, the virtual code maps an expression statement's expression from the line break and indent before it: in `<p>@{user.nmae}</p>`, the verify-only mapping for `user.nmae` covers 14 generated characters for its 9 source ones. The plugin still finds the generated `user.nmae` for the warning, but Volar maps that range back through the longer mapping, so its start lands 5 characters late, on `nmae`. The warning, its code, severity and message are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
In jsx/helpers.js and tests/shared/compile.js, main's element-operand parentheses fix (tsrx-org#1167) added code and tests at the spots where this branch adds its binding-pattern, string-statement and comment printing; both sides are kept. The binding-pattern-annotation test this branch shared with tsrx-org#1085 is already on main, so it appears once. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…ritten in printed output (#1097) * fix(core): print an array pattern's type annotation once esrap 2.4 prints an array pattern's type annotation itself, and the wrapper that added the annotation esrap 2.3 left out printed it again: `function f([a]: number[]) {}` compiled to `function f([a]: number[]: number[]) {}`, which does not parse. This hits every target's compiled output and type view, and also published `@tsrx/core` (which allows `esrap@^2.3.2`) on a fresh install. * fix(core): keep the ? of an optional binding pattern parameter esrap prints a binding pattern's type annotation but not the `?` of an optional one, so `declare function f({ a }?: T): void` and `([a]?: T[]) => void` printed as required parameters, and calling `f()` reported TS2554 in the editor. A wrapper now writes the `?` before the annotation, marked to go once sveltejs/esrap#245 is released (#556). * fix(core): keep the parentheses of a string statement that is not a directive esrap writes a string statement without its parentheses, so `('use strict');` compiled to a `'use strict'` directive: an early error beside a default parameter, and strict mode elsewhere. A string statement the parser did not mark as a directive now keeps its parentheses, as Prettier prints it, until sveltejs/esrap#246 is released (#968). * fix(core): keep block TypeScript directives and print block comments as written The type view dropped every block comment at statement level that was not JSDoc, so `/* @ts-expect-error */` and `/* @ts-ignore */` stopped applying, and tsrx-tsc reported the errors they suppress (#866). TypeScript reads these block directives as it reads the line form, so the type view now keeps them, as it already did between JSX children. A block comment that ends on the line where its statement starts stays on that line: TypeScript applies a directive to the line after the one where it ends, so it covers nothing there, as in the source. Block comments also print as written. `format_comment` rebuilt a JSDoc comment as `/** ${value.trim().slice(1)} */`, which added a space after `/**` and moved the closing `*/` of a comment over several lines onto its last line of text (#1065). * test(core): pin the type parameters of an object literal accessor `{ get g<T>() {} }` and `{ set s<T>(v: T) {} }` lost their type parameters, and `compile_to_volar_mappings` threw for them (#632). esrap 2.4 (#1085) prints them, so this only adds the regression tests. * chore: add changeset for type view printer fidelity * fix(core): keep an empty directive a directive The parentheses check tested `directive` for truthiness, so an empty directive, `'';`, printed as `('');` and ended the prologue: a `'use client'` after it was no longer a directive. A statement whose `directive` is a string, empty or not, now prints as before (#968). * fix(core): keep the lines of the comments around a TypeScript directive TypeScript applies a directive to the first line after it that is neither blank nor a line comment. The type view lost that in three ways: - A plain block comment between a directive and its code was dropped, so the directive covered the code. The comment now stays when it follows a directive, for the line form too. - Comments that share a line were split over several lines, which put a JSDoc comment between a directive and its code. They now stay on one line. - A directive on the line where its statement starts was kept on that line, but it covers the source line after it, and the printer splits or joins the lines of the statement. It is now left out, as before #866's fix. A block directive is now recognized as TypeScript does, from its last line, so `/* explanation\n@ts-expect-error */` applies too. The changeset no longer lists the array pattern fix, which #1085 describes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… (TSRX2035) (#1295) * fix(mcp): keep each compile error's severity, and pass a compile with only warnings `normalize_error` dropped `severity`, and any collected entry made `ok` false, so a warning from a compiler failed `compile-tsrx`, `analyze-tsrx` and `validate-tsrx-file` on code that compiles. Each normalized error now has `severity`, `'warning'` for a collected warning and `'error'` otherwise, including for an error the compiler threw. `ok` is false only when there is an error. The analysis gave `compile-clean` ("No target-neutral TSRX issues were found") whenever `ok` was true. It now gives it only when there are no diagnostics; a warning without a hint of its own gets the general `compiler-diagnostic` advice, as a warning. * fix(content-mapper): leave out warnings, which TypeScript 7 shows as errors The content-mapper protocol has no severity: TypeScript 7 shows each of a mapper's diagnostics as an error. A collected warning, such as one a consumer compiler reports, failed `tsc --runExternalCode` on code that compiles. Its ignore directive also hid TypeScript's own errors in the statement that holds it. A `category` field on the diagnostic, as a number or a string, makes no difference on 7.1.0-dev.20260930.4. The mapper now sends errors only. The TSRX language server and the classic `tsrx-tsc` still show warnings. * feat(core): warn about a @{ … } whose only statement is an expression `<p>@{user.name}</p>` reads like an `@` and an expression, but every `@{` opens a code block, so it runs `user.name` as a statement and renders nothing, silently. The shared analysis pass now reports TSRX2035, a warning, for a `@{ … }` with no output whose only statement is an expression with no effect: the expressions ESLint's `no-unused-expressions` reports with short circuits, ternaries and tagged templates allowed. A call, `new`, an assignment, `++`, `delete`, `void`, `await`, `yield` or `import()` may be there for its effect, so `@{log(user)}` doesn't warn. Nor does a declaration, a block with output, or a block with more statements. JSX keeps its own TSRX2010. In a child list the message says how to render an `@` and then the value; anywhere else (a function body, a value, the output of another block or a directive body) it says to end the block with output. Every target runs the pass, so React, Preact, Solid, Vue and Hono warn alike, and Ripple will once its compiler is on this core. Compiled output doesn't change. A compile that doesn't collect, such as a build, drops the warning. The code is the next one free in TSRX2xxx: open fork PRs use TSRX2027 to TSRX2034. The specification lists it, marked a warning, and `llms.txt` and the MCP docs say how to write the `@` as text. Tests cover every position and form, and each consumer of collected errors: the language server shows it as a warning, `tsrx-tsc` prints it and exits 0, MCP reports it with `ok` true, TypeScript 7 leaves it out and still shows TypeScript's errors in the block, ESLint parses and lints, and Prettier prints the block as before. Fixes #82 * fix(vscode-plugin): keep the language server's warnings when TypeScript 7 serves the workspace The extension drops the language server's TSRX diagnostics for the session once it sees the content mapper report, so a mistake doesn't show twice. The mapper leaves warnings out, as TypeScript 7 would show them as errors, so a warning such as TSRX2035 showed until the mapper reported anything, in any file, and then vanished. The extension now keeps a server diagnostic that isn't an error. * fix(core): leave a directive alone in TSRX2035, and give MCP advice for every position A `@{ … }` function body reads its leading strings as its directive prologue, so `async function action() @{ 'use server' }` warned about a directive the compiler keeps. A directive no longer warns; the same string as a child, `<p>@{'use server'}</p>`, still does. The MCP advice for TSRX2035 only explained how to render an `@` as text in a child, the fix for one of its two messages. It now covers the other positions too: use the expression itself, or give the block output. The comments and the changeset said "no effect". The check judges the outermost operation, as ESLint's `no-unused-expressions` does, so `a.b` may still run a getter; they now say the expression is there only for its value. The changeset also lists the VS Code extension. * fix(mcp): keep error advice for an unhinted error next to TSRX2035 With a TSRX2035 warning in the same file, `analyze-tsrx` gave only the warning's advice for a compile that failed on an error no hint covers (such as TSRX2013), so the failing error had no advice at all. The general `compiler-diagnostic` advice is now added as an error whenever the compile fails and no advice is an error. * docs: say where TSRX2035 doesn't show yet, and list its second message The content mapper leaves warnings out, and the language server's native backend reports no compile diagnostics, so on TypeScript 7 only VS Code shows TSRX2035. llms.txt said editors and `tsrx-tsc` show it, and the content-mapper README said the language server still does; both now name the TypeScript 7 gap, and so does the changeset. The specification's table also lists the message TSRX2035 has outside a child list. * test(language-server): expect TSRX2035's editor range as main now maps it Since main's #1085, the virtual code maps an expression statement's expression from the line break and indent before it: in `<p>@{user.nmae}</p>`, the verify-only mapping for `user.nmae` covers 14 generated characters for its 9 source ones. The plugin still finds the generated `user.nmae` for the warning, but Volar maps that range back through the longer mapping, so its start lands 5 characters late, on `nmae`. The warning, its code, severity and message are unchanged. * test(language-server): expect TSRX2035 on `user.nmae` again Round 2 changed this expectation to `nmae`, because main's mapping for `user.nmae` starts at the line break before it, and Volar mapped the warning's start through it 5 characters late. Main now also maps the statement's end, a zero-length source point at the `;` (#1096). The warning's generated range ends on that point, so Volar maps its start through the `user` token and its end through the `;`. The editor underlines `user.nmae` again, as this branch first expected, so the test goes back to that. * test(language-server): expect TSRX2035 on `nmae` again, as main maps it now Main's #1169 writes a statement's end as written in the editor output. `<p>@{user.nmae}</p>` has no `;`, so the virtual code has none, and the zero-length mapping at the `;` (#1096) that ended the warning's generated range is gone. The verify-only mapping for `user.nmae` still starts at the line break and indent before it (14 generated characters for 9 source ones). So Volar again maps the warning's start, at the generated `user`, to the source `nmae`, as it did before #1096. The warning, its code, severity and message are unchanged; only the underlined text moves back. This test has now followed main's mapping of that expression three times, and the root cause is the verify-only mapping's start. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
main now has tsrx-org#1085'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


Closes #707, closes #606, closes #272. Part of #235.
Why
@tsrx/coredeclaresesrap: ^2.3.2, so every fresh install since esrap 2.4.0 shipped (2026-09-26) already runs on 2.4. That release removed theboundaryTokensoption the editor output relied on and replaced it with atokensoption. Running the test suite on 2.4.0 with no code changes gives 59 failures. Users installing today get:<T,>async/functionkeywordsfunction f([a]: number[]) {}compiles tofunction f([a]: number[]: number[]) {}, which does not parse, on every targetWhat changes
keywordTokensis on. Type-only prints pass them to esrap'stokensoption, which replacesboundaryTokens.<T,>is written only for a generic arrow with one type parameter, where TSX needs it ([Bug]: tsrx-core: A generic arrow function with one type parameter compiles to<T>(…) => …, which isn't valid TSX #707). Every other list prints as written.defineVaporComponent. esrap's markers are now skipped forProgram.}, mapped before the generated}. The body now prints without its location, and the braces map through their tokens.<{tag}>mapped the source{tag}over the generatedTsrxDynamicname. A generated tag name is now written together with its<.TSParameterPropertyprinter. esrap 2.4 printsoverrideitself and puts parameter decorators first; the override was putting them after the modifiers ([Bug]: tsrx-core: Compiled and editor output drop parameter decorators #606).ArrayPatternprinter, which added the type annotation that esrap 2.3 left out. esrap 2.4 prints it itself, so the override printed it a second time.@tsrx/rippleand the@tsrx/core@<0.5it bundles. The published Ripple compiler still passesboundaryTokens, so its editor mappings need 2.3 until a Ripple release adoptstokens. Ripple users who install fresh are affected either way; this needs a Ripple-TS/ripple issue.Visitors.Tests
<T>(…) => …, which isn't valid TSX #707, [Bug]: tsrx-core: Compiled and editor output drop parameter decorators #606 and [Bug]: tsrx-tsc loses tagged-template type arguments, missing constraints and rejecting valid code #272 inpackages/tsrx/tests/shared/compile.js, which every target runs, plus one for array, object, defaulted and rest binding-pattern parameters with type annotations.<T>(…) => …, which isn't valid TSX #707 record fromKNOWN_PROBLEMSincontent-mapper; that test now passes.pnpm test: 10024 passed, 82 skipped. After the array-pattern fix (3a0315b), the compiler, typescript-plugin, content-mapper and prettier projects pass: 71 files, 8483 tests.pnpm typecheck,pnpm format:checkandpnpm changeset:checkare clean.Follow-up
The other issues waiting on esrap (#243, #232, #230, #216, #208, #193, #1029) and the rest of #235 (dropping the remaining manual location guesses) will be checked one by one in a separate pass.
Cursor Bugbot
<{tag} id="a">text</{tag}>, the only esrap segment over the generated closing tag starts at the generated</and maps to the source</, so nothing attaches the source{tag}toTsrxDynamic. The Volar mappings map the closing tag as a whole, and the closingtagmaps to the openingis={tag}. Same on all five targets for member-expression, nested, spaced, multi-line and commented closing tags, at 6a0380d, at fix(core): map more TypeScript errors to the .tsrx code that caused them #1086's head and at ff7a08d.🤖 Generated with Claude Code
Note
Medium Risk
Touches the core JSX/type-only print path and dependency resolution for all framework packages; incorrect token or type-parameter printing would break editor tooling and generated TS parseability.
Overview
Requires esrap 2.4 and fixes type-only codegen that broke when fresh installs picked up esrap without the removed
boundaryTokensoption.When
keywordTokensis enabled, the parser now records all lexer tokens on the AST and passes them to esrap’stokensoption for type-only prints, restoring editor mappings for keywords, punctuation, imports, interfaces, and similar output.Printing fixes layer on esrap 2.4 behavior: only generic arrows with a single type parameter emit
<T,>(TSX#707); other type parameter lists stay as written. Custom printers for parameter properties and array-pattern annotations are dropped so decorators and annotations aren’t duplicated or reordered (#606, double annotations). Interface bodies and lowered dynamic JSX tag names get targeted location tweaks so source maps stay correct;Programno longer gets esrap’s blanket start/end markers.Lockfile/workspace bumps
esrapto^2.4.0while pinning 2.3.2 for@tsrx/rippleand@tsrx/core@<0.5until Ripple adoptstokens. Regression compile tests and removal of the#707known-problem entry accompany the changes.Reviewed by Cursor Bugbot for commit 6a0380d. Bugbot is set up for automated code reviews on this repo. Configure here.