Skip to content

[Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker #663

Closed

Description

@leonidaz

Issue Category

Compilation Bug

Bug Description

A parameter property modifier on an arrow function's parameter fails in every parse mode, including collect and loose:

const k = (public x: number) => x;
const m = async (readonly x: number) => x;

TypeScript's parser reads both as arrow functions with a parameter property and reports TS2369 A parameter property is only allowed in a constructor implementation. from its checker. By the rule from #415 (#558), collect and loose mode should record such an error and keep parsing, so the editor keeps its AST. #645 does this for a function declaration's or expression's parameters.

Reproduction Steps

On main (10911705), from the repository root:

node --input-type=module <<'JS'
import { parseModule } from './packages/tsrx/src/index.js';

for (const source of [
	'const k = (public x: number) => x;',
	'const m = async (readonly x: number) => x;',
]) {
	const errors = [];
	try {
		parseModule(source, 'App.tsrx', { collect: true, errors, comments: [] });
		console.log(source, '-> parsed, errors', JSON.stringify(errors.map((e) => e.message)));
	} catch (error) {
		console.log(source, '->', error.message);
	}
}
JS
const k = (public x: number) => x; -> The keyword 'public' is reserved (1:11)
const m = async (readonly x: number) => x; -> Unexpected token (1:26)

TypeScript 5.9.3 (ScriptKind.TSX): no parse diagnostic, and TS2369 from the checker at 11 and 17.

Cause

acorn reads an arrow function's parameters as the expressions of a parenthesized expression (parseParenAndDistinguishExpression) and converts them to patterns once it sees =>. Modifiers are read only by @sveltejs/acorn-typescript's parseAssignableListItem, which a parenthesized expression never reaches, so public is read as a name (a reserved word in strict code), and the name after readonly is unexpected.

Fix Direction

When collecting, read parameter property modifiers before an item of a parenthesized expression that can be an arrow's parameter list, where TypeScript does (a modifier followed by a name or a pattern on the same line), build the TSParameterProperty that #645 builds for a function's parameter, and record TS2369 at the first modifier. If no => follows, keep failing as now. A strict parse keeps throwing. sveltejs/acorn-typescript#136 describes the upstream side.

Environment

- OS: macOS 26.6.2
- TSRX package and version: @tsrx/core 0.4.0 (main at 10911705), @sveltejs/acorn-typescript 1.0.13
- Compiler target and version: any (the parser is shared)
- Node Version: 24.18.0

Additional Context

Found while fixing #645. The same cause, reading an arrow's parameters as expressions, means two other checker errors TypeScript reports for an arrow's parameters aren't reported in any mode, while TSRX reports them for other functions:

Both parse today in every mode, so reporting them the way the other functions do would make a strict compile throw for code that compiles now. That needs a decision; TypeScript's checker reports both.

Checklist

  • I've searched for existing issues
  • I'm willing to help implement a fix

Activity

  1. added
    bug
    on Sep 25, 2026
  2. changed the title [-][Bug]: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker[/-] [+][Bug]: tsrx-core: Collect mode throws for a parameter property modifier on an arrow function's parameter, which TypeScript reports from its checker[/+] on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions