Skip to content

fix(core): collect parameter property modifiers on signatures and arrow functions, and report an arrow function's optional parameters and a parameter property's pattern with a default (#663, #664, #665) - #701

Merged
leonidaz merged 4 commits into
mainfrom
fix/core-parameter-mistakes
Sep 25, 2026

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #663
Closes #664
Closes #665

These follow #647 and #666: parameter 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. Three of them used to compile and are now reported in every mode, which is the user's decision (see Behavior change).

The bugs and the fixes

#664: a parameter property modifier on a signature's parameter (TS2369)

acorn-typescript reads the parameters of a function or constructor type, and of a method, call, or construct signature, with tsParseBindingListForSignature. That calls acorn's parseBindingList directly, past #666's override, with no allowModifiers. When collecting, tsParseBindingListForSignature now reads them through parseBindingList, which passes allowModifiers: false. acorn-typescript then reads the modifiers and raises TS2369, raise records it at the first modifier, and the parameter is a TSParameterProperty, as for a function's parameter. acorn-typescript's check of each parameter's type now looks through the parameter property.

A function type needed one more change. The lookahead that tells (public x: number) => void from a parenthesized type (tsSkipParameterStart) didn't skip modifiers, so it read (public x as a parenthesized type and failed at x. TypeScript's skipParameterStart skips them, and when collecting, so does this one. (readonly [string]) and (readonly string[]) stay parenthesized types, since no => follows them.

Because the list now goes through parseBindingList, a parameter after a rest parameter in a signature (type F = (...a: number[], b: string) => void) is recorded when collecting (TS1014), as for a function's, instead of throwing.

#663: a parameter property modifier on an arrow function's parameter (TS2369)

acorn reads an arrow function's parameters as the items of a parenthesized expression, or as the arguments of async (…), and makes them patterns once => follows. When collecting, the parser now reads parameter property modifiers before such an item where TypeScript's parser does:

  • #parseArrowParameterList marks a list that can be an arrow function's parameters: a parenthesized expression that can be an arrow function (parseParenAndDistinguishExpression), or the arguments after async (parseSubscript). parseMaybeAssign counts how deep the parser is in an item, so only the list's items are candidates, not the expressions inside them. parseFunctionBody sets the list aside for a body.
  • At an item that starts with a modifier, #startsArrowParameterProperty looks ahead. It reads the rest of the list as parameters (parseBindingList with allowModifiers: false) and checks that => follows. At the list's first item it also requires what TypeScript's isParenthesizedArrowFunctionExpressionWorker requires, a name other than as after the modifier. So (public [a]) => a, (public ...r) => r, and (readonly as) => 1, which TypeScript's parser rejects, still throw, while (a, public [b]) => a is read. After type parameters (<T,>(public [a]: T) => a), TypeScript reads parameters whatever the first item is; tsParseTypeParameters records where they end.
  • If the lookahead succeeds, #parseArrowParameterProperty reads the modifiers, records TS2369 at the first one, reads the item as before, records TS1187 if it's a pattern, and builds the TSParameterProperty that a function's parameter gets. toAssignable makes its parameter a pattern along with the other parameters. Before a rest element, it records TS1317 and TS2369 and keeps the rest element without the modifiers, as fix(core): collect decorator, modifier, and rest parameter mistakes that TypeScript reports from its checker (#610, #611, #616, #617) #647 does for [Bug]: tsrx-core: Collect mode throws for a modifier on a rest parameter, which TypeScript reports from its checker #611.
  • Anywhere else nothing is read, so the item reads as before: (a, readonly [b]) is still a member access, and a strict parse fails as before.

The parameters have the constructor's shape. (a, private readonly b?: number, protected c: string = 'x', override d = 1) => a gives the same parameters, apart from locations, as a constructor with them, and so do the async and generic forms. A generic async arrow function (async <T,>(public x: T) => x) is read by acorn-typescript with parseBindingList, where #666 already reads the modifiers. It failed only because toAssignable rejected the parameter property, and it now parses.

#663: an arrow function's optional rest or pattern parameter (TS1047, TS2463)

(...a?: number[]) => a and ({ a }?: T) => a parsed with no error in every mode. The user decided to report them. For an arrow function, parseFunctionBody now raises TS1047 at the ? of an optional rest parameter and TS2463 at an optional pattern parameter, as #647 and #618 do for other functions, with the same messages and positions. Collecting records them, and a strict parse throws them.

#665: a parameter property whose pattern has a default (TS1187)

acorn-typescript's parseAssignableListItem raises TS1187 when a parameter property's parameter isn't an Identifier or an AssignmentPattern, and doesn't look at the AssignmentPattern's left. #parseAssignableListItem now raises it for a pattern with a default too, at the same place, the first modifier. Collecting records it through #644's CHECKER_LEVEL_ERRORS entry. The user decided to report it, so a strict parse throws, as for the parameter without a default.

Behavior change: inputs that compiled and now throw

This is the user's decision. TypeScript's checker reports each of these, and the output for the #665 inputs didn't build (esbuild: Expected identifier but found "["). A strict compile now throws:

Input Error
constructor(public [a] = [1]), constructor(readonly { a }: T = { a: 1 }), constructor(private [a]: number[] = [1]), also after decorators A parameter property may not be declared using a binding pattern. at the first modifier
m(override [a] = [1]) in a class. acorn-typescript reads modifiers on any method's parameters, and m(override [a]: number[]) already threw. the same
(...a?: number[]) => a, (x, ...[a]?) => a A rest parameter cannot be optional. at the ?
({ a }?: T) => a, async (x, [a]?: number[]) => a, const App = ({ a }?: T) => @{ … } A binding pattern parameter cannot be optional in an implementation signature. at the pattern
<T,>({ a }?: T) => a, <T,>(...a?: T[]) => a, async <T,>({ a }?: T) => a Unexpected token at the <, or after async: acorn-typescript throws the error of another reading there (#703)

@tsrx/prettier-plugin parses strictly, so it now refuses these inputs too.

Overrides

Override Issue Upstream What it does
tsParseBindingListForSignature (collect only) #664 sveltejs/acorn-typescript#136 Reads a signature's parameters through parseBindingList, with modifiers.
tsSkipParameterStart (collect only) #664 sveltejs/acorn-typescript#139 (filed) Skips modifiers in the lookahead for a function type.
#parseArrowParameterProperty, through parseParenAndDistinguishExpression, parseSubscript, parseMaybeAssign, tsParseTypeParameters, and toAssignable (collect only) #663 sveltejs/acorn-typescript#136 Reads modifiers before an arrow function's parameter. #136 names arrow functions as needing their own handling.
#parseAssignableListItem (in the parseAssignableListItem override) #665 sveltejs/acorn-typescript#138 (filed) Raises TS1187 for a pattern with a default.
parseFunctionBody #663 none: TSRX's own report TS1047 and TS2463 for an arrow function, like #647's TS1047 and #618's TS2463 for other functions.

I checked #110's head (65376678): tsSkipParameterStart, tsParseBindingListForSignature, and parseAssignableListItem are unchanged there, so it fixes none of these.

The formatters

tsrx-prettier-plugin parses with collect: true. Following decision 14 in #596 and #666, the newly recorded mistakes keep their code in the tree, so they format:

@tsrx/prettier-plugin parses strictly, so it throws for all of them. For the behavior changes above, that's new.

Language server

The language server compiles with loose: true. I ran each new case through compile_to_volar_mappings for all five targets, and none fails. The virtual code keeps the modifiers (const k = (public x: number) => x;, type F = (public x: number) => void;), so TypeScript reports its own TS2369 there too, following #558's convention. The virtual code leaves out an arrow function's optional ?, as it does for other functions (#556), so only TSRX reports TS1047 and TS2463 there.

Verification

Parse comparison with main (3a33f715, merged in). 18,099 distinct sources:

  • the 70 tracked .tsrx files (59 distinct);
  • the 1,545 distinct inputs and 1,574 distinct outputs of the 2,040 Prettier snapshot cases under packages/tsrx-prettier-plugin/tests/prettier/ (readSnapshotEntries/readFormatCase);
  • 14,921 string and template literals from the test files, this PR's included.

Each was parsed strict, with { collect: true, errors: [], comments: [], preserveParens: true }, and with { loose: true }, before and after. That's 108,594 parses in four processes, each killed if a parse took over 15 s. None hung. I compared every AST (without metadata), comment list, and error list, or the thrown message and position.

41 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 or comment list.

I also timed parsing the .tsrx files and Prettier sources five times in each mode, before and after. The difference was within run-to-run noise.

Tests.

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). 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
Changes core TypeScript parsing semantics and breaks previously accepted invalid parameter syntax on strict compile, though behavior is intentional and scoped to parameter/modifier edge cases.

Overview
Extends collect/loose parsing so checker-only parameter mistakes are recorded in errors while the AST is still built—matching TypeScript’s language service—while strict parses (compile, strict Prettier) still throw.

Newly collected (still parse in the formatter/LSP): parameter property modifiers on function/constructor types and on method, call, and construct signatures (via tsParseBindingListForSignature + tsSkipParameterStart), and on arrow parameters (via #parseArrowParameterProperty and related hooks in paren/async/generic lists). Rest-after-rest in signatures is handled like ordinary functions.

New strict failures (previously compiled): TS1187 for constructor(public [a] = [1])-style defaults; TS1047/TS2463 for arrow optional rest and optional binding-pattern parameters (parseFunctionBody).

Prettier collect tests expect these invalid snippets to format where the tree keeps the mistake; strict @tsrx/prettier-plugin and compile paths reject the behavior-change inputs. Types and broad parser/upstream test coverage document the new cases.

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

leonidaz and others added 2 commits September 25, 2026 18:53
…ow functions, and report an arrow function's optional parameters and a parameter property's pattern with a default (#663, #664, #665)

- A parameter property modifier on a signature's parameter (#664) or an arrow
  function's parameter (#663) is recorded as TS2369 when collecting, where
  TypeScript's parser reads it.
- An arrow function's optional rest parameter (TS1047) and optional binding
  pattern parameter (TS2463) are reported, as other functions' are (#663).
- A parameter property whose binding pattern has a default is reported as
  TS1187, as one without a default is (#665).

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