Conversation
The bottom-up traversal matches Three things before merge:
Once these land, this is ready to merge. |
Still want this – reviver symmetry with |
|
Thanks @johannschopplich — yes, I'm up for finishing it. It's been a bit, so to target the right gaps: which specific approve-with-changes items stalled it? I'll knock those out and report the bundle-size delta with the reviver added. |
All three from the review round are still open – the branch has no commits since:
And the bundle-size delta you already offered. With those, ready to merge. |
Mirrors the existing `replacer` option for encode. The reviver function is called bottom-up (leaves first) during decode, matching JSON.parse reviver semantics. Supports value transformation, property filtering via `undefined` return, and path tracking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ed104ed to
b3e4f61
Compare
|
All three are in, plus the bundle numbers.
Bundle delta for One thing worth flagging from the rebase: this branch was cut when
|
Summary
Adds a
reviveroption toDecodeOptions, mirroring the existingreplacerforEncodeOptions. The reviver transforms values during decode, matchingJSON.parsereviver semantics (bottom-up traversal: leaves first, then parents).Why this matters
JSON.stringifyhasreplacer,JSON.parsehasreviver. TOON'sencodealready hasreplacer. The decode side had no equivalent, forcing users to walk the decoded tree manually for any post-decode transformation.PR #161 (quoteStrings) was closed in favor of the general-purpose
replacer, confirming the preference for general mechanisms over specific flags.reviverfollows the same philosophy for the decode side.Usage
Changes
packages/toon/src/types.ts: addedDecodeRevivertype andreviveroption toDecodeOptionspackages/toon/src/decode/reviver.ts: new module implementing bottom-up value traversal (mirrorsencode/replacer.ts)packages/toon/src/index.ts: wired reviver intodecodeFromLines(), exportedDecodeRevivertypepackages/toon/test/reviver.test.ts: 22 tests covering filtering, transformation, root handling, bottom-up traversal, path tracking, edge cases, and JSON.parse parityDemo
Testing
All 488 tests pass (22 new + 466 existing). Lint, build, and type checks clean.
This contribution was developed with AI assistance (Claude Code).