Repository navigation
fix(core): read an async arrow function's optional rest parameter, report a generic arrow function's errors where they are, collect a signature parameter's default, and reject async(a)(b) => and type assertions in arrow parameters (#702, #703, #704, #705, #706) - #728
Merged
Merged
Conversation
…port a generic arrow function's errors where they are, collect a signature parameter's default, and reject `async(a)(b) =>` and type assertions in arrow parameters (#702, #703, #704, #705, #706) - An async arrow function's optional rest parameter parses, and TS1047 is recorded when collecting and thrown otherwise (#702, sveltejs/acorn-typescript#140). - A generic arrow function read past its `=>` throws its own error instead of `Unexpected token` at its type parameters (#703, sveltejs/acorn-typescript#141). - A call after `async (…)` followed by `=>` is a syntax error, as in TypeScript (#704, acornjs/acorn#1460). - A parameter's default in a signature is recorded as TS2371 when collecting and thrown otherwise (#705). - A type assertion in an arrow function's parameters is a syntax error, as in TypeScript (#706, sveltejs/acorn-typescript#142). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.
Reviewed by Cursor Bugbot for commit e3388de. Configure here.
…e members in every mode Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #702
Closes #703
Closes #704
Closes #705
Closes #706
These follow #701: arrow functions and signatures that TSRX read differently from TypeScript's TSX parser. Each cause is in
@sveltejs/acorn-typescriptor acorn, and each fix is a narrow override inTSRXPluginmarkedUPSTREAM(…), as in #701. Two kinds of input that compiled now throw, because TypeScript rejects them (decision 23 in #596; see Behavior change).The bugs and the fixes
#702: an async arrow function's optional rest parameter
async (...a?: number[]) => afailed withUnexpected tokenat the?in every mode. acorn reads an async arrow function's parameters as the arguments ofasync (…), and acorn-typescript'sparseExprListreads a type annotation after a spread there, but not a?(sveltejs/acorn-typescript#140).parseSubscriptnotes where the(ofasync (…)is (#parseAsyncArguments), andparseExprListmarks that list, and no other, forparseSpread.parseSpreadtakes a?after a spread in that list and makes itoptional, asparseParenItemdoes for the items of a parenthesized list. The rest parameter keeps it, and 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's check inparseFunctionBodyreports TS1047 at the?: recorded when collecting, thrown in a strict parse.=>follows,#parseAsyncArgumentsfails at the?withUnexpected token, as before (async(...a?)). A spread in any other list,f(...a?)orasync(f(...b?)) => 1, fails there as before too.The rest parameter's range stays the spread's, which ends before its type annotation, as for any async rest parameter today (#725).
#703: a syntax error in a generic arrow function
acorn-typescript reads an expression that starts with
<as an element first, then as a generic arrow function, and when both failed it threw the element's error. It readsasync <T,>(…) => …in atsTryParseAndCatchthat took any error to mean "not an arrow function" and went on to readasync < Tas a comparison (sveltejs/acorn-typescript#141). So an error in the arrow function's parameters or body was reported asUnexpected tokenat its type parameters, or after them.#parseGenericArrowFunctionwraps both places,#parseMaybeAssign(an expression that starts with<) andparseSubscript(async <). It notes where the type parameters start,tsParseTypeParametersnotes where the arrow function's parameters start, andparseArrowExpressionrecords theSyntaxErrorthat arrow function throws. It's thrown instead of acorn-typescript's.parseArrowExpressionis only called once the=>is read, so this covers the errors from there on: in the body, and the ones the parser raises for the parameters after the=>(TS1047, TS2463, [Bug]: tsrx-core: A type assertion in an arrow function's parameters parses with no error, and the output keeps it #706's type assertion).parseBindingListinside itstsTryParseAndCatch, whereparseBindingListItemthrew TS1047, before the=>. For that list,parseBindingListItemnow leaves it toparseFunctionBody, which raises it after the=>for every arrow function.This is reported as
Unexpected token (1:30)at the;, where TypeScript reports TS1109, instead ofUnexpected token (1:10)at the<. The message is acorn's, as for the same mistake anywhere else.#704:
async(a)(b) => 1acorn's
parseSubscriptsworks outmaybeAsyncArrowonce, for theasyncidentifier, and passes it to every subscript in its loop, so an=>after a later call made the whole chain an async arrow function, andasync(a)(b) => 1compiled toasync (b) => 1(acornjs/acorn#1460).parseSubscriptnow keepsmaybeAsyncArrowonly while the base is still theasyncidentifier, which is the first subscript. The chain is a call, and the=>after it fails withUnexpected token, where TypeScript reports TS1005';' expected..#705: a parameter's default in a signature (TS2371)
acorn-typescript's
tsParseBindingListForSignaturerejected anAssignmentPatternwith its own message,Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got AssignmentPattern., in every mode. TypeScript's parser reads it, and its checker reports TS2371A parameter initializer is only allowed in a function or constructor implementation.. #701's override of that method now raises TS2371 at the parameter instead, in every mode.CHECKER_LEVEL_ERRORSlists it, so collecting records it and keeps the default in the tree, as typescript-estree does, and a strict parse throws it. The strict parse still reads the list as acorn-typescript does; only the message changes.type F = (public x = 1) => voidrecords TS2369 and TS2371 when collecting, both at the modifier, as TypeScript reports them.#706: a type assertion in an arrow function's parameters
(x as number) => x,(x!) => x, andasync ([a satisfies number]) => aparsed in every mode, and the output kept the assertion. TypeScript's parser doesn't read these as arrow functions (TS1005). acorn-typescript'stoAssignableaccepts an assertion in a binding, where @babel/parser reports it (sveltejs/acorn-typescript#142).checkLValPattern, which already unwraps type assertions for assignment targets, now raises @babel/parser'sUnexpected type cast in parameter position.at an assertion when it checks a binding (a binding type other thanBIND_NONE), in every mode. It isn't intoAssignable, as the issue suggested, for two reasons:toAssignablegetsisBinding: truefor an assignment target too (parseMaybeAssignOrigin), and acorn's nested conversions droppreserveTypeScriptWrapper, so it can't tell([a as T]) => afrom[a as T] = arr, which TypeScript accepts.([b as T] = []) => b, isn't converted again, butcheckParamschecks every parameter with a binding type.Only an arrow function's parameters, which acorn reads as expressions, can hold an assertion in a binding. An assignment target keeps working:
(x as number) = 1,[a as number, b!] = [1, 2],[{ a: o } as { a: unknown }] = [],({ a: b! } = o).Behavior change: inputs that parsed and now throw
TypeScript's parser rejects each of these (decision 23). A strict compile, and now
collectandloosemode too, throw:async(a)(b) => 1,async(a)[0](b) => 1,async(a)`t`(b) => 1,async!(a) => 1,async<T>(a)(b) => 1Unexpected tokenat the=>(TypeScript: TS1005';' expected.there)(x as number) => x,(x!) => x,(x!: number) => x,async (x!) => x,async ([a satisfies number]) => a,({ a: b as string }) => b,([b as string] = []) => b,<T,>(x as T) => x,(props as Props) => @{ … },function f(x = (a as T) => a) {}Unexpected type cast in parameter position.at the assertion (TypeScript: TS1005';' expected.or',' expected.)Inputs that threw before and throw a different error now:
?instead ofUnexpected tokenthere.async (...a?, b) => 1now throwsComma is not permitted after the rest elementat the comma, asasync (...a, b) => 1does, and records it with TS1047 when collecting.async (...a? = 1) => 1fails at the=instead of the?.Unexpected tokenat its type parameters #703: the arrow function's error, at its place, instead ofUnexpected tokenat the<(or afterasync <T). For the generic arrow functions in 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's behavior change table,<T,>({ a }?: T) => a,<T,>(...a?: T[]) => a, andasync <T,>({ a }?: T) => a, that's TS2463 or TS1047 now.@tsrx/prettier-pluginparses strictly, so it now refuses the behavior change inputs too.Overrides
parseSubscriptmaybeAsyncArrowonly while the base isasync.parseSpread, withparseExprListand#parseAsyncArguments(fromparseSubscript)?after a spread among the arguments ofasync (…), and fails at it when no=>follows.#parseGenericArrowFunction, from#parseMaybeAssignandparseSubscript, withtsParseTypeParameters,parseArrowExpression, andparseBindingListItem(TS1047)=>.tsParseBindingListForSignature(#701's override, now in every mode)checkLValPatternI checked #110's head (
65376678): it doesn't touchparseExprList,parseSubscript,parseMaybeAssign,tsTryParseGenericAsyncArrowFunction,tsParseBindingListForSignature, ortoAssignable, so it fixes none of these.The formatters
tsrx-prettier-pluginparses withcollect: true:typescriptparser formats them: a parameter's default in a signature keeps it.type F = (a = 1) => void,interface I { m(a: number = 1): void; new ({ b } = { b: 2 }): I }, andlet f: (a?: number = 1) => voidformat the same.async (x, ...a?: number[]) => aprints without the?, as(...a?: number[]) => adoes since 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.typescriptparser rejects it:type F = (public x = 1) => void, as 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'stype F = (public x: number) => void. The tree keeps the modifier and the default. Nothing is added toREJECTED_MISTAKES.typescriptparser refuses them (with its own messages): the behavior change inputs, and a generic arrow function's syntax error now at its place.@tsrx/prettier-pluginparses strictly, so it throws for all of these.Language server
The language server compiles with
loose: true. I ran the new collect-mode parses throughcompile_to_volar_mappingsfor all five targets (type F = (a = 1) => void, the interface above,type G = (public x = 1) => void, async arrow functions' optional rest parameters, also in a template's setup, andasync <T,>({ a }?: T) => a). None fails. The virtual code keeps the default (export type F = (a = 1) => void;), so TypeScript reports its own TS2371 there too, following #558's convention. It leaves out the rest parameter's?, as for other functions (#556).Verification
Parse comparison with
main(f73b6760). 19,427 sources, 18,453 distinct:.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 116,562 parses in four worker threads, each killed if a parse took over 15 s. None hung. I compared every AST, 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.Unexpected tokenat its type parameters #703's positions, [Bug]: tsrx-core: Collect mode throws for a parameter initializer in a function type or a signature, which TypeScript reports from its checker #705's message).Unexpected tokenat its type parameters #703).I also timed parsing the
.tsrxfiles and Prettier sources, five times in each mode, in alternating processes before and after. The difference was within run-to-run noise.Tests.
parser.test.js,mistakes that TypeScript reports only from its checker: new cases for [Bug]: tsrx-core: An async arrow function's optional rest parameter fails to parse in every mode, where TypeScript reports TS1047 from its checker #702 (an async arrow function's optional rest parameter, one with a pattern and a comment before the?across lines) and [Bug]: tsrx-core: Collect mode throws for a parameter initializer in a function type or a signature, which TypeScript reports from its checker #705 (a function type, an interface's method, call, and construct signatures across lines, a constructor type, and a parameter property with a default). Each checks the collected messages at their positions, the node, and the strict throw.<T,>({ a }?: T) => athrows TS2463 now ([Bug]: tsrx-core: A syntax error in a generic arrow function is reported asUnexpected tokenat its type parameters #703).upstream-parser-workarounds.test.js, new describes:?when collecting, inloosemode, and thrown strictly (with a return type across lines, and in a template's setup), and a?after a spread that keeps failing where no=>follows.=>in every mode, and async arrow functions and calls ofasyncthat still parse. The file's header now names acorn too.tsParseBindingListForSignaturenow runs in a strict parse too (added after Bugbot's review; it parses as onmain).tsrx-prettier-plugin/tests/tsrx.test.js: the new parses that format, and the errors for [Bug]: tsrx-core: A syntax error in a generic arrow function is reported asUnexpected tokenat its type parameters #703, [Bug]: tsrx-core:async(a)(b) => 1parses as an async arrow function and compiles toasync (b) => 1#704, and [Bug]: tsrx-core: A type assertion in an arrow function's parameters parses with no error, and the output keeps it #706.main's parser. 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(no changes outside this PR's files), andpnpm changeset:check.A
patchchangeset for@tsrx/coreis included.tsrx-prettier-pluginis private.Findings
Filed upstream:
for…inorfor…ofhead is rejected sveltejs/acorn-typescript#148: a type assertion in afor…inorfor…ofhead is rejected. It's the other branch of feat: carry diagnostic severity and codes through collected-error channel #142'stoAssignablecase, whose flag means the opposite of @babel/parser's.?in parentheses or call arguments is accepted when no=>follows sveltejs/acorn-typescript#149: a?or a type annotation in parentheses or call arguments is accepted when no=>follows.Filed here, each with a separate cause and not fixed in this PR:
for…inorfor…ofhead fails to parse, although TypeScript accepts it #723:for ((a as T) of x)fails to parse in every mode, although TypeScript accepts it (A type assertion in afor…inorfor…ofhead is rejected sveltejs/acorn-typescript#148).?or a type annotation in parentheses or call arguments parses when no=>follows, and the compile crashes or keeps it #724:(x: number),f(x?), andf(...x: number[])parse with no error; the compile crashes (Not implemented: TSTypeCastExpression) or prints the mistake back (A type annotation or?in parentheses or call arguments is accepted when no=>follows sveltejs/acorn-typescript#149).tsrx-prettier-pluginmoves a comment inasync (...a /* c */: number[]) => aafter the type annotation (An async arrow function's rest parameter ends before its type annotation sveltejs/acorn-typescript#150).function f(...a = []) {}), which TypeScript reports from its checker (TS1048).(...a, b) => 1), which it records for functions, signatures, and async arrow functions (TS1014).Same cause as the issues here, and not covered:
=>is still acorn-typescript's:<T,>(x: ) => xthrowsUnexpected token (1:10)at the<, where TypeScript reports TS1110 at the), andasync <T,>(x as T) => xfails at the=>. In TSX, TypeScript reads<T,,<T =,<T extends U, or<const Tas a generic arrow function before its parameters (isParenthesizedArrowFunctionExpressionWorker) and reports what follows at its place. Reporting those needs that rule in place of acorn-typescript's element-first attempt (A syntax error in a generic arrow function is reported at its type parameters with jsx sveltejs/acorn-typescript#141). [Bug]: tsrx-core: A syntax error in a generic arrow function is reported asUnexpected tokenat its type parameters #703 covers errors from the=>on.🤖 Generated with Claude Code
Note
Medium Risk
Core parser semantics change with new strict errors and shifted diagnostic locations; impact is broad (compile, loose/collect, formatter) but scoped to edge-case syntax and heavily regression-tested.
Overview
Aligns
@tsrx/coreparsing with TypeScript for async/generic arrows and type signatures via targetedTSRXPluginoverrides (markedUPSTREAMfor acorn / acorn-typescript).Parsing and diagnostics: Optional rest on
async (...a?: T[]) =>now parses; collect/loose record TS1047 at?instead of failing at the token. Generic arrow syntax errors (and parameter checker errors after=>) surface at the real site, not at<. Defaults in signatures (type F = (a = 1) => void, etc.) stay in the AST while collect/loose record TS2371 and strict compile throws TypeScript’s message.Intentional breaks (match TypeScript):
async(a)(b) => …no longer rewrites to an async arrow; type assertions in arrow parameters ((x as number) => x,x!,satisfiesin params) throwUnexpected type cast in parameter position.Assignment targets like(x as number) = 1still work.Tests: Parser, upstream-workaround, and prettier-plugin cases cover the new behavior and formatting of signature defaults / async optional rest.
Reviewed by Cursor Bugbot for commit 5118c39. Bugbot is set up for automated code reviews on this repo. Configure here.