Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should reviver functions still get a context argument for non-primitive values? #25

Closed
gibson042 opened this issue May 28, 2022 · 1 comment

Comments

@gibson042
Copy link
Collaborator

Source text access is restricted to primitive values per #10 (comment) , so there is currently no information to provide for non-primitive values:

JSON.parse("42", (key, val, context) => context) // => {source: "42"}
JSON.parse("{}", (key, val, context) => context) // => ???

Some possibilities:

  1. Do not provide the argument at all.
  2. Provide undefined.
  3. Provide an object with no source property ({}).
  4. Provide an object with source: undefined.
@gibson042
Copy link
Collaborator Author

I am in favor of the third option, always providing the object for consistency (and in particular to not break callbacks that attempt to destructure it) but omitting the source property.

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

No branches or pull requests

1 participant