Repository navigation
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
Conversation
…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]>
…hen collecting Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 25, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz
enabled auto-merge (squash)
September 25, 2026 23:53
leonidaz
disabled auto-merge
September 25, 2026 23:53
This was referenced Sep 26, 2026
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.
Closes #663
Closes #664
Closes #665
These follow #647 and #666: parameter mistakes that TypeScript's parser accepts and reports only from its checker.
collectandloosemode (the language server, the formatter, and other editor tooling) record them inerrorsand 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'sparseBindingListdirectly, past #666's override, with noallowModifiers. When collecting,tsParseBindingListForSignaturenow reads them throughparseBindingList, which passesallowModifiers: false. acorn-typescript then reads the modifiers and raises TS2369,raiserecords it at the first modifier, and the parameter is aTSParameterProperty, 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) => voidfrom a parenthesized type (tsSkipParameterStart) didn't skip modifiers, so it read(public xas a parenthesized type and failed atx. TypeScript'sskipParameterStartskips 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:#parseArrowParameterListmarks a list that can be an arrow function's parameters: a parenthesized expression that can be an arrow function (parseParenAndDistinguishExpression), or the arguments afterasync(parseSubscript).parseMaybeAssigncounts how deep the parser is in an item, so only the list's items are candidates, not the expressions inside them.parseFunctionBodysets the list aside for a body.#startsArrowParameterPropertylooks ahead. It reads the rest of the list as parameters (parseBindingListwithallowModifiers: false) and checks that=>follows. At the list's first item it also requires what TypeScript'sisParenthesizedArrowFunctionExpressionWorkerrequires, a name other thanasafter the modifier. So(public [a]) => a,(public ...r) => r, and(readonly as) => 1, which TypeScript's parser rejects, still throw, while(a, public [b]) => ais read. After type parameters (<T,>(public [a]: T) => a), TypeScript reads parameters whatever the first item is;tsParseTypeParametersrecords where they end.#parseArrowParameterPropertyreads the modifiers, records TS2369 at the first one, reads the item as before, records TS1187 if it's a pattern, and builds theTSParameterPropertythat a function's parameter gets.toAssignablemakes 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.(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) => agives 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 withparseBindingList, where #666 already reads the modifiers. It failed only becausetoAssignablerejected the parameter property, and it now parses.#663: an arrow function's optional rest or pattern parameter (TS1047, TS2463)
(...a?: number[]) => aand({ a }?: T) => aparsed with no error in every mode. The user decided to report them. For an arrow function,parseFunctionBodynow 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
parseAssignableListItemraises TS1187 when a parameter property's parameter isn't anIdentifieror anAssignmentPattern, and doesn't look at theAssignmentPattern'sleft.#parseAssignableListItemnow raises it for a pattern with a default too, at the same place, the first modifier. Collecting records it through #644'sCHECKER_LEVEL_ERRORSentry. 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:constructor(public [a] = [1]),constructor(readonly { a }: T = { a: 1 }),constructor(private [a]: number[] = [1]), also after decoratorsA parameter property may not be declared using a binding pattern.at the first modifierm(override [a] = [1])in a class. acorn-typescript reads modifiers on any method's parameters, andm(override [a]: number[])already threw.(...a?: number[]) => a,(x, ...[a]?) => aA 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) => aUnexpected tokenat the<, or afterasync: acorn-typescript throws the error of another reading there (#703)@tsrx/prettier-pluginparses strictly, so it now refuses these inputs too.Overrides
tsParseBindingListForSignature(collect only)parseBindingList, with modifiers.tsSkipParameterStart(collect only)#parseArrowParameterProperty, throughparseParenAndDistinguishExpression,parseSubscript,parseMaybeAssign,tsParseTypeParameters, andtoAssignable(collect only)#parseAssignableListItem(in theparseAssignableListItemoverride)parseFunctionBodyI checked #110's head (
65376678):tsSkipParameterStart,tsParseBindingListForSignature, andparseAssignableListItemare unchanged there, so it fixes none of these.The formatters
tsrx-prettier-pluginparses withcollect: true. Following decision 14 in #596 and #666, the newly recorded mistakes keep their code in the tree, so they format:typescriptparser rejects them:type F = (public x: number) => void,interface I { m(private readonly x: number): void },(public x: number) => x,async (a, readonly [b]: number[]) => a,async <T,>(override x: T) => x, andconstructor(public [a] = [1]). The tree keeps the modifiers, the pattern, and the default. None of these is added toREJECTED_MISTAKES.typescriptparser formats it:({ a }?: T) => akeeps its?, and(...a?: number[]) => aprints without the?, asfunction f(...a?: number[]) {}does since fix(core): collect decorator, modifier, and rest parameter mistakes that TypeScript reports from its checker (#610, #611, #616, #617) #647.(a: number, public ...rest: number[]) => a, through the existingREJECTED_MISTAKESentry for TS1317, because the tree drops the modifiers (as for [Bug]: tsrx-core: Collect mode throws for a modifier on a rest parameter, which TypeScript reports from its checker #611).@tsrx/prettier-pluginparses 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 throughcompile_to_volar_mappingsfor 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:.tsrxfiles (59 distinct);packages/tsrx-prettier-plugin/tests/prettier/(readSnapshotEntries/readFormatCase);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 (withoutmetadata), 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
.tsrxfile, 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
.tsrxfiles and Prettier sources five times in each mode, before and after. The difference was within run-to-run noise.Tests.
parser.test.js,mistakes that TypeScript reports only from its checker: 21 new cases for [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663, [Bug]: tsrx-core: Collect mode throws for a parameter property modifier in a function type or a signature, which TypeScript reports from its checker #664, and [Bug]: tsrx-core: A parameter property with a binding pattern and a default parses with no error, and its output doesn't build #665. Each checks the collected messages and the source text at their positions, the node (against a valid equivalent, such as the constructor's parameters for(public x: number) => x, or an expected shape), and the strict throw. New sources that still throw in every mode:(public [a]) => a,async (readonly { a }) => a,(public ...r) => r,(readonly as) => 1, modifiers where no=>follows, andtype F = (public ...rest: number[]) => void, which TypeScript also reads as a parenthesized type. New sources that record nothing: parameters named after modifiers,(a, readonly [b]),f(readonly, readonly[0], override * 2),type P = (readonly [string]) | (readonly string[]), and a parameter property with a default that isn't a pattern.upstream-parser-workarounds.test.js:tsrx-prettier-plugin/tests/tsrx.test.js: the cases that format, and the refused rest parameter.main's source. The others guard behavior that already worked.Local runs. These pass:
tsrx-utils,tsrx-analyze,prettier-plugin,tsrx-prettier-plugin,tsrx-react,tsrx-preact,tsrx-solid,tsrx-vue, andtsrx-hono(--maxWorkers=4).prettier-known-failures.jsonis unchanged.pnpm typecheck.tsrx-tscisn't linked after--ignore-scripts, so I built@tsrx/typescript-pluginand ranvite-plugin-hono'stypecheck:teststhroughpackages/typescript-plugin/dist/tsc.js.pnpm format:checkandpnpm changeset:check.A
patchchangeset for@tsrx/coreis included.tsrx-prettier-pluginis private.Findings
Filed upstream:
Filed here, each with a separate cause and not fixed in this PR:
async (...a?: number[]) => a, fails to parse in every mode. acorn-typescript'sparseExprListdoesn't take the?(An async arrow function's optional rest parameter fails to parse sveltejs/acorn-typescript#140). Once it parses, this PR's check reports TS1047.Unexpected tokenat its type parameters #703: a syntax error in a generic arrow function is reported asUnexpected tokenat its type parameters. acorn-typescript throws the error of reading<T,>as an element (A syntax error in a generic arrow function is reported at its type parameters with jsx sveltejs/acorn-typescript#141). That's the strict error for the generic rows in the behavior change table.async(a)(b) => 1parses as an async arrow function and compiles toasync (b) => 1#704:async(a)(b) => 1parses as an async arrow function and compiles toasync (b) => 1(An arrow after a later call in an async call chain makes the chain an async arrow function acornjs/acorn#1460).type F = (a = 1) => void, which TypeScript reports from its checker (TS2371). The check is in thetsParseBindingListForSignaturethat this PR overrides, but it's a different mistake.(x as number) => x, parses with no error, and the output keeps it (A type assertion in an arrow function's parameters is accepted sveltejs/acorn-typescript#142).<T>(…) => …, which isn't valid TSX #707: a generic arrow function with one type parameter,<T,>(x: T) => x, compiles to<T>(x: T) => x, which isn't valid TSX, in the compiled output and the editor's virtual code. esrap 2.3.8 fixed its TSX printer; the lockfile has 2.3.2.Same cause as the issues here, and not covered:
(a, @dec b) => a) still throw in every mode (Leading decorators must be attached to a class declaration.). TypeScript's parser reads them and its checker reports TS1206. It's [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663's cause, arrow parameters read as expressions, but [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663 covers modifiers only.(1, public x) => 1now throwsAssigning to rvalueat the1, wherepublicwas a reserved word before, and(a, public ...r, b) => anow throwsComma is not permitted after the rest element, as(a, ...r, b) => adoes. Both still throw.🤖 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
errorswhile 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#parseArrowParameterPropertyand 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-pluginand 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.