tc39 / proposal-json-parse-with-source

Proposal for extending JSON.parse to expose input source text.
https://tc39.github.io/proposal-json-parse-with-source
MIT License
214 stars 9 forks source link

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

Closed gibson042 closed 1 year ago

gibson042 commented 2 years ago

Source text access is restricted to primitive values per https://github.com/tc39/proposal-json-parse-with-source/issues/10#issuecomment-704441802 , 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 commented 2 years ago

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.