-
Notifications
You must be signed in to change notification settings - Fork 15
Description
If not allowing parsing which errs upon use of the JSON6 (or changing JSON6 to become a strict subset of JS), I would find it helpful to have documented the JSON6 features which are not allowable in JavaScript.
I changed some tests around so as to see whether the tests would unexpectedly pass or fail within JavaScript. Some details below on how I identified the missing support if of interest*.
I see the following divergences**:
- In JSON6, old-style octal support has not been entirely removed (from source or tests), so
eval
complains about this for strict mode. - ES does not fail with
.123e2-45
,.123e3-45
- Not allowed in ES: Literal newline inside string, e.g.,
{a:'abc\ndef'}
(ok with backticks) - Not allowed in ES: Back-tick quoted keys
- Not allowed in ES: Keys with special symbols (hyphens, backslashes, ampersand, plus, asterisk, pipe)
- Not allowed in ES: There aren't tests for it, but multiple minus signs
- Not present in ES: Console warnings with an unfinished
//
comment
My suggested lines of action (besides documenting any remaining differences):
- No. 1 appears to be a bug to be fixed (per the current README).
- No. 2 would be a good feature to add.
- No. 3, 4, 6, and 7 do not add much value, imo, to justify deviating from JS, esp. with backticks available
- No. 5 adds some value, but imho, it would be better to keep JS compatibility
- Restrict use of unescaped
${...}
within backticks so that moving JSON6 to JS could not suddenly turn into variable substitution.
No. 3-5 could even be proposed to JS for them to be supported in a future ES version, though they might want to reserve the characters for potential use or deliberately err with those characters to prevent typos.
* I created an "drop-unused-stream-reviver" branch (not meant for merging) to find these (running npm run mocha-lite
or nyc run nyc-lite
). This branch:
- Switches the lite tests (i.e., tests not in the nested folders for benchmarking but which nevertheless have 100% coverage) slightly to use
eval
to confirm they work in JS (except in the case of a reviver argument (whose tests I've confirmed are only necessary as far as coverage in checking the reviver) - Drops the stream and reviver tests and code so can check coverage related to eval. (I also have a
no-stream-coverage
branch which shows a few lines still uncovered by the non-stream tests and which I'm not 100% sure are stream related, but they seem to be)
**Note that there were also two tests which were expected to fail but would not fail in JS as they have a different meaning there and should understandably not be allowed:
{ a : 'no quote' [1] }
(because of array index).123-45
(because of being subtraction)