Skip to content

Decorators are parsed by the grammar: @ a, @a . b, @℘ accepted as tsc does; the decorator scope covers only @name - #209

Merged
johnsoncodehk merged 5 commits into
masterfrom
land/grammar-decorators-2
Nov 24, 2026
Merged

johnsoncodehk merged 5 commits into
masterfrom
land/grammar-decorators-2

Conversation

@johnsoncodehk

Copy link
Copy Markdown
Owner

The single-token Decorator pattern (@ then an optional name(.name | .#name | .)*) made a decorator's
shape a lexer decision: trivia after @ or around a . broke it (@ a class C {}, @a . b class C {}),
a name with a character beyond ASCII was no token (@℘ class C {}, @a.℘ class C {}), and the token
swallowed a trailing . and a bare @ (@a. class C {}, @ class C {}, @() class C {} were
accepted). tsc's parser accepts the first four and rejects the last three; the decorators proposal's
productions (Decorator : @ DecoratorMemberExpression | @ DecoratorParenthesizedExpression | @ DecoratorCallExpression, DecoratorMemberExpression : IdentifierReference | DecoratorMemberExpression . IdentifierName | DecoratorMemberExpression . PrivateIdentifier) put every one of those tokens apart.

Change (javascript.ts, typescript.ts):

  • The Decorator token is @ and ONE IdentifierName (ASCII and \u escapes, as before). It stays a token
    so the three highlighters keep the decorator scope on @name. @ is also a literal: a @ that trivia
    or a non-ASCII character separates from its name lexes alone, then an Ident.
  • JavaScript's DecoratorExpr: @ ( Expression ), or a head (the Decorator token, or @ and an
    IdentifierReference) then (. IdentifierName | . PrivateIdentifier)* and optional arguments.
  • TypeScript's: the head is the Decorator token (not @new), or @ and a non-reserved name or a
    parenthesized expression, then the LeftHandSideExpression tails as before; @new X is the fused
    @new token or @ new.
  • Every lookahead that tested the Decorator token tests @ too.

Verdicts (interpreter JS / TS, before -> after; tsc):
@ a class C {} r/r -> A/A (tsc A); @a . b class C {} r/A -> A/A (A); @℘ class C {} r/r -> A/A (A);
@a.℘ class C {} r/r -> A/A (A); @a. class C {} A/A -> r/r (r); @ class C {} A/A -> r/r (r);
@() class C {} A/A -> r/r (r); @ new x class C {} -/A (A). Unchanged: @a, @a.b.c, @a.#p,
@a(1), @(e), @new x (TS), @a.b(1).c (TS A, JS r: not a DecoratorMemberExpression), @a[0] r.
Witnesses: test/js-conformance.ts (valid JS), test/portable-cases.ts TS_DECORATORS (every engine).

Highlighter changes (TextMate, Monarch, tree-sitter; expected): the decorator scope covers @name only:
in @a.b.c the .b.c is now an accessor and properties, as in any member expression (before, the
whole @a.b.c was one decorator-scoped token); a lone @ is punctuation (punctuation.js/ts,
Monarch delimiter, tree-sitter @punctuation.delimiter). Monarch's JavaScript rules list the
delimiter rule before the parenthesis rule (an ordering of disjoint rules). The regex-start contexts
gain @ (after @ an operand may start: @(…)).

Records moved (re-measured on the rewritten history, master 3587831 merged in): the ECMAScript lexer goldens
(test/golden/lexer: the Decorator token and the @ literal re-derived in the frozen specs; 4 cases per golden, each
a lone @ that is now the literal); lex-family's Decorator read bounds (a failed attempt now reads an escape:
failRead Infinity) and its failed-attempts list (+ Decorator); treesitter-assertions reserved-set +1 per grammar
(the @ name arm's reserved guard); decision pages (no new ties or dead arms).

Recovery (test/portable-recovery.ts): @ joins the grammar's literals and TypeScript's decorator list gains
accepts, so both mutant sets are drawn again (the documented procedure): the farthest-hint floors move
javascript 5412 -> 5349 (5,349 of 5,850 rejects agree, 91.4%, was 91.7%) and typescript 6051 -> 6388 (6,388 of
6,845, 93.3%). P10 lists redrawn: javascript greedy captures drop two entries no longer drawn and gain
for (of of as y);; typescript's drop for (global of of x); and gain for (x = (y = (a in b)) constructor c);
and for (get of of x); (each an arrow body taking a supplied in); the lookahead-bypass and unclassified lists
hold none of their entries in this draw and are empty (f(class extends a?.b{ () {});, class C { static export case type\nx = 1 }, export await using from|meta x = y; are not drawn; the export await using kind is the
grammar's export lookahead admitting a Stmt: it leaves with the Statement / Declaration split). The P10 check
now names the listed entries that no longer fail.

TextMate / Monarch agreement (node test/monarch-dialect.ts --agreement): identical to the record (typescript
98.70%, javascript 99.17%). Verdict scan: unchanged. test262 and tree-sitter records: unchanged (CI green).

Profile (run 45352219814, A = merge base 3587831, M = b93592e). Work counters identical on every input (rule
calls, checkpoints, restores, peeks, leaf pushes, lex_tokens). Rust instructions (parse): checker.ts +0.42%,
typescript.js +0.54%, parser.ts +0.43%, gen-tm.ts +0.63%, typescript.d.ts +0.34%, typescript.ts +0.41%
(gen-tm.tsx +1.71%, jsx-corpus.tsx +1.26%; synthetic: synth2mb +0.50%, nonascii +0.29%, dense-* 0.00%). This is
the known lexer-layout effect, decided as accepted by the coordinator: the earlier full-scope run (45327261780)
put it in lex_into, mostly "line 0" (no source line) with the same token count: the lexer dispatch function's
register allocation after the @ punctuator joined it; three attempts to cure it failed. Go instructions (reuse):
checker.ts +0.35%, gen-tm.ts +0.11%, typescript.d.ts +0.25% (builder: +0.36% / +0.12% / +0.28%), with the same
work; TS target blocks: checker.ts -0.0004%, gen-tm.ts -0.005%, typescript.d.ts -0.065%.

Emitted sizes (docs/emit-sizes.json re-recorded): what the Decorator token's pattern did is now DecoratorExpr's
arms, so the parsers move: e.g. typescript js +0.73%, go -0.66%, rust +0.12%; javascript ts -0.68%, js +1.09%,
rust -0.19% against the record. NOTE: master's record already drifted before this change (textdialect, which does
not import javascript.ts, moved ts -0.53%, go -0.30%), so part of these moves is master's earlier drift absorbed
by the re-record.

Owed: @a℘ class C {} (tsc accepts) is still refused: the Decorator token stops at ℘ and the Unicode fallback
cannot take a prefixed token whose prefix is also a punctuator (lexer side). The token's name is not checked
against reserved words (@class, @this in JavaScript: as before).

🤖 Generated with Claude Code

johnsoncodehk and others added 5 commits November 24, 2026 07:38
…egments and arguments are the grammar's (transplanted from land/grammar-decorators 5632dcd onto the rewritten history; regenerated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… sizes re-recorded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e literals): floors and P10 lists re-measured

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/COMPLETENESS.md
#	test/portable-recovery.ts
#	typescriptreact.tmLanguage.json
@johnsoncodehk
johnsoncodehk merged commit 6bb8170 into master Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant