Repository navigation
fix(core): collect decorator, modifier, and rest parameter mistakes that TypeScript reports from its checker (#610, #611, #616, #617) - #647
Merged
Conversation
…hat TypeScript reports from its checker (#610, #611, #616, #617) 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 repeated accessibility modifier (#617): "Accessibility modifier already seen." joins CHECKER_LEVEL_ERRORS. It and "Duplicate modifier" are now raised at the repeated modifier instead of the token after it, in every mode (UPSTREAM(sveltejs/acorn-typescript#129)). - Decorators before a declaration other than a class (#610): when a declaration follows, `raise` records acorn-typescript's error at the first decorator and takes the decorators off the decorator stack, so no later class takes them. Before anything else (`@dec x;`), or in an expression, it still throws. Decorators on a constructor join CHECKER_LEVEL_ERRORS. - A modifier on a rest parameter (#611): parseAssignableListItem reads the rest element after the modifiers, records TS1317 at them, and keeps the rest element without them. An optional rest parameter is reported as TS1047 "A rest parameter cannot be optional.", at the `?`, instead of TS2463's message (#616). A `?` after an element of an array pattern is a syntax error in every mode, as in TypeScript (UPSTREAM(sveltejs/acorn-typescript#130)). tsrx-prettier-plugin refuses the mistakes that leave code out of the tree and that Prettier's typescript parser rejects: a second accessibility modifier, a modifier on a rest parameter, and decorators before a declaration other than a class. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ker-errors-3 #614 overrides parseDecorators (decorators before `export`), parseAssignableListItem (decorators on a rest parameter), and parseExportDefaultDeclaration (decorators after `export default`). Combined with this branch: - parseDecorators keeps #614's check before `export` (now #checkDecoratorsBeforeExport) and sets the leading-decorator scope for collecting, so `@dec export function f() {}` is recorded at the decorators when collecting, like the other decorators before a declaration. - parseExportDefaultDeclaration reads the decorators after `export default` as the declaration's leading decorators: `export default @dec function f() {}` is recorded when collecting, and `export default @dec 1;` still throws. - parseAssignableListItem reads a rest element after parameter property modifiers after any decorators too (`constructor(@dec public ...rest)`). The comma check after a rest element is shared. - An at-sign construct after `export` is no declaration, so the error there is still thrown when collecting. #614's tests expect these to throw when collecting too; they now expect the error to be recorded, as TypeScript reports it from its checker (TS1206). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-level list at the new sites Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #610
Closes #611
Closes #616
Closes #617
These are follow-ups to #558 and #618: mistakes that TypeScript's parser accepts and reports only from its checker. As there,
collectandloosemode (the language server, the formatter, and other editor tooling) record them inerrorsand keep parsing, and a strict parse, which every compile uses, still throws them. A message joinsCHECKER_LEVEL_ERRORSinpackages/tsrx/src/plugin.jsonly where the raise site goes on to build the node it builds for valid code; where it can't, a narrow override handles it.mainis merged in, with #614 (which touches the same decorator code), #633, #605, #635, and #641.The bugs and the fixes
#617: a repeated modifier
Accessibility modifier already seen.(TS1028) joinsCHECKER_LEVEL_ERRORS. Whenraisereturns,tsParseModifiersskips recording the second accessibility modifier, as it does forDuplicate modifier, and the node keeps the first (public protected xis apublicfield).this.start, which is the token after the modifier.raisenow moves them to the modifier (this.lastTokStart) in every mode, strict too, because the issue reports the strict position as wrong as well. This follows 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 handling of Version Packages #123, not fix(core): collect type-check-level errors in collect mode instead of throwing (#415) #558's of Version Packages #122, which kept the strict position. The order and compatibility errors (Version Packages #122) keep their strict position as before.#616:
?after a binding list elementparseBindingListItem(#618's override) now handles every?that acorn-typescript would take:const [a?] = b;,[{ a }?],[...a?], also in a parameter or aforhead): TypeScript's parser rejects it with',' expected.(TS1005). It now throws acorn'sUnexpected tokenat the?in every mode. Before,[a?]parsed without an error, and a pattern or rest element got TS2463's message about parameters.function f(...a?: number[]) {}, and in an overload): TypeScript reports TS1047A rest parameter cannot be optional.from its checker. It's now reported with that message, at the?, instead of TS2463's message at the.... It's raised only where acorn-typescript raised TS2463's message (not in a type or an ambient context, where TypeScript's checker reports TS1047 too), so no source that parsed before throws now. The node keepsoptional: true, as test: run the parser over the TypeScript compiler corpus sveltejs/acorn-typescript#110 gives it.#611: a modifier on a rest parameter
acorn-typescript's
parseAssignableListItemreads the modifiers and thenparseMaybeDefault, which can't read.... When collecting,#parseRestParameterPropertylooks ahead withtsTryParse: if the modifiers are followed by..., it reads the rest element, records TS1317A parameter property cannot be declared using a rest parameter.across the modifiers, and returns the rest element as the parameter, without them. typescript-estree rejects a rest parameter property, so there's no ESTree node to mirror, and dropping the modifiers is what the issue suggests. A comma after that rest element is reported as for any rest parameter. Otherwise the lookahead is undone and acorn-typescript reads the item as before. A strict parse still throwsUnexpected tokenat the.... It works after #614's decorators too (constructor(@dec public ...rest)).#610: decorators that TypeScript reports as TS1206
Which cases are collected, and why. TypeScript's parser takes decorators before any declaration and reports them from its checker. Whether it reports them depends on
experimentalDecoratorsin only two places, and the parser can't know that option:@dec function f() {},@dec const x = 1;,@dec interface I {},@dec import …,export @dec function f() {},export default @dec function f() {},@dec export function f() {},@dec export default 1;experimentalDecorators@dec export …since #614); now recorded when collectingclass A { @dec constructor() {} }CHECKER_LEVEL_ERRORS)@dec x;,@dec if (a) {},export @dec x;,export default @dec 1;Declaration expected.from the parserconst y = @dec 1;,const y = @dec function () {};experimentalDecoratorsconst A = @dec class {};experimentalDecoratorsSo only the rows that TypeScript reports whatever the option says, and that threw here, are collected. The two option-dependent rows stay as they are: accepted, with TypeScript's checker deciding in the editor and
tsrx-tsc.How. acorn-typescript raises
Leading decorators must be attached to a class declaration.after reading the decorators, and leaves them on the decorator stack, so the next class parsed would take them.parseDecoratorsnow marks the decorators of a statement (the only caller that allowsexportafter them) and those afterexport default(#614'sparseExportDefaultDeclaration). Whenraisegets that error for them while collecting, and a declaration keyword follows, it records the error at the first@, where TypeScript reports TS1206, and takes the decorators off the stack. The statement is then parsed without them.#parseDecoratedStatementstill throws the original error, at its original position, if the statement turns out not to be a declaration (@dec type;). An at-sign construct afterexport(@dec export @if (a) { … }) isn't a declaration, so that still throws. #614's check for decorators beforeexportis unchanged; it's now#checkDecoratorsBeforeExport, called from the combinedparseDecorators.ESTree has no place for decorators on a function or a variable, so the tree leaves them out. That's fine for the editor. The formatter refuses it (below).
Overrides
raise, for a repeated modifierparseBindingListItem, for an array pattern elementUnexpected tokenat the?.parseBindingListItem, for a rest parameterparseFunctionBody.parseAssignableListItem(#parseRestParameterProperty)parseDecorators,parseStatement,parseExportDefaultDeclaration(#dropLeadingDecorators,#parseDecoratedStatement)sveltejs/acorn-typescript#122 and #123 are the other position bugs in the same
tsParseModifiersloop, and neither covers the repeated-modifier errors, so I filed #129. I checked both new issues against a build of #110's head (65376678): it doesn't fix #129, and for #130 it accepts every array-element?with no error, because it drops the only check. #130 also covers a type annotation on an array element (const [a: number] = b;), which acorn-typescript accepts in the same method. This PR doesn't reject that (see Findings).Nothing is filed with acorn: its errors here are ECMAScript early errors or syntax errors, which acorn is right to raise.
The formatters
tsrx-prettier-pluginparses withcollect: true. For each new case I compared it with Prettier'stypescriptparser:Refused through
REJECTED_MISTAKES. The tree leaves code out, and Prettier'stypescriptparser rejects the input too:public x = 1);constructor(...rest: number[]));function f() {}).Each error is at the same position as Prettier's (
(1:18),(1:23),(1:1),(1:8),(1:16)).Formatted as Prettier formats them:
readonly readonly xbecomesreadonly x.function f(...a?: number[]) {}becomesfunction f(...a: number[]) {}. Prettier's printer doesn't print a rest element's?either.Formatted, where Prettier's parsers reject it:
class A { @dec constructor() {} }. The tree keeps the decorator, so nothing is lost, and it prints unchanged.@tsrx/prettier-pluginparses strictly, so it throws for all of them, as before. The messages are the new ones for the repeated modifiers and the optional rest parameter.Language server
The language server compiles with
loose: true. I ran every new case throughcompile_to_volar_mappingsfor all five targets, and none fails. I checked the React output with a TypeScript 5.9.3 program. Only TSRX reports each of them, because the printer leaves the construct out:?of a rest parameter;The exception is the constructor decorator, which both TSRX and TypeScript report (TS1206), following the convention #558 describes.
Verification
Parse comparison with
main(4701beb1). 18,064 distinct sources:.tsrxfiles;packages/tsrx-prettier-plugin/tests/prettier/(readSnapshotEntries/readFormatCase);Each was parsed strict, with
{ collect: true, errors: [], comments: [], preserveParens: true }, and with{ loose: true }. That's 54,192 parses in four workers, each killed after 15 s, with no hangs. I compared every AST, comment list, and error list, or the thrown message and position.52 sources changed: 1 Prettier input, 16 existing test strings, and 35 of this PR's new test strings. No
.tsrxfile changed.typescript/conformance/classes/constructorDeclarations/constructorParameters.snap :: readonlyReadonly.ts. ItsDuplicate modifiererrors moved to the repeated modifier, in every mode. It formats as before.?after an array element used to parse and now throw:const [a?] = b;,function f([a?]: number[]) {},declare function f([a?]: number[]): void;, andfor (const [a, b?] of c) {}.@dec type;records the decorator error before throwing it at the same place.@dec function f() {\n\t@inner x;\n}now throws the inner decorators' error, atx, because the outer decorators are before a declaration and are recorded.export default @dec function f() {}and@dec export function f() {}. They threw when collecting and are now recorded, and fix(core): parse anonymous and decorated default-exported classes as declarations, and decorators on a rest parameter (#194, #533, #564) #614's tests are updated to expect that.m(@a ...rest?: any[])pair, which is TS1047 now.readonly readonly,function f(...a?: number[]): void;,const [{ a }?] = b;, andfunction f([{ a }?]?: T): void;.Tests.
parser.test.js, inmistakes that TypeScript reports only from its checker:readonly readonlycase moved to the modifier. For each case, the test checks:function f() {}for@dec function f() {}, andconstructor(...rest)forconstructor(public ...rest)) or an expected shape;@dec function f() {}followed byclass A {}).still throws decorators before anything but a declaration, for six sources, with messages and positions in all three modes.upstream-parser-workarounds.test.js:accessor,in, andconst.?in every mode, and a?after a parameter or in a tuple type is still accepted.export default @dec 1;and the at-sign constructs, which still throw. The recorded ASTs have noDecoratorleft.tsrx-prettier-plugin/tests/tsrx.test.js: the refused cases, with Prettier's positions, and the cases that still format.main'splugin.jsandparse.js. The others guard behavior that already worked.Local runs. These pass:
tsrx-utils,tsrx-analyze,prettier-plugin, andtsrx-prettier-plugin(--maxWorkers=4), after mergingmain;prettier-known-failures.jsonstays empty.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:
?and a type annotation sveltejs/acorn-typescript#130: an array pattern element takes a?and a type annotation.Filed here, each with a separate cause and not fixed in this PR:
parseAssignableListItem.publicis a reserved word.Same cause as the issues here, and not covered:
const [a: number] = b;) still parses in every mode, where TypeScript's parser rejects it. It's the sameparseBindingListItemcause as the?, and it's in An element of an array pattern takes a?and a type annotation sveltejs/acorn-typescript#130. This PR rejects only the?, as [Bug]: tsrx-core: Parser takes?after an array pattern element, and reports an optional rest parameter as an optional binding pattern #616 asks.(...a?: number[]) => a) isn't reported in any mode, as before. acorn-typescript reads arrow parameters as expressions (parseParenItem), as 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 notes for an arrow's optional pattern parameter.export(@dec export default @dec2 function f() {}) record one error, at the second decorators, and drop both. TypeScript also reports TS8038 for them.exportrecorded,@dec export x;now throwsUnexpected tokenatxwhen collecting, instead of the decorator error at the same position.export @if (a) { … }crashes with aTypeErrorin every mode. That's [Bug]: tsrx-core: Parser crashes with a TypeError onexport abstractfollowed by a line break #607. The at-sign construct check above keeps@dec export @if (a) { … }throwing the decorator error instead of reaching that crash.🤖 Generated with Claude Code
Note
Medium Risk
Changes core parser error handling and AST recovery paths used by the language server and formatter; behavior shifts for invalid TypeScript that previously threw or parsed incorrectly.
Overview
Aligns TSRX parsing with TypeScript checker diagnostics in
collect/loosemode (editor, Prettier plugin) while strict compile still throws: repeated accessibility modifiers, leading decorators on non-class declarations (including export forms), modifiers on rest parameters, optional rest parameters, and constructor decorators are recorded and parsing continues instead of hard-failing or mis-attaching decorators to a later class.Parser fixes in
plugin.js: repeated-modifier errors point at the duplicate modifier (not the following token);...rest?reports TS1047 at?;const [a?]is a syntax error everywhere; collect-mode paths drop invalid leading decorators and parse the declaration without them via#dropLeadingDecorators/#parseRestParameterProperty.Prettier plugin treats the new collected errors like existing “would lose AST” mistakes—formatting is refused when output would silently strip the second modifier, parameter-property+rest, or misplaced leading decorators; some checker-only issues still format like Prettier’s TypeScript parser (e.g. duplicate
readonly, optional rest?stripped).Reviewed by Cursor Bugbot for commit 7ec52d1. Bugbot is set up for automated code reviews on this repo. Configure here.