Repository navigation
Simplify compiler internals; fix event leakage in typed parsers - #103
Conversation
Greptile SummaryThis PR simplifies compiler source generation while fixing typed parsers so runtime event hooks cannot persist across
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, security, or repository-rule issues identified. The refactors preserve prior generation semantics, while the parser-tail change correctly scopes validator and event state to individual calls and is covered by a focused typed and untyped regression test. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Hera grammar] --> B[Compiler]
B --> C[Generated JS or TS parser]
C --> D[parse call]
D --> E[Fresh Validator]
D --> F[Fresh event context]
E --> G[Rule execution and validation]
F --> G
G --> H[Parse result]
Reviews (1): Last reviewed commit: "Unify parser tails; fix event leakage in..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #103 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 9 9
Lines 1903 1886 -17
Branches 311 307 -4
=========================================
- Hits 1903 1886 -17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| ruleNames.map((name) -> ` ${name}`).join(",\n") | ||
|
|
||
| return `{\n${meat}}` | ||
| compileRulesObject := (ruleNames: string[]) -> |
There was a problem hiding this comment.
Perhaps add an optional "newline before close brace" argument so you can use it in export below?
There was a problem hiding this comment.
Done in b1bd9cf: ruleNameBlock(names, closeOnOwnLine) now emits the braces, and both the grammar object and export use it. Output verified unchanged against the snapshot.
There was a problem hiding this comment.
I'd probably inline compileRulesObject now i.e. just use ruleNameBlock
There was a problem hiding this comment.
Inlined; compileRulesObject is gone and the call site uses ruleNameBlock directly. Branch squashed to one commit and rebased on main.
Refactor (byte-identical output): - Merge the three terminal-interning functions into one `intern` helper. - Drop the `types` parameter threaded through `compileOp`; it was never read. - Write `tsHead` as a literal instead of deriving it from `mjsHead` with a regex replace and a match on the import block. - Emit the braced rule-name block from one `ruleNameBlock` helper, used by both the grammar object and the ESM export block. - Collapse `prettyPrint` to a single expression. Fix: - The typed parser tail hoisted the Validator and context out of `parse` into an IIFE, so `Object.assign(ctx, options.events)` from one call persisted into the next. The untyped tail created them per call. Emit one tail for both, with type annotations slotted in when `types` is set, using the per-call structure. Typed output changes only in the tail. Adds a regression test for both JS and typed parsers. Verified against a snapshot of compiler output for source/hera.hera, every sample, and the inference fixture across ten option combinations. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01P6RAoyCaAv1Xe7FjMYwD3b
b1bd9cf to
15d0e73
Compare
Summary
Two commits.
1. Pure refactor, byte-identical output
defineTerminal,defineRe,defineDynamicRe) into oneinternhelper.typesparameter threaded throughcompileOp; it was never read.tsHeadas a literal instead of deriving it frommjsHeadvia regex replace and a match on the import block.prettyPrintto one expression.2. Unify the JS and TS parser tails, fixing a bug
Validator()andctxout ofparseinto an IIFE, soObject.assign(ctx, options.events)from one call persisted into later calls. The untyped tail created them per call. Confirmed: afterparse("a", { events: { enter } })thenparse("a"), the typed parser firedentertwice, the untyped one once.typesis set.transpileTsToJs) parsers.Verification
Snapshotted compiler output for
source/hera.hera, every sample, and the inference fixture across ten option combinations (js/ts, cjs/esm, civet, tokenize, custom libPath, inline map), 180 files total.After commit 1: all 180 identical.
After commit 2: untyped outputs identical. Typed outputs differ only in the parser tail, as intended.
c8 mocha— 210 passing, 100% coveragepnpm test:typed-parser-samplespnpm test:esbuild-pluginpnpm test:loaders🤖 Generated with Claude Code
https://claude.ai/code/session_01P6RAoyCaAv1Xe7FjMYwD3b