Skip to content

fix(core): collect parameter property, empty for head, and let name mistakes that TypeScript reports from its checker, and reject decorators on object literal members (#644, #645, #646) - #666

Merged
leonidaz merged 3 commits into
mainfrom
fix/core-collect-checker-errors-4
Sep 25, 2026

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #644
Closes #645
Closes #646

These follow #558, #618, and #647: mistakes that TypeScript's parser accepts and reports only from its checker. collect and loose mode (the language server, the formatter, and other editor tooling) record them in errors and keep parsing. A strict parse, which every compile uses, still throws them, with the same message and position as before. Two of the gaps #618 and #647 listed fit the same approach and are fixed here too. main is merged in, with #650 (A2's decorators on an array pattern, #609) and #657.

The bugs and the fixes

#644: a parameter property with a binding pattern (TS1187)

A parameter property may not be declared using a binding pattern. joins CHECKER_LEVEL_ERRORS. When raise returns, acorn-typescript goes on to build the TSParameterProperty with the pattern as its parameter, the node typescript-estree's shape allows. #reportOptionalPatternParameters now looks through a parameter property, so constructor(public { a }?: T) {} also records TS2463, as TypeScript does.

#645: a parameter property modifier on a function's parameter (TS2369)

acorn's parseFunctionParams reads a function's parameters with no allowModifiers, so acorn-typescript doesn't read modifiers there: public failed as a reserved word, and the name after readonly as unexpected. When collecting, parseBindingList now passes allowModifiers: false for a ) list that was given none (only acorn's parseFunctionParams does that; methods pass true). acorn-typescript then reads the modifiers and raises its UnexpectedParameterModifier error, which is TypeScript's TS2369 text and which joins CHECKER_LEVEL_ERRORS, and builds the TSParameterProperty, as for a constructor.

acorn-typescript raises that error at the first modifier's column (no caller of its own passes false, so this was unreachable). raise moves it to the first modifier, where #parseAssignableListItem started reading. A modifier on a rest parameter (#611) now also records TS2369 there, since TypeScript reports both.

This covers function declarations and expressions, declare function, overloads, and components (function App(public x) @{ … }). Arrow functions and signatures in types have their own causes; see Findings.

#646: decorators on an object literal member

The issue brief suggested TypeScript's parser accepts these and reports TS1206 from its checker. It doesn't: TypeScript 5.9.3 (and the 7.0 native preview) reports TS1136 Property assignment expected. at the @, from the parser, also after a modifier ({ async @dec m() {} } gets TS1005). typescript-estree and Babel reject them too. So it isn't a checker-level mistake. parseProperty throws acorn's Unexpected token at the @ in every mode, as acorn does in an object pattern (const { @dec a } = b;). Before, { @dec m() {} } parsed in every mode and compiled to { m() {} }, and { @dec ...s } threw a different message after the decorators. A decorated class as a property's value ({ A: @dec class {} }) is unchanged.

Gaps from #618 and #647 that are fixed here

Gaps left

Overrides

Override Issue Upstream What it does
parseBindingList (collect only) #645 sveltejs/acorn-typescript#136 (filed) Passes allowModifiers: false for a function's parameters.
raise, for UnexpectedParameterModifier #645 sveltejs/acorn-typescript#136 Moves the error from the modifier's column to the modifier.
parseProperty #646 sveltejs/acorn-typescript#135 (filed) Throws at a decorator on an object literal member.
parseForStatement (collect only) TS1123 gap none: acorn's grammar Parses an empty declaration list where TypeScript's parser does, as #618's parseVarStatement does.

sveltejs/acorn-typescript#136 also asks upstream to pass false for a method other than a constructor, as Babel does. acorn-typescript passes true for every method, so class A { m(public x) {} } parses with no error in any mode, and TypeScript's checker reports TS2369 in the editor. This PR doesn't change that. #110 (at 65376678) has the same parseAssignableListItem and parseProperty code, so it fixes neither.

The formatters

tsrx-prettier-plugin parses with collect: true. For each newly recorded mistake, I compared it with Prettier's typescript parser:

@tsrx/prettier-plugin parses strictly, so it throws for all of them, as before.

Language server

The language server compiles with loose: true. I ran every new case through compile_to_volar_mappings for all five targets, and none fails. The virtual code keeps public [a], function f(public x: number), var let, and for (const of x), so TypeScript reports its own diagnostic there too, following #558's convention. @for (const of items) gives __map_iterable(items, () => …), which parses as TSX. Without the change to get_for_of_iteration_params, the transform used the declaration itself as the parameter ((const ;) =>).

Verification

Parse comparison with main (d1785a10): 17,493 distinct sources:

  • the 70 tracked .tsrx files;
  • the 2,040 inputs and 2,040 outputs of the Prettier snapshot cases (readSnapshotEntries/readFormatCase);
  • the string and template literals of the test files.

Each was parsed strict, with { collect: true, errors: [], comments: [], preserveParens: true }, and with { loose: true }, before and after. That's 52,479 parses on each side, in four processes, each parse killed after 15 s, with no hangs. I compared every AST (without metadata), comment list, and error list, or the thrown message and position.

37 sources changed, and all of them are this PR's new test strings. No .tsrx file, Prettier input or output, or existing test string changed, and no source that parsed before has a different AST.

Tests.

  • parser.test.js, mistakes that TypeScript reports only from its checker: 19 new cases, each checking the collected messages and the source text at their positions, the node (against a valid equivalent such as constructor(public x: number) for function f(public x: number), or an expected shape), and the unchanged strict throw. There are also new sources that record nothing (parameters named readonly and override, and declarators named of) and sources that still throw (for (const of []), for (const of x.y), and readonly before a line break).
  • upstream-parser-workarounds.test.js:
  • tsrx-prettier-plugin/tests/tsrx.test.js: the refused for heads, the object literal decorator's error position, and the cases that format unchanged.
  • tests/shared/compile.js: @for (const of items) in loose mode gives a loop with no parameter, for all six target configurations.
  • 6 of the new or updated test blocks fail with main's plugin.js, and the @for compile test fails with main's ast-builders.js.

Local runs. These pass:

  • vitest tsrx-utils, tsrx-analyze, prettier-plugin, tsrx-prettier-plugin, tsrx-react, tsrx-preact, tsrx-solid, tsrx-vue, and tsrx-hono (--maxWorkers=4), after merging main. prettier-known-failures.json is unchanged.
  • pnpm typecheck. tsrx-tsc isn't linked after --ignore-scripts, so I built @tsrx/typescript-plugin and ran vite-plugin-hono's typecheck:tests through packages/typescript-plugin/dist/tsc.js.
  • pnpm format:check and pnpm changeset:check.

A patch changeset for @tsrx/core is included. tsrx-prettier-plugin is private.

Findings

Filed upstream:

Filed here, each with a separate cause and not fixed in this PR:

Same cause as the issues here, and not covered:

🤖 Generated with Claude Code


Note

Medium Risk
Touches core parser error collection and for-loop/@for codegen paths used by the language server and formatter; behavior changes for previously silent object-literal decorators (now hard errors).

Overview
Extends collect/loose parsing so TypeScript checker-only mistakes are recorded in errors while parsing continues (strict compile still throws), aligning the language server, formatter, and editor tooling with TypeScript’s behavior.

Parser (plugin.js): Adds checker-level handling for parameter properties with binding patterns (TS1187), parameter-property modifiers on ordinary function parameters (TS2369, via parseBindingList / error repositioning), empty for declaration heads including @for (const of items) (TS1123, shared #parseEmptyDeclarationList), and extra let-as-name diagnostics (deduped to one per site). Object literal member decorators ({ @dec m() {} }) now fail at @ in all modes instead of parsing and dropping decorators.

Transform: @for over an empty declaration list exposes no loop parameter (get_for_of_iteration_params).

Prettier plugin: Documents/refuses empty for heads via existing empty-declaration rejection; new tests for object-literal decorator errors and cases that still format when Prettier’s TS parser would reject the tree.

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

leonidaz and others added 3 commits September 25, 2026 17:29
…me mistakes, and reject decorators on object literal members (#644, #645, #646)

In collect and loose mode the parser records these mistakes, which
TypeScript's parser accepts and reports only from its checker, and keeps
parsing; a strict parse still throws them:

- A parameter property with a binding pattern (#644, TS1187): the message
  joins CHECKER_LEVEL_ERRORS, and acorn-typescript builds the
  TSParameterProperty with the pattern. An optional one also gets TS2463.
- A parameter property modifier on a function's parameter (#645, TS2369):
  when collecting, parseBindingList passes `allowModifiers: false` for a
  function's parameters, so acorn-typescript reads the modifiers and raises
  TS2369, which `raise` records at the first modifier
  (UPSTREAM(sveltejs/acorn-typescript#136)).
- A `for` head's declaration list with no declarator (TS1123):
  `for (var; ;)`, `for (const of x)`, `for (const in x)`, also in `@for`,
  where TypeScript's parser ends the list. The template transform gives such
  a loop no parameter.
- `let` as a binding name or an assignment target (TS1212-TS1214, TS2480):
  acorn's later errors for the same `let` join CHECKER_LEVEL_ERRORS, and only
  the first is recorded.

Decorators on a member of an object literal are a syntax error at the `@` in
every mode, as in TypeScript's parser (TS1136); acorn-typescript put them on
the property and the output left them out (#646,
UPSTREAM(sveltejs/acorn-typescript#135)).

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