Repository navigation
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
Merged
Conversation
…odifier's message, and accept an optional binding pattern in an overload (#587, #588, #550, #557) 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: - An import or export inside a block (#587): acorn's "'import' and 'export' may only appear at the top level" joins CHECKER_LEVEL_ERRORS, and acorn goes on to parse the declaration as at the top level. - A `const` or `var` with nothing after it, and a bare `let` (#588). parseVarStatement ends the declaration with no declarators where TypeScript's parser ends an empty list (before `;`, `}`, the end of the input, or a line break) and records TS1123 right after the keyword. "The keyword 'let' is reserved" joins CHECKER_LEVEL_ERRORS. - A disallowed modifier (#550): acorn-typescript's tsParseModifiers raises the error template itself, at the token after the modifier. `raise` now calls the template with the modifier and moves the error to it (UPSTREAM(sveltejs/acorn-typescript#123)), and the three messages (TS1070, TS1273, TS1274) join CHECKER_LEVEL_ERRORS. An optional binding pattern parameter (#557) is accepted while reading the parameter, as sveltejs/acorn-typescript#110 does (UPSTREAM(sveltejs/acorn-typescript#110)), and parseFunctionBody raises TS2463 only when a body follows, so overload signatures and abstract methods parse. An array pattern element and a rest parameter keep acorn-typescript's error. tsrx-prettier-plugin refuses an empty declaration list and a disallowed modifier, as Prettier's typescript parser does, instead of printing without the modifier or failing inside the printer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz
added a commit
that referenced
this pull request
Sep 25, 2026
Resolves the conflicts with #618 in plugin.js, keeping both sides: the OPTIONAL_BINDING_PATTERN_PARAMETER constant next to UNEXPECTED_LEADING_DECORATOR, and #618's parseBindingListItem after this branch's parseExportDefaultDeclaration, parseDecorators and parseAssignableListItem, which both sides added at the same place. parseAssignableListItem now uses #618's #bindingListClose to leave a decorated `...` in an array pattern an error, as on main, instead of accepting it like the other decorated array elements (#609). Tests cover errors inside a decorated rest parameter, which keep their message and position, and a decorated optional pattern parameter in an overload. 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 #587
Closes #588
Closes #550
Closes #557
These are more of the #415 family: mistakes that TypeScript's parser accepts and reports only from its checker. As in #558,
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. Each message joinsCHECKER_LEVEL_ERRORSinpackages/tsrx/src/plugin.jsonly after I checked that the raise site goes on to build the node it builds for valid code. Where it can't, a narrow override handles it instead, as #558 did forconstwithout an initializer.The bugs and the fixes
#587:
importorexportinside a blockacorn raises
'import' and 'export' may only appear at the top levelinparseStatementand then parses the declaration as it would at the top level, so the message goes on the list and nothing else changes. Every form TypeScript accepts there parses to the same node as at the top level:export const,export default,export { … },export *,export =,export as namespace,import … from,import x = require(…),import type. TypeScript reports them as TS1184, TS1231, TS1232, TS1233, TS1258, and TS1316.This also fixes the typing case from #583: when a function is missing its
}, the next top-levelexportlands inside it, and a collecting parse now goes on to report'}' expected.at the end, like TypeScript.#588:
constorvarwith nothing after it, and a bareletconstandvar. acorn reads a declarator straight after the keyword and throwsUnexpected tokenat whatever follows. When collecting,parseVarStatementnow checks whether TypeScript's parser would end an empty declaration list there: the next token can't start a declarator (a name,{,[, or#x), and it is;,}, or the end of the input, or a line break comes before it (isVariableDeclaratorListTerminator). If so, it finishes the declaration as acorn-typescript'sparseVarStatementwould, withdeclarations: [], and records TS1123'sVariable declaration list cannot be empty.with no width, right after the keyword, where TypeScript reports it. Anything else takes the old path, soconst 1;,const if (a) {}, andvarfollowed by#xstill throw in every mode, as TypeScript's parser rejects them too. Aconstfollowed by a declarator on the next line is still one declaration.let. Aletthat no binding follows is an identifier, in acorn and in TypeScript. acorn reports it throughraiseRecoverable, which returns once the message,The keyword 'let' is reserved, is on the list. TypeScript reports TS1214 from its checker for every use ofletas a name, so the entry coverslet;,let.x, andx = lettoo.#550: a disallowed modifier's message
acorn-typescript's
tsParseModifiersraises a disallowed modifier's error with the error template itself,this.raise(this.start, errorTemplate), so the message was the function's source, at the token after the modifier.raisenow calls a template it's given with the modifier (the token just read) and moves the error to the modifier. It's the only raise site in acorn-typescript 1.0.13 that passes a function:InvalidModifierOnTypeMember,InvalidModifierOnTypeParameter, andInvalidModifierOnTypeParameterPositionsare passed uncalled only astsParseModifiers'errorTemplate.TypeScript reports all three from its checker (TS1070, TS1273, TS1274), so they join the list:
raisereturns, the loop reads the next modifier, and the node keeps the modifier (accessibility: 'private'on the property signature,in: trueon the type parameter). A strict parse throws the message at the modifier:The text is acorn-typescript's template. It's TypeScript's text, except that TypeScript's TS1273 and TS1274 have no final period.
staticon the line before an interface member, which #551 made a modifier, gets the same error, at thestatic.#557: an optional binding pattern parameter in an overload
acorn-typescript raises TS2463 while it reads the parameter, before it knows whether a body follows. TypeScript's checker reports TS2463 only for a function with a body.
parseBindingListItemnow accepts the?on a parameter that is an object or array pattern, as test: run the parser over the TypeScript compiler corpus sveltejs/acorn-typescript#110 does, and with the same node (optional: true, thentypeAnnotation). An element of an array pattern (const [{ a }?] = b), which TypeScript's parser rejects, and an optional rest parameter keep acorn-typescript's error.parseBindingListrecords the list's closing token so the item can tell a parameter from an array element.parseFunctionBodyraises TS2463, with the same message and position as before, for each optional pattern parameter when a body follows: a{ … }block, a@{ … }code block, or anything else acorn-typescript would read as a body.#isBodilessSignatureis acorn-typescript's own test for aTSDeclareFunctionorTSDeclareMethod, without eating the;. It still skips ambient contexts, as acorn-typescript did, and arrow functions, whose parameters acorn-typescript never checked.Overload signatures, constructor overloads, and abstract methods now parse in every mode. A function with a body is reported as before: collected in
collectmode (#558), thrown in a strict parse.Overrides
raise, for a template messageparseBindingListItem?on an object or array pattern parameter, with #110's AST.Once a release includes #110,
parseBindingListItemand the closing-token bookkeeping inparseBindingListgo. The TS2463 check inparseFunctionBodystays: #110 drops the error everywhere, and this keeps reporting it for a function with a body. #110 also stops reporting[{ a }?]and...a?; that's in #616.Nothing is filed with acorn: its errors here are ECMAScript early errors or syntax errors, which acorn is right to raise.
The formatter
tsrx-prettier-pluginparses withcollect: true, so without a change it would have formatted these. For an import or export inside a block and a barelet, it prints what Prettier'stypescriptparser prints. For the other two it didn't:locEnd(Cannot destructure property 'type').interface I { private x: number }becameinterface I { x: number; }), since Prettier's printer doesn't print it.Prettier's
typescriptparser rejects both (typescript-estree throwsA variable declaration list must have at least one variable declarator.and the modifier errors), so the plugin now refuses them too, through the same path as broken markup and with #511's Prettier-style position:REJECTED_MISTAKESinsrc/parse.js.@tsrx/prettier-pluginparses strictly, so it throws as before, with the new messages for #550, and it formats the #557 overloads, keeping the?.Language server
The language server compiles with
loose: true. I ran every new case throughcompile_to_volar_mappingsfor all five targets: none fails, and the React output was checked with a TypeScript 5.9.3 program:let(TS1212, TS1214), andinorouton a function's or function type's type parameter (TS1274).?([Bug]: tsrx-core: Optional binding pattern parameters lose their?in compiled and editor output #556), so a call likef()gets TS2554 in the editor until [Bug]: tsrx-core: Optional binding pattern parameters lose their?in compiled and editor output #556 is fixed.ESLint's core rules run on the new ASTs, including
declarations: [], without a rule failing. Only the two rules that already fail on any.tsrxfile,no-div-regexandno-dupe-args, fail, because@tsrx/eslint-parserreturns no tokens.Verification
main(1af65cc6). 11,014 distinct sources: the 58 tracked.tsrxfiles, 7,208 string and 359 template literals from 153 test files (including this PR's), and the 1,548 inputs and 1,841 outputs of the 2,040 Prettier snapshot cases underpackages/tsrx-prettier-plugin/tests/prettier/(readSnapshotEntries/readFormatCase). Each was parsed strict, with{ collect: true, errors: [], comments: [], preserveParens: true }, and with{ loose: true }, in four killable child processes, with no hangs. That's 33,042 parses. I compared every AST, comment list, and error list, or the thrown message and position. 43 sources changed, all test strings, and no.tsrxfile or Prettier input or output. 36 of them are this PR's new test strings; the other 7 are existing test strings:staticbefore a line break as a modifier, a generic call signature first in an interface, a class named after a contextual keyword, andassertafter an import (#439, #420, #421, #423) #551'sstaticstrings.importandexportinside a block, which TypeScript reports from its checker #587, [Bug]: tsrx-core: Collect mode throws forconstorvarwith no declarator and a barelet, which TypeScript reports from its checker #588, and [Bug]: tsrx-core: Parser error for a misplaced modifier shows a JavaScript function instead of a message #550 (including fix(core): readstaticbefore a line break as a modifier, a generic call signature first in an interface, a class named after a contextual keyword, andassertafter an import (#439, #420, #421, #423) #551's twostaticstrings).function f([{ a }?]?: T): void;keeps only the error on the array element.closing-brace.test.js([Bug]: tsrx-core: A missing}is reported asUnexpected tokeninstead of'}' expected, and an unclosed directive body at the end of the input parses #583).function f() {\n a();\nexport function g() {}\n,{ const, and{ letnow reach'}' expected.at the end, as TypeScript reports them. That test expected the earlier error in every mode, so it now expects that error only in a strict parse.let &{ a } = b;andlet &[count] = …. They now record theleterror and then throwAssigning to rvalue. The tests that use them parse strictly and still get a throw.parser.test.js, inmistakes that TypeScript reports only from its checker:const 1;,const if (a) {},varfollowed by#x, and@{ const <div /> }.constwith a pattern on the next line, andexportin a namespace.upstream-parser-workarounds.test.js:@{ … }body, which are still reported; an ambient class, which isn't; and array elements and rest parameters, which keep acorn-typescript's error.staticbefore a line break as a modifier, a generic call signature first in an interface, a class named after a contextual keyword, andassertafter an import (#439, #420, #421, #423) #551'sstatictest now expects the error to be collected atstatic.closing-brace.test.js: as above.tsrx-prettier-plugin: the new cases format like Prettier, or are refused with Prettier-style positions.parse_in_worker,parse_in_worker_with_ast). The new tests fail onmain'splugin.js.tsrx-utils,tsrx-analyze,prettier-plugin,tsrx-prettier-plugin,eslint-parser, andtsrx-react(--maxWorkers=4);prettier-known-failures.jsonis unchanged.pnpm typecheck.tsrx-tscisn't linked after--ignore-scripts, so I built@tsrx/typescript-pluginand ran thevite-plugin-honostep throughpackages/typescript-plugin/dist/tsc.js.pnpm format:checkandpnpm changeset:check.A
patchchangeset for@tsrx/coreis included.tsrx-prettier-pluginis private.Findings
New issues:
?after an array pattern element, and reports an optional rest parameter as an optional binding pattern #616: acorn-typescript takes a?after any binding list element.const [a?] = b;parses in every mode, andconst [{ a }?] = b;and an optional rest parameter get TS2463's message. TypeScript's parser rejects the first two (TS1005), and its checker reports TS1047 for the rest parameter.Accessibility modifier already seen.(TS1028) still throws when collecting. It andDuplicate modifierare reported at the token after the modifier, which is acorn-typescript'sthis.startin the same loop as Version Packages #123.Same root cause as the issues here, and not covered:
for (var; ;)andfor (const of x)still throw when collecting. TypeScript reports TS1123 from its checker for both. This PR handles only statements, the typing case in [Bug]: tsrx-core: Collect mode throws forconstorvarwith no declarator and a barelet, which TypeScript reports from its checker #588; aforhead needsparseForStatementand TypeScript'soflookahead.letas a binding name (var let,class let {},import let from 'a',function f(let) {}) still throws when collecting. The message is now acorn's next error for the same name,Binding let in strict mode, instead ofThe keyword 'let' is reserved, at the same position. TypeScript reports TS1212, TS1213, and TS1214 from its checker.({ a }?: T) => a) isn't reported in any mode, as before, since acorn-typescript reads arrow parameters as expressions. TypeScript's checker reports TS2463 for it.class A { constructor(private { a }?: T) {} }throwsA parameter property may not be declared using a binding pattern., andfunction f({ a }?: T, b: ) {}throwsUnexpected token. When collecting, TS2463 is recorded after those errors. No source in the comparison has both.🤖 Generated with Claude Code
Note
Medium Risk
Touches core parser error recovery and Prettier integration; behavior changes for invalid TS in collect mode and when formatting, but strict compile paths remain throwing for these mistakes.
Overview
Extends collect/loose parsing so more TypeScript checker-only mistakes are recorded while parsing continues (strict compile still throws), matching editor and language-server behavior.
Parser (
@tsrx/core): Adds checker-level handling forimport/exportinside blocks, barelet, emptyconst/varlists (TS1123 at the keyword), and illegal modifiers on type members/parameters or misplacedin/out.raisenow evaluates acorn-typescript’s template errors so disallowed modifiers report real messages at the modifier, not function source. Optional binding-pattern parameters ({ a }?: T) parse in bodiless signatures (overloads, abstract methods); implementations with a body still get TS2463 viaparseFunctionBody.Prettier plugin: After a collecting parse,
REJECTED_MISTAKESturns empty declaration lists and disallowed-modifier diagnostics into SyntaxErrors (like broken markup), because Prettier’s TypeScript parser/printer would reject or drop those constructs. Other diagnostic-only issues (e.g. import in a block, barelet) still format.Tests cover parser AST/errors, closing-brace recovery, upstream workarounds, and formatter accept/refuse cases. Patch changeset for
@tsrx/core.Reviewed by Cursor Bugbot for commit f6adebe. Bugbot is set up for automated code reviews on this repo. Configure here.