Repository navigation
The default tree of the TypeScript, Go and Rust parsers holds every token again, punctuation included - #214
Merged
Merged
Conversation
…e TS, Go and Rust targets keeps punctuation leaves $punct gets a real tt id in ArenaIdPlan (it was the sentinel 255, never stored); the TS cstBuilder, Go CstBuilder.Leaf and Rust CstBuilder::leaf no longer drop it, and the Go direct engine's matchLit pushes a $punct leaf for a non-word literal. SlimBuilder still drops it. Every target's default CST equals the interpreter's CST on the parity corpus of javascript (2487 accepted inputs) and typescript (2647).
…ity gates compare the CST byte for byte
…rse keeps the operator span
johnsoncodehk
added a commit
that referenced
this pull request
Nov 29, 2026
…II in the interpreter and the TS target, as in Go and Rust: `$` starts no identifier in a grammar whose identifier pattern refuses it
Before: in a grammar whose identifier token's ASCII pattern does not take `$` (cappedcalc, calc,
envspec, envtpl, guardjs, ledexitjs, lookrec, the pattern* fixtures, startargets), the interpreter
and the TS target lexed `$a` as an identifier, and Go and Rust refused it as an unexpected
character. The TS target accepted `$a;` in cappedcalc; Go and Rust rejected it. Recovery inherited
the difference: on the total-lex inputs (`` `a ${x `` and three more) the TS repairs differed from Go's
and Rust's (the recovery gate's cross-target check P6, 4 mismatches per target), and the last
landing had fed those inputs to the javascript / typescript recovery class only.
Now: all four agree. `$` is lexed as an identifier only where the grammar's own pattern takes it.
Cause: not recovery, the lexer. Each target ends its dispatch with a Unicode IdentifierName
fallback (the identifier classes, ECMAScript's by default: `$`, `_`, ID_Start / ID_Continue).
uni-ident.ts defines it as an extension BEYOND ASCII ("a run starting at a non-ASCII ID_Start
character"): an ASCII character is the token pattern's to take or refuse. Go and Rust guard the
fallback with `c >= 0x80`, and the TS target's continuation (lx_ext) guards `< 0x80`; the
interpreter's fallback (lexer.ts) and the TS target's did not, so the ASCII members of the class
(`$`) reached it. The interpreter was inconsistent with itself too: `$` started an identifier but
did not continue one (`a$` lexed as `a`, `$`).
Fix: the same guard in the interpreter's fallback (src/interpreter/lexer.ts) and the TS target's
(src/targets/target-ts.ts). `$a;` joins cappedcalc's reject list, so the strict lists gate (every
target against the interpreter) sees this class; the recovery gate's narrowing is removed: the
total-lex inputs run in every recovery grammar's class again.
HTML (landing #213 first): html.ts's attribute names were the tag-name pattern, so `<a _b="1">` and
`<a $b="1">` (valid HTML) were accepted only through this fallback; #213 gave html its own
attribute-name token, matched before the fallback. With the guard, html's verdict on every case of
#213's table (25 cases: `_b`, `$b`, `@click`, `:x`, `[p]`, `(e)`, `#r`, `*ngIf`, `1b`, `-b`, `é`, the
parse-error names, ...) is identical, interpreter and jsTarget; html-conformance green. No html
reject case for `_` / `$` is added: they are valid.
Three tests pinned the unguarded fallback and follow it now (CI round 1 on this branch found them;
each old expectation is proven wrong against the contract, uni-ident.ts "beyond ASCII", and Go /
Rust already behaved so):
- test/portable-corpus.ts: the expected-fail entry for exactly this cause (envspec / envtpl,
`#\n$ x #\n$ x`, Go / Rust disagreeing with the interpreter) no longer disagrees: removed (the gate
demands it), the list is empty.
- test/lexer-verify.ts: the identifier-extension toy (`[a-z_][a-z0-9_]*`) expected `a$` as `a`, `$`
(the fallback's identifier); now a lex error at the `$` (`a$`, `a$b`, `é$ a$`); the extension rows
(`aé$`, `naïve`, `café`) unchanged. docs/TARGETS.md's witness sentence says the same.
- test/agnostic.ts: the raw-text toy lexed `[CODE]` only because the fallback took ASCII upper case
its lowercase Word refuses; the toy now declares a word with both cases (its checks unchanged).
Can it happen on javascript / typescript: no. A sweep of every ASCII character of the identifier
start class, alone and followed by `a`, through each grammar's interpreter lexer: on javascript,
typescript, javascriptreact, typescriptreact (and minijs, regexjs, templatejs, the dialects) every one
is lexed as the identifier by the token's own pattern, so none reaches the fallback; the guard
changes nothing there (the emitted Go / Rust already had it). Only `$` in the eleven fixtures above
is affected.
Evidence
- Recovery gate, cappedcalc (`node test/portable-recovery.ts --grammars=cappedcalc`, this branch's
tests, from master 093dfb8): with master's two lexer sources, Go 8 and Rust 6 mismatches: on the
four total-lex inputs 4 P6 per target (`` `a ${x ``: TS read `$` as an Ident and repaired `$`,
`{x` as two statements; Go / Rust skipped `${x` as one $error), plus the new `$a;` reject case
(the TS target accepted it, Go / Rust did not: 1 P6 per target, and the oracle-vs-parseTotal and
step-count lines on Go); with the guard: recovery ok on TS / Go / Rust, 0 P6.
- Interpreter on cappedcalc `$a;`: before accepted (an Ident `$a`); after "Unexpected character at
offset 0: '$'"; `é;` and `aé;` unchanged (accepted).
- Emission against master 093dfb8's lexer sources (javascript, typescript, cappedcalc, calc;
default and recovery): Go and Rust byte-identical; TS changes in one line per grammar,
`const _um = LX_UNI_IDENT.exec(src);` -> `const _um = src.charCodeAt(pos) >= 0x80 ? LX_UNI_IDENT.exec(src) : null;`
(+37 bytes; the fallback runs only after every dispatch arm failed).
- CI green on 3534c18 (all jobs; runs 46296307593 CI, 46296307528 profile), after merging #214
and re-running the recovery (cappedcalc, calc, envspec: 0 P6), parity corpus (the eleven `$`
fixtures), lexer-verify and agnostic locally. Profile default rows A against M (Rust Callgrind
instructions, reuse and fresh, 13 inputs each): 26 of 26 rows +0.000% (Rust emission is
byte-identical). Then merged master d07cb23 (shape-plan / rust-shape only): fd67497.
Owed (unchanged by this landing): an invalid escape INSIDE a template gives no tree (the lexer must
hand out escape offsets); a repair that skips a zero-width template tail says "unexpected end of input".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What changes
The tree that the generated TypeScript, Go and Rust parsers build by default now holds every token as a leaf again, punctuation included. Until now these three targets left out
(,),;,=,,and every other punctuation token, while the reference interpreter kept them and the README said the tree holds every token. Now the three targets give exactly the interpreter's tree.let a = f(1);letaf1leta=f(1);Who must change their code: anyone who walks the default tree and reads a node's children by position. The call
f(1)above had two children, the callee and the argument. It now has four, with the(and)leaves between and after them. Code that picks a child by its kind or rule name is not affected. Go and Rust users of the slim builder see no change: it still keeps only rule nodes and named tokens, as a deliberately smaller tree.Results
[a, b] = x;got a wrong span (start 7, end 6). It now spans its own=.Cost
Instructions per parse, Rust target, a fresh parse, before and after:
checker.tstypescript.jstypescript.d.tschecker.tsmonogram goes from 0.896 to 0.915 of oxc's count. Ontypescript.d.tsit goes from 0.997 to 1.034, so monogram now executes slightly more instructions than oxc there.Known limits
🤖 Generated with Claude Code