Skip to content

refactor(core): read generic arrows by TypeScript's TSX rule (#183) - #1124

Merged
jonkwheeler merged 70 commits into
tsrx-org:mainfrom
jonkwheeler:refactor/generic-arrow-tsx-rule
Nov 12, 2026
Merged

jonkwheeler merged 70 commits into
tsrx-org:mainfrom
jonkwheeler:refactor/generic-arrow-tsx-rule

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1085; review the commits after ff7a08d; merge after #1085.

Summary

TSRX now decides whether < starts a generic arrow function or a tag the way TypeScript does in a .tsx file, as decided in #183 (option 2, exact TSX parity). That rule applies to files with JSX: .tsrx, .tsx, .jsx, and .js. A .ts, .mts, or .cts file has no JSX, as in TypeScript.

  • Before: the tokenizer scanned the type parameters, the value parameters, and the return type to guess. It accepted the bare <T>(x) => x and async <T>(x) => x, and it misread shapes TypeScript reads fine: a ) in a parameter's comment, regular expression, or nested template literal hid a constrained arrow ([Bug]: Generic arrows fail when parameter comments or regex literals contain parentheses #175), and an element whose text starts like an arrow, <b>(i) => i</b> or <script>(i) => i</script>, failed 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).
  • After: where an expression starts, only TypeScript's four-token rule (isParenthesizedArrowFunctionExpression) applies. <[const] T followed by , or =, or by extends and anything but =, >, or /, is a generic arrow. Everything else is a tag, including <T>(x) => x.
    • The rule never runs between JSX children, or where a template's render node or child starts: a @{ … } body, a directive body or @case arm, a child after a directive's }. Those positions are tags, as before, so <Foo extends bar /> keeps parsing there.
    • A < read as a tag is read only as an element. acorn-typescript's retry as a generic arrow function, which let a strict parse accept <Box fn={<T>(x: T) => x} />, no longer runs, so strict and collecting parses agree.
  • Files without JSX (.ts, .mts, .cts): a < where an expression starts is a generic arrow function's type parameters when an arrow function follows, and otherwise a type assertion's type (<T>x), never a tag. That matches tsc.
  • Migration: <T>(x) => x becomes <T,>(x) => x (or <T extends …>, <T = …>), and async <T>(x) => x becomes async <T,>(x) => x. The old forms get targeted errors at the <:
    • TSRX1001 Unclosed tag '<T>'. Expected '</T>' before end of template. To write a generic arrow function, add a trailing comma, as in \<T,>() => ...`.It covers, nested arrows, and arrow bodies like { return x; }, but not lowercase HTML tags (
      (hello)`).
    • TS7060, with the same fix, for async <T>.
    • Strict parses throw these errors. Collect and loose parses record them, so the editor shows them too.
  • scan_type_from, scan_balanced_from, skip_regex_from, skip_string_from, REGEX_PRECEDING_KEYWORDS, and the character codes only they used are gone (a separate commit).
  • Docs: llms.txt and the specification (§4.2, and TSRX1001's second message in appendix B) say a generic arrow needs <T,>, a constraint, or a default.
  • Changeset: minor for @tsrx/core and the five target compilers, since they stop accepting the bare forms; its body is the migration note. @tsrx/prettier-plugin takes core as workspace:* and gets the internal-dependency patch bump, as in feat(core): give an @case or @default arm its { … } body as a BlockStatement #879, feat(core): give an enum's members in a TSEnumBody #877 and feat(core): give a type parameter's name as an Identifier with its position #874.

reportReservedArrowTypeParam is untouched (cleanup waits on #169).

Commits

  1. b48148146 replaces the lookahead with the TSX rule.
  2. 9c75108c9 deletes the scanners.
  3. 0c8dbea0d adds the trailing-comma diagnostic.
  4. 9097a6ae8 adds the docs and the changeset.
  5. Follow-ups from review:
    • e80c2933d reads template render nodes and children as tags.
    • 648fa9892 stops the generic-arrow retry after a failed tag.
    • 62b018ea2 handles async <T> (TS7060), enum as a reserved word, and drops the hint on lowercase tags.
    • 4cdff0002 scopes the changeset.
    • 851437390 reads .ts, .mts, and .cts files without JSX.
    • 325f735b3 notes that in the changeset.
    • aca5f0ccd keeps <=/<</<<= whole in those files, reads a type assertion on a parenthesized function, and records TS7059 once per assertion.

Notes for review

  • Test sites the issue named:

    • parser.test.js and the shared compile test, which every target runs, now use <T,>. The compile test checks that <T,>(x: T) => x and <const T,> keep their comma on React, Preact, Solid, Vue, and Hono, and that the output reparses as TSX.
    • In source-mappings.js the <Value,> case already existed, so the bare-form test there now asserts the loose-mode diagnostic.
    • The prettier-plugin src/index.test.js round trips were deleted with the old formatter in feat(prettier): switch to the new formatter architecture #944, and no current prettier test or conformance fixture uses the bare form.
  • Two test changes:

    • Two parser tests pinned the old lookahead firing between children (<b><T,>() => 1). Their error now lands on the ,, where TypeScript reports it.
    • A generic arrow as a bare statement at the start of a one-line template body (@{ <T,>(x) => x }, which does nothing) is now read as the render node. That is how base already read it at the start of a line.
  • Content mapper:

  • Probes from review (340 template and position cases):

    • Differences from base went from 116 to 68: 32 are elements base rejected (<b>(i) => i</b>), and 36 are extends-attribute tags at a plain expression start, where TypeScript also reads a generic arrow.
    • Template positions now differ from base only by those improvements. 170 more probes over 17 other template positions changed from 102 regressions to 0.
    • The TSX parity corpus is unchanged except where the result now matches TypeScript.
  • With fix(core): throw in a strict parse what a collecting parse records #1131 merged in (a local throwaway merge of fork/fix/parity-strict-collect at 5c8dbe3, not pushed):

Verification

Related

Fixes #183
Related: #734 (closed as duplicate), #164, #175, #169

🤖 Generated with Claude Code


Note

High Risk
Core tokenizer/parser behavior changes with a breaking migration for common generic-arrow syntax across all JSX targets and .ts/.mts/.cts parsing paths.

Overview
Breaking: In .tsrx and other JSX-capable files, a leading < only starts a generic arrow when TypeScript’s TSX rule says so—<T,>, a constraint, or a default—not bare <T>(x) => x or async <T>(x) => x. Those forms are treated as tags; TSRX1001 (with a trailing-comma hint) and TS7060 replace silent mis-parses. Template render nodes and children still always parse as tags (<Foo extends bar />, etc.), and failed tag parses no longer retry as generic arrows.

Non-JSX .ts / .mts / .cts now follow tsc: < is a generic arrow or <T>x type assertion (not JSX); TS7059 applies in .mts/.cts. Old lookahead scanners for generic arrows were removed in favor of looks_like_generic_arrow.

Diagnostics: TS_SYNTAX_ERROR_CODES, checker-vs-syntax classification, and stricter error order/parity with TypeScript (e.g. declare in blocks, duplicate signature parameters, generic async arrow parameter errors, syntax errors suppressing deferred checker errors).

Docs/changeset describe migration to <T,>. Extensive parser, compile, content-mapper, and platform-loader tests cover the new behavior.

Reviewed by Cursor Bugbot for commit ba415d5. Bugbot is set up for automated code reviews on this repo. Configure here.

jonkwheeler and others added 7 commits October 26, 2026 11:18
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]>
- `declare` directly in an ambient namespace or module is TS1038, also
  when it's the only modifier or after `export`.
- Modifiers before a class `static` block are TS1184 at the first one,
  and decorators there TS1206, recorded when collecting; the block keeps
  no modifiers. The formatter prints `static {}`, as Prettier does.
- A parameter property on a method, accessor, object literal method or a
  constructor without a body is TS2369.
- `abstract` before a declaration other than a class in a block is TS1184
  at the declaration's first modifier; the formatter still refuses it.
- TS1029 and TS1243 from acorn-typescript are thrown at the modifier in a
  strict parse too, not at its column on the first line.

Fixes tsrx-org#885, tsrx-org#886, tsrx-org#783, tsrx-org#735. Part of tsrx-org#961.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A missing `;` is TS1005 `';' expected.`, `',' expected.` after a
  declarator, and TS1434 or TS1435 after a lone name, as TypeScript's
  `parseErrorForMissingSemicolonAfter` reports it.
- A word reserved in strict mode used as a name is TS1214, or TS1213 in a
  class, recorded when collecting for every such word; a `let` or `const`
  declaration named `let` also reports TS2480.
- An item after a rest element is TS1014 at a rest parameter, or TS2462 at
  a destructuring pattern's rest element; TS1013 stays for a trailing comma.
- A call of `import.<name>` is TS18061.
- Type arguments after `?.` without a call report TS1358 or TS1005 at the
  token after them, not `Unexpected token (1:NaN)`.

Fixes tsrx-org#966, tsrx-org#962, tsrx-org#956, tsrx-org#884, tsrx-org#1053, tsrx-org#786.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g#183)

Replace the generic-arrow lookahead's scan of the type parameters, the
value parameters, and the return type with the four-token rule of
TypeScript's `isParenthesizedArrowFunctionExpression` for `.tsx` files:
`<[const] T` followed by `,` or `=`, or by `extends` and anything but
`=`, `>`, or `/`, starts a generic arrow function. Everything else is a
tag, including `<T>(x) => x`, as in TSX. As in TypeScript, the rule
applies only where an expression can start, never between JSX children.

Nothing after the type parameter is read, so a constrained arrow whose
parameters hold a `)` in a comment, a regular expression, or a nested
template literal parses (tsrx-org#164, tsrx-org#175), and `<b>(i) => i</b>` and
`<script>(i) => i</script>` are elements again (tsrx-org#734).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The four-token rule reads no type, parameter list, string, or regular
expression, so `scan_type_from`, `scan_balanced_from`, `skip_regex_from`,
`skip_string_from`, `REGEX_PRECEDING_KEYWORDS`, and the character codes
only they used go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as a tag

An unclosed tag with a single name and no attributes (or `<const T>`)
followed by `(` is almost always a generic arrow function written for a
`.ts` file. Report it at the tag as TSRX1001 with the fix:
"To write a generic arrow function, add a trailing comma, as in
`<T,>() => ...`." It throws in a strict parse and is collected in
collect and loose mode, so the editor shows it too. When an arrow body
such as `{ return x; }` fails as markup before the tag is found
unclosed, and no closing tag follows, the parse fails with it instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the TSX rule to llms.txt and the specification, and the changeset
with the migration note: `<T>(x) => x` becomes `<T,>(x) => x`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/tsrx/src/plugin.js Resolved
jonkwheeler and others added 7 commits October 26, 2026 17:08
A strict parse now reports the checker errors a collecting parse records,
at the same position: TS1354 for `readonly` on another type, TS1308,
TS1103 and TS2852 for `await` in a namespace, TS1123 for an empty
declaration list, TS1155 for `const` without an initializer, TS2369 and
TS1317 for parameter properties on a function or rest parameter.

`let` in a `for` head always starts a declaration list (TS1134 or TS1123),
as in TypeScript's parser. A collecting parse records a private name that
no class declares (TS1111). TS7060 is no longer reported in a `.ts` file,
and a strict parse throws it in a `.mts` or `.cts` file.

Fixes tsrx-org#883, tsrx-org#880. Part of tsrx-org#963.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t bodies

- Exports TypeScript's binder declares twice report TS2528 (default
  exports) or TS2300 (export specifiers, `export * as`), at each.
- `import type a, { b }` reports TS1363 at `type`.
- `import type A = B.C` reports TS1392 at the declaration, recorded when
  collecting.
- A function body in an ambient context reports TS1183 at the body,
  recorded when collecting.

The formatter refuses TS1363, TS1392 and TS1183, as Prettier does.

Fixes tsrx-org#882, tsrx-org#881, tsrx-org#785, tsrx-org#784.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the generic-arrow rule says

The four-token rule ran wherever the tokenizer met a `<`, including where
a template expects a tag, so valid markup with an `extends` attribute
(`<Foo extends bar />`, `<div extends className="a">`) read as a
generic arrow function in a `@{ … }` body, a directive body or `@case`
arm, and as an element's child after a directive's `}`, and failed.

A `<` that starts a render node or a child is now re-read as a tag start
without the rule (`#rereadAsTagStart`), a one-line body's render node is
found after a `{` or `}` as after a `;`, and in a template's setup code
the rule doesn't run after an operand, where the next line's `<` starts
the render node.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unction

When the element at a `jsxTagStart` failed, acorn-typescript's
`parseMaybeAssign` tried a generic arrow function instead. A strict parse
throws on the unclosed `<T>`, so the retry accepted the bare form there
(`<Box fn={<T>(x: T) => x} />` compiled on every target with `<T,>`),
while a collecting parse kept the element and reported TSRX1001. The two
modes disagreed and the removed form still compiled.

A `<` the TSX rule reads as a tag is now read only as an element, with
acorn's own `parseMaybeAssign`, so both modes report the trailing-comma
hint at the tag, nested too. The rule now also looks past a comment after
the `<` (`</* c */ T,>`), which the retry used to cover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… before `(`

- `async <T>(x) => x` compiled, but TypeScript reads it in a `.tsx` file as
  a call (TS1005). It now reports TS7060 with the trailing-comma fix: it
  throws when parsing strictly and is collected otherwise. `async <T,>`
  and `async <T extends U>` are unchanged.
- `enum` is reserved in TypeScript, so `<enum extends foo>ok</enum>` is
  an element, not a generic arrow function.
- The trailing-comma hint no longer goes on an HTML element's lowercase
  tag (`<div>(hello);`) or on a `<const>` without a name.

The content mapper's TS7060 example is `async <T>() => 1` again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sync migration

`@tsrx/prettier-plugin` takes `@tsrx/core` as `workspace:*`, so the
internal-dependency patch bump already releases it. A `minor` would pull
its fixed group (the ESLint packages, the language server, and the
TypeScript plugin) to minor as well. The migration note now covers
`async <T>(x) => x` too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rejects

- `const` on a type parameter of a function type, constructor type or
  signature parses, as TypeScript reads it.
- `asserts` before a line break is a type, not a predicate's modifier.
- An element superclass without parentheses reports TS1109 at its `<`.

Fixes tsrx-org#731, tsrx-org#682. Part of tsrx-org#745.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 27, 2026 11:47
@jonkwheeler
jonkwheeler marked this pull request as draft October 27, 2026 12:21
jonkwheeler and others added 9 commits October 27, 2026 08:29
…to tsc

- A private method without a body (`declare class A { #m(): void; }`)
  declares its name, so neither mode reports TS1111 for it.
- In a `.mts` or `.cts` file, TS7060 is reported for a default type
  parameter and an async arrow function too, as TypeScript does.
- TS1354 spans `readonly`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The default `const` reader reached acorn-typescript's
`parseClassFunctionParams`, which reads type parameters after a method's
`(`, so `m(<const T>x) {}` parsed. Read it only in `tsFillSignature`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cript does

The TSX rule, its trailing-comma error, and the generic-arrow retry fix
applied to every file, so a `.ts` file read `<T>() => 1` as an unclosed
`<T>` tag and threw TSRX1001. TypeScript reads such a file without JSX.
`<T>() => 1` is a generic arrow function there, `<T>x` is a type
assertion, and `async <T>(x) => x` is accepted.

In a `.ts`, `.mts`, or `.cts` file, a `<` where an expression starts now
reads as a generic arrow function's type parameters when an arrow function
follows them, and as a type assertion's type otherwise
(`#parseArrowOrTypeAssertion`). A `.mts` or `.cts` file reports TS7059 for
`<T>x`, as TypeScript does, through the new
`TS_ERRORS.RESERVED_TYPE_ASSERTION`: a strict parse throws it, and a
collecting parse records it.

TS7060 for a generic arrow function is still `reportReservedArrowTypeParam`'s,
which tsrx-org#1131 makes match TypeScript (tsrx-org#880), so the new tests leave it out.
Every other file keeps JSX: `.tsrx`, `.tsx`, `.jsx`, and `.js`.

The comment tests that hold elements now read their sources as `.tsx`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rule applies to a `.tsrx` file and any other file with JSX. A `.ts`,
`.mts`, or `.cts` file has no JSX, so it keeps `<T>(x) => x` as a generic
arrow function and reads `<T>x` as a type assertion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… precedence

- When `abstract` is left out of the tree after a `declare` whose error
  TypeScript reports first (TS1184 in a block, TS1038 in an ambient
  namespace), a collecting parse records `abstract`'s own error too, so
  the formatter refuses the code instead of printing it without
  `abstract`.
- Between `abstract` and `declare` in an ambient namespace, the first
  modifier reports its error (TS1242 or TS1038), as TypeScript does.
- The body of an `if`, a loop or a label is not a statement list, so
  `abstract` there is TS1184.
- `static constructor() {}` is TS1089 at `static` and takes parameter
  properties; a rest parameter property on a method reports TS2369 too.
- The formatter prints `abstract static {}` as `static {}`, as Prettier
  does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The JSX-file behaviour of a generic arrow function belongs to tsrx-org#183
(PR tsrx-org#1124), which tests it itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… x)` as an assertion

- In a `.ts`, `.mts`, `.cts`, or `.d.ts` file every `<` was read as a lone
  `<` token, so `a <= b`, `1 << 2`, and `a <<= 1` failed with TS1012. That
  broke Turbopack's platform loader, which parses every TypeScript module.
  A lone `<` is now taken only where an expression starts, and never from
  `<=`, `<<`, or `<<=`. Elsewhere such a file reads `<` as JavaScript
  does, never as a tag.
- `<Handler>((e) => e.x)` read as a generic arrow function with type
  parameter `Handler`, because acorn-typescript doesn't see the
  parentheses. It is a type assertion, as in TypeScript and as the
  `preserveParens` parse already read it: a generic arrow function's
  parameters must start at the `(` after its type parameters.
- A collecting parse of `<T>(<U>y)` in a `.mts` or `.cts` file recorded
  the inner TS7059 twice. The failed generic-arrow attempt's errors are
  now dropped with it.

New tests:
- `replacePlatformFlags` on `.ts`, `.mts`, and `.cts` utility modules
  containing these operators, generics, and type assertions.
- A parse of every `.ts`, `.mts`, and `.cts` source in the repository
  (declaration files excepted).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 27, 2026 13:08
- TS2462 in an arrow function's parameters is at the rest element's
  target, as in a binding pattern, and a collecting parse records it for
  each rest element that isn't last, not only the first.
- A function named `let` reports TS1214 only, without TS2480.
- A strict mode reserved word in an ambient context, or as the name an
  export specifier exports, is no error, as in TypeScript.
- `let`, `const` or `using` after `if (...)` or a loop head is TS1156,
  which collecting parses record.
- `in` ends a declaration list (`';' expected.`), a modifier that starts
  no statement is TS1128, `new import` is TS1109, `a?.<T>[0]` is TS1003
  at the `<`, `import.<name>()` names the property without escapes, and
  `constructor` is a keyword suggestion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler and others added 4 commits November 10, 2026 21:25
…ance

Brings in tsrx-org#1137's head 1b0a8e6, which carries the
fixes for Cursor Bugbot's findings from the 2026-11-10 sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…st-error

Brings in tsrx-org#1140's head 565b6bb, which carries the
fixes for Cursor Bugbot's findings from the 2026-11-10 sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…irst-error-followups

Brings in tsrx-org#1192's head 3599918, which carries the
fixes for Cursor Bugbot's findings from the 2026-11-10 sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…y-declare-block-signature-duplicates

Brings in tsrx-org#1235's head c155edb, which carries the
fixes for Cursor Bugbot's findings from the 2026-11-10 sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 12, 2026
…1131)

* fix(core): throw in a strict parse what a collecting parse records

A strict parse now reports the checker errors a collecting parse records,
at the same position: TS1354 for `readonly` on another type, TS1308,
TS1103 and TS2852 for `await` in a namespace, TS1123 for an empty
declaration list, TS1155 for `const` without an initializer, TS2369 and
TS1317 for parameter properties on a function or rest parameter.

`let` in a `for` head always starts a declaration list (TS1134 or TS1123),
as in TypeScript's parser. A collecting parse records a private name that
no class declares (TS1111). TS7060 is no longer reported in a `.ts` file,
and a strict parse throws it in a `.mts` or `.cts` file.

Fixes #883, #880. Part of #963.

* fix(core): declare bodiless private methods; match TS7060 and TS1354 to tsc

- A private method without a body (`declare class A { #m(): void; }`)
  declares its name, so neither mode reports TS1111 for it.
- In a `.mts` or `.cts` file, TS7060 is reported for a default type
  parameter and an async arrow function too, as TypeScript does.
- TS1354 spans `readonly`.

* test(core): narrow the #880 test to .ts, .mts and .cts files

The JSX-file behaviour of a generic arrow function belongs to #183
(PR #1124), which tests it itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler and others added 5 commits November 12, 2026 10:06
In error-examples.js, WITHOUT_EXAMPLE keeps this PR's RESERVED_TYPE_ASSERTION entry and main's LET_DECLARATION_NAME in place of the LET_BINDING entry main removed, and KNOWN_PROBLEMS keeps this PR's UNCLOSED_TAG_GENERIC_ARROW record without the two CODE_BLOCK records main dropped. platform.test.js keeps this PR's TypeScript-module test and main's TSX and TypeScript platform tests from tsrx-org#1087.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
KNOWN_PROBLEMS in error-examples.js conflicted because main (tsrx-org#1273) dropped the UNCLOSED_TAG and MISMATCHED_CLOSING_TAG records just above this PR's UNCLOSED_TAG_GENERIC_ARROW record; main's removals and this PR's record are both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…roblem

With tsrx-org#1273 on main, a loose compile closes a recovered tag in the editor's code, so TypeScript no longer reports TS17008 over the TSRX1001 of `export const f = <T>(x: T) => x;`. error-examples.test.js reports the record as fixed and asks for its removal. TypeScript 7 still shows one error for this example: TS18080 at the start of the file, for problems in the virtual code with no location in the source. `T` names no value, so the generated `<T>…</T>` gets TS2304 "Cannot find name 'T'" at both tag names, and neither maps back. That position isn't one this test classifies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
parseTemplateBody conflicted because main (tsrx-org#1193) now reads a template's children in a loop. This PR's re-read of a child's `<` as a tag start goes into the loop body at the same place, before the expression-container branch, indented one level deeper; the rest of the function is main's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
parseBindingList conflicted twice: this PR adds the held-error list around the binding list's read, and main (tsrx-org#1244) counts the `[` of an array pattern around it. The `#openBrackets` increment now sits just before the `try`, after this PR's setup, and its decrement goes into the `finally` after this PR's restores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7bb1d77. Configure here.

Comment thread packages/tsrx/src/plugin.js Resolved
jonkwheeler and others added 13 commits November 12, 2026 13:14
…rrow

In a `.mts` or `.cts` file, a strict parse threw TS7059 from inside `#parseArrowOrTypeAssertion`'s attempt to read a `<` as a generic arrow function's type parameters. `tryParse` takes that SyntaxError to mean "not an arrow function", so a type assertion in the parameters ended the attempt. The `<` was then read as a type assertion's and failed at its `,`: `const f = <T,>(x = <number>y) => x;` threw TS1012 at that `,` instead of TS7059 at the inner `<number>`. The other way round, the attempt's TS7060 was thrown or recorded even when it failed, so the type assertion `<Handler>((e) => e.x)` gave TS7060 at `Handler` (and a collecting parse recorded it beside TS7059).

While the attempt runs, a strict parse now holds both errors. They go through acorn-typescript's undo log, so an attempt that fails drops them, and once the attempt reads a generic arrow function the first by position is thrown (in an enclosing attempt, once that one is read too). A collecting parse's TS7060 goes through the undo log as its TS7059 already did. Found by Cursor Bugbot on tsrx-org#1124.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
In parseElement's report for an element left open, this PR's type_parameter branch stays, and its null case now passes main's `[tag.start, tag.end]` range so the error lands on the tag's name (tsrx-org#1298). parser.test.js keeps this PR's title and comment for the `<b><T,>() => 1` test: its expected position (15) is the same as main's after tsrx-org#1271, but under this PR's TSX rule the `<` is never read as a type parameter list there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
plugin.js conflicted where this PR and main each added module-level tables before block_scoped_redeclarations: this PR's held-error sets and maps, and main's default_class_names. Both are kept, this PR's first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…rg#1214 order test

Since tsrx-org#1298 on main, a collecting parse records an unclosed tag's TSRX1001 at the tag's name, while a strict parse still throws it at the end of its template. This PR's order test checked both at one position, so `class A { public static { <div> } }` failed on the collected error, now at `div` instead of `} }`. Each row can now give the collected error's position separately. The order the test is about still holds: the syntax error comes before the static block's TS1184 in both parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…f its list

A parameter property whose parameter is a binding pattern skipped the held path on a method, so that its TS1187 would come first. Its TS2369 was then left to `parseMethod`'s loop after the body. A collecting parse of `class A { m(public [a]) { let let = 1; } }` recorded TS1213 and TS2480 from the body before TS2369, the order this PR is meant to reverse. A strict parse of `m(x, public [x])` threw TS1187 at the pattern before the earlier duplicate name.

The pattern now takes the held path too. TS1187 is raised as the parameter is read, so it still comes first at that place, then TS2369, then the errors in the body and the duplicate names after it, as tsc orders them. Found by Cursor Bugbot on tsrx-org#1235.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…rrow-tsx-rule

tsrx-org#1235 lands first, so this branch takes its held-error mechanism. That replaces the separate list this PR's Bugbot fix held TS7059 and TS7060 in (`#holdArrowError`). `#parseArrowOrTypeAssertion` now holds checker errors with `#setHeld` while it tries a `<` as a generic arrow function's, and releases them through `#releaseErrors` once the attempt reads one. A failed attempt drops them through the undo log. `#parseTypeAssertion` records TS7059 as a held checker error while errors are held. `#reportReservedArrowTypeParameters` is tsrx-org#1235's, whose release then goes into the attempt's list instead of throwing inside it. This also keeps a TS1047 in the arrow's parameters (`<T>(...a?: number[]) => a` in `.mts`) from ending the attempt. The GenericArrowFunction typedef's doc describes both PRs' fields.

One tsrx-org#1235 expectation changes with this PR's `.mts` reading. For `const f = <T>(x = <U>(u: U) => u, y = ) => x;` a collecting parse now throws at the `)` after `y =`, where TypeScript reports its error, not at `<T>`, because a `.mts` file has no JSX.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
The parser's constructor conflicted: this PR's `#jsxFile`, set from the filename, and main's `#textComments` option are set at the same place. Both are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Main now has tsrx-org#1235's squash, which matches the tsrx-org#1235 this branch had merged in. The conflicts are where both sides added the same tsrx-org#1235 lines: this branch keeps its own versions. Those are the GenericArrowFunction doc that also covers this PR's `arrowRead`, and the `.mts` expectation in tsrx-org#1235's held-errors test, which throws at the `)` after `y =` because this PR reads `.mts` without JSX. shared/source-mappings.js keeps main's `@tsrx/core` import with DIAGNOSTIC_CODES (tsrx-org#1280) and this PR's TSRX_ERRORS import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
plugin.js conflicted in four places. Both diagnostics.js import lists are kept, with this PR's TS_SYNTAX_ERROR_CODES and main's extract_identifiers. Both module-level tables are kept: this PR's generic_arrow_parameter_errors and main's default_class_names (tsrx-org#1234). In parseBindingList, this PR's `recorded` list and main's `#openBrackets` count (tsrx-org#1244) both stay. In #parseAssignableListItem, `list` is read once at the top as this PR does, and the pattern check takes main's version from tsrx-org#1235's review fix, which holds a method's pattern parameter property with the rest of its list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…eric-arrow-tsx-rule

tsrx-org#1269 lands first. Merged against the main both branches share (3cecb2c), the two merge without a textual conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
…le without JSX

With tsrx-org#1269 merged, its test "throws first the error a collecting parse records first (tsrx-org#1264)" failed for `const f = <T>(x: T) => { const z; return x +; };` in `.mts`. tsrx-org#1269 expects a strict parse to throw TS1155 at `z`, and a collecting one to record TS1155 and then throw the body's syntax error. This PR tries such a `<` as a generic arrow function in `#parseArrowOrTypeAssertion`. The body's syntax error ended the attempt, which dropped the held TS1155 with it. The `<` was then read as a type assertion, and the arrow function's syntax error was thrown alone.

Once the `=>` of the generic arrow function it tries is read, TypeScript reads an arrow function whatever follows. So when the attempt fails after that point, `#parseArrowOrTypeAssertion` now reads the arrow function again, not as an attempt. The error comes the way tsrx-org#1269 reports it outside an attempt: the checker errors held before it are kept. An attempt that fails before its `=>` still falls back to a type assertion, as `<Handler>((e) => e.x)` and `<T>(x = <U>(u: U) => u, y = ) => x` need.

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
@jonkwheeler
jonkwheeler merged commit d18720d into tsrx-org:main Nov 12, 2026
8 checks passed
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
Merged against merge/1276 (6e362da), which carries origin/main d18720d with tsrx-org#1124 and tsrx-org#1269, on top of this PR's tsrx-org#1269 base c7add54. WITHOUT_EXAMPLE in error-examples.js drops the five tsrx-org#964 records this PR settles and keeps tsrx-org#1124's RESERVED_TYPE_ASSERTION record. In parseTemplateBody, main's version (tsrx-org#1193's loop with tsrx-org#1124's tag re-read) stays, with this PR's comment that `jsx_readToken()` would report an unclosed element.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the generic-arrow lookahead scanners with TypeScript's TSX rule

1 participant