Repository navigation
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
Conversation
…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]>
This was referenced Sep 25, 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 #644
Closes #645
Closes #646
These follow #558, #618, and #647: 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, 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.mainis 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.joinsCHECKER_LEVEL_ERRORS. Whenraisereturns, acorn-typescript goes on to build theTSParameterPropertywith the pattern as itsparameter, the node typescript-estree's shape allows.#reportOptionalPatternParametersnow looks through a parameter property, soconstructor(public { a }?: T) {}also records TS2463, as TypeScript does.#645: a parameter property modifier on a function's parameter (TS2369)
acorn's
parseFunctionParamsreads a function's parameters with noallowModifiers, so acorn-typescript doesn't read modifiers there:publicfailed as a reserved word, and the name afterreadonlyas unexpected. When collecting,parseBindingListnow passesallowModifiers: falsefor a)list that was given none (only acorn'sparseFunctionParamsdoes that; methods passtrue). acorn-typescript then reads the modifiers and raises itsUnexpectedParameterModifiererror, which is TypeScript's TS2369 text and which joinsCHECKER_LEVEL_ERRORS, and builds theTSParameterProperty, 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).raisemoves it to the first modifier, where#parseAssignableListItemstarted 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.parsePropertythrows acorn'sUnexpected tokenat 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
forhead (TS1123):for (var; ;),for (const of x),for (let of x),for (const in x),for await (var of x), and@for (const of items). When collecting,parseForStatementchecks where TypeScript's parser ends the list: after the keyword comes;,}, the end of the input, a line break, orin, and no declarator, oroffollowed by a name and)(canFollowContextualOfKeyword). It then finishes the declaration with no declarators and records TS1123 with no width, right after the keyword, sharing#parseEmptyDeclarationListwith fix(core): collect more checker-level mistakes, report a disallowed modifier's message, and accept an optional binding pattern in an overload (#587, #588, #550, #557) #618's statement case.for (const of of x)still declaresof, andfor (const of [])still throws.get_for_of_iteration_paramsgives a@forloop over such a list no parameter, instead of printing(const ;) =>into the virtual code.letas a binding name or an assignment target (TS1212, TS1213, TS1214):var let,class let {},import let from 'a',function f(let),const { a: let } = b,let = 1. acorn reports the reserved word, which fix(core): collect more checker-level mistakes, report a disallowed modifier's message, and accept an optional binding pattern in an overload (#587, #588, #550, #557) #618 already collects, and then raisesBinding let in strict mode,Assigning to let in strict mode, orlet is disallowed as a lexically bound name(TS2480) throughraiseRecoverable, which always goes on. These now joinCHECKER_LEVEL_ERRORS, and#collectCheckerLevelErrorrecords only the first error for eachlet, so each mistake gets one error.Gaps left
(...a?: number[]) => a, TS1047), and its optional pattern parameter (({ a }?: T) => a, TS2463, from fix(core): collect more checker-level mistakes, report a disallowed modifier's message, and accept an optional binding pattern in an overload (#587, #588, #550, #557) #618's list). These parse in every mode today. Reporting them the way other functions do would make a strict compile throw for code that compiles now, which fix(core): collect decorator, modifier, and rest parameter mistakes that TypeScript reports from its checker (#610, #611, #616, #617) #647 avoided for TS1047. That needs a decision. It's recorded in [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663, together with the arrow half of [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on a function's parameter, which TypeScript reports from its checker #645.for (let; ;)andfor (let in x): acorn readsletthere as a name, not a declaration, and fix(core): collect more checker-level mistakes, report a disallowed modifier's message, and accept an optional binding pattern in an overload (#587, #588, #550, #557) #618 already records theleterror and keeps parsing. TypeScript reads an emptyletlist instead (TS1123). Both report an error, and changing the AST of code that parses when collecting seemed out of scope.Overrides
parseBindingList(collect only)allowModifiers: falsefor a function's parameters.raise, forUnexpectedParameterModifierparsePropertyparseForStatement(collect only)parseVarStatementdoes.sveltejs/acorn-typescript#136 also asks upstream to pass
falsefor a method other than a constructor, as Babel does. acorn-typescript passestruefor every method, soclass 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 (at65376678) has the sameparseAssignableListItemandparsePropertycode, so it fixes neither.The formatters
tsrx-prettier-pluginparses withcollect: true. For each newly recorded mistake, I compared it with Prettier'stypescriptparser:forhead, through the existingVariable declaration list cannot be empty.entry inREJECTED_MISTAKES. Prettier'stypescriptparser rejectsfor (const of x)(Only a single variable declaration is allowed…) and crashes onfor (var; ;).constructor(public [a]: number[])andfunction f(private readonly x: number). The tree keeps the modifiers and the pattern, so nothing is lost. This is how fix(core): collect decorator, modifier, and rest parameter mistakes that TypeScript reports from its checker (#610, #611, #616, #617) #647 handled the constructor decorator, and I didn't add these toREJECTED_MISTAKES. [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on a function's parameter, which TypeScript reports from its checker #645 suggested refusing it, but no code is dropped.var let = 1;,class let {}.@(Unexpected token (1:13), where Prettier reportsProperty assignment expected. (1:13)).@tsrx/prettier-pluginparses strictly, so it throws for all of them, as before.Language server
The language server compiles with
loose: true. I ran every new case throughcompile_to_volar_mappingsfor all five targets, and none fails. The virtual code keepspublic [a],function f(public x: number),var let, andfor (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 toget_for_of_iteration_params, the transform used the declaration itself as the parameter ((const ;) =>).Verification
Parse comparison with
main(d1785a10): 17,493 distinct sources:.tsrxfiles;readSnapshotEntries/readFormatCase);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 (withoutmetadata), 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
.tsrxfile, Prettier input or output, or existing test string changed, and no source that parsed before has a different AST.@.{ @dec ...s }threw after the decorators and now throws at the@.forheads, andlet.let =, still throws, now at the end of the input, after recording theleterror.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 asconstructor(public x: number)forfunction f(public x: number), or an expected shape), and the unchanged strict throw. There are also new sources that record nothing (parameters namedreadonlyandoverride, and declarators namedof) and sources that still throw (for (const of []),for (const of x.y), andreadonlybefore a line break).upstream-parser-workarounds.test.js:declare function, and nothing recorded for a method.@in every mode, and a class member's decorators and a decorated class as a value still parse.tsrx-prettier-plugin/tests/tsrx.test.js: the refusedforheads, 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.main'splugin.js, and the@forcompile test fails withmain'sast-builders.js.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), after mergingmain.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:
tsParseBindingListForSignaturecalls acorn'sparseBindingListdirectly, past this override.constructor(public [a] = [1])parses in every mode with no error, and the compiled output fails in esbuild. acorn-typescript's TS1187 check doesn't look inside anAssignmentPattern.Same cause as the issues here, and not covered:
async <T,>(public x: T) => x) still throw in every mode. It's the arrow case of [Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663.for (const item of items; index i)extension: an empty list before it (for (const of items; index i)) still throws when collecting, because TypeScript'soflookahead needs a)after the name.🤖 Generated with Claude Code
Note
Medium Risk
Touches core parser error collection and for-loop/
@forcodegen 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
errorswhile 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, viaparseBindingList/ error repositioning), emptyfordeclaration heads including@for (const of items)(TS1123, shared#parseEmptyDeclarationList), and extralet-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:
@forover an empty declaration list exposes no loop parameter (get_for_of_iteration_params).Prettier plugin: Documents/refuses empty
forheads 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.