Repository navigation
Conversation
jordanbtucker
requested changes
Oct 18, 2026
jordanbtucker
left a comment
Member
There was a problem hiding this comment.
Thanks, this looks good. I checked it against Node's native JSON.parse with a bunch of different revivers, and context matches in every case, including source disappearing after a value is modified. I also didn't see any slowdown when no reviver is passed.
Before merging, can you add a CHANGELOG entry under Unreleased, and document the context argument in the README's reviver section?
43081j
force-pushed
the
jg/source-revivals
branch
from
October 19, 2026 09:01
b0e4e52 to
c5c0f6b
Compare
Closes json5#361. The parse loop has changed quite a lot since that PR was opened so its pretty much a full rework to add this feature either way. This adds support for `context.source` when using a reviver, just the same as `JSON.parse`. Note that this may look a bit funky but that's for performance reasons. Instead of allocating an AST-like set of objects to track position info, we hold a collection of slots. The slots collection looks like this: ```ts type PrimitiveSlot = [value: unknown, start: number, end: number]; type ChildMeta = Array<number> | Map<string, number> type ContainerSlot = [value: unknown, childMeta: ChildMeta, end: 0]; ``` This results in something like this: ```ts // {foo:303,bar:808} const slots = [ // {foo:303,bar:808} root, Map { foo: 3, bar: 6 }, 0, // 303 303, 5, 8, // 808 808, 13, 16 ]; ```
43081j
force-pushed
the
jg/source-revivals
branch
from
October 19, 2026 09:03
c5c0f6b to
cb2930a
Compare
Collaborator
|
Since this implements the source text access reviver API, it also resolves #185. Worth adding |
jordanbtucker
requested changes
Oct 22, 2026
jordanbtucker
left a comment
Member
There was a problem hiding this comment.
Thanks! Just a couple doc changes. Happy to push them myself if you’d rather.
Co-authored-by: Jordan Tucker <[email protected]>
This branch has not been deployed
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.
Closes #361.
Closes #185.
The parse loop has changed quite a lot since that PR was opened so its pretty much a full rework to add this feature either way.
This adds support for
context.sourcewhen using a reviver, just the same asJSON.parse.Note that this may look a bit funky but that's for performance reasons. Instead of allocating an AST-like set of objects to track position info, we hold a collection of slots.
The slots collection looks like this:
This results in something like this: