Documentation

Docs / Reference

ADR 0074 - Patched JavaScript, TypeScript and TSX grammars (TS-F2 recovery)

Status: Accepted (delegated review, 2026-11-18) Date: 2026-11-18

Task: T020 (grammar patches). Evidence: the T020 task record (internal) and its per-file census the T020 task record (internal). Amends ADR 0006 (asset list and compilation-cache namespace), ADR 0007 ("compiles checked-in generated parsers without regeneration") and ADR 0028 (toolchain note), and narrows the cost of row TS-F2 of ADR 0070.

Context

ADR 0070 row TS-F2 refuses every TypeScript, TSX or JavaScript file in which tree-sitter reports an ERROR or MISSING node: the file claims nothing beyond its file node. The developer chose (O-S3-1 (c)) to fix the grammar gaps as their own task. The investigation found 749 rejected files of 22,122 on the 27 pinned corpora plus Graphvein itself; the TypeScript 6.0.3 compiler parses 745 of them without a syntax error. Nine forms cause the 745; three of them (G1 keyword JSX attribute names, 644 files, all JavaScript; G2 a bare & in JSX text or attribute strings, 14; G4 export type *, 1) account for 659.

The pinned grammars are the newest releases: tree-sitter-javascript v0.25.0 and tree-sitter-typescript v0.23.2 (git tags, npm, crates.io and PyPI agree). G1 is a regression of JavaScript 0.25.0, which adopted tree-sitter 0.25's reserved-word sets.

Options considered

Decision

Carry three reviewed patches of the generated src/grammar.json files (decisions 1 and 2):

Patch file Grammar Change
grammars/patches/javascript-0001-jsx.diff JavaScript v0.25.0 src/grammar.json P1: _jsx_attribute_name also accepts the reserved-word tokens break case catch class const continue debugger default delete do else export extends finally for function if in instanceof new return switch throw try typeof var void while with, aliased to property_identifier, and wraps the identifier branch in RESERVED properties. P2: _jsx_bare_ampersand (token(prec(-1, /&/))) aliased to jsx_text in _jsx_child and to string_fragment in both _jsx_string quote forms
grammars/patches/typescript-0001-jsx-export-type.diff TypeScript v0.23.2 typescript/src/grammar.json P2 as above; P3: the export type branch of export_statement also takes * from and namespace_export from
grammars/patches/tsx-0001-jsx-export-type.diff TSX v0.23.2 tsx/src/grammar.json P2 and P3

Pipeline (scripts/build-grammars.py, grammars/manifest.yaml):

Same change (decision 6): tree-sitter-javascript (patched or not) reads await (x).y() as a call of a function named await; the TypeScript extractor now records no call site for a call whose callee is the bare identifier await (counted misparse), and still reads the calls in its operand. A bare await(x) is already read as an await_expression and is not affected, and the TypeScript and TSX grammars read every form correctly. In a sloppy script that declares function await, a real call written await (1).y() is dropped the same way: an under-claim counted misparse, never a wrong fact. Such calls occur 30 times in accepted files (maintainerr 26, all in .yarn/releases/yarn-4.17.1.cjs, which is not extracted; gladys 3; kaneo 1). Snapshot diff main against the branch with the unchanged grammar modules: main emitted 3 invented unknown call sites (gladys 2 in server/lib/gateway/gateway.disconnect.js, kaneo 1 in scripts/ui-review-bot/worker/index.mjs) and no edge; the branch removes those 3 and adds misparse counts (gladys 3, kaneo 1); nothing else changes on maintainerr, gladys or kaneo.

Consequences

Known gaps

Implementation

Review notes (acceptance, 2026-11-18)

Accepted after delegated review (2026-11-17; the developer asked for the grammar task, O-S3-1 (c), to be finished before acceptance). Steps: the investigation (the T020 task record (internal), census of 749 rejected files and fix options), the implementation (patch pipeline, CI build, module registration, the await call-site rule), one independent review (the T020 task record (internal): no class A; B1 a name reachable through a type-only and a value star export of different modules, B2 missing fixtures for the recovered forms, C1-C3 docs), TSGF fixes (B1 binds nothing for such a name, mutation-checked; B2 fixture files per recovered form; C1-C3).

Report a problem with this pageSource: docs/adr/0074-typescript-javascript-grammar-patches.md