-
Notifications
You must be signed in to change notification settings - Fork 15
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
JSON6 Superset of JavaScript #46
Comments
I concur - the one deviation I know is signficant is strings allow any unicode character until the same unescape ending quote.
Why wouldn't a user just expect a quote to continue? Why does any language absolutely break with \n as an early terminator?
do you expect to copy .c or .ts files into .js files and have them work? I mean... this ireally more like (in node) I do
|
oh ya I can't parse that... that's not a valid floating point number... where's the E? Techically in stream mode it would be 2 numbers |
You mean something like
Cool. Should I file an issue?
I guess because back-ticks are expected to come with evaluation ( const key = 'hello';
const Greeting = {
[key]: 'Hi!'
};
Greeting.hello === 'Hi!'; One could argue (or propose) about whether backticks here may better reuse an existing syntax, but:
ES could, if that's what you mean, but it doesn't currently.
Single ones are allowed, just not multiple sequential ones (in some contexts where allowed, would be interpreted as increment/decrement, but neither is allowable for numbers).
Sorry, I was mistaken, but it is still an incompatibility in ES mode. For numbers and strings, the support for allowing leading 0's, albeit as decimals, will give an error, i.e., substituting JSON6.parse with
I agree it would be a reasonable feature in JS (though some might argue it either interferes with the chance to adopt the symbols in the future for other purposes or that it visually makes it appear like some other opertor (e.g., subtraction for the allowance for hyphen) when used in a JS context). But just reporting here the incompatibilities with current ES.
Understood. Perhaps JS vendors would like to see the spec changed too if it may help in this regard. Insistence on optimizing speed in all possible areas might help in focused projects, and serve as good experience for systems to come to adopt, but interoperability is a huge benefit. Developers will not end up applying it in the wrong way because the syntax is already familiar, there will not be interoperability problems with porting code (except of course if going from JS to JSON6) or with tools that might be made to work with JSON6--allowing even naive tool makers, whose tools inevitably become a part of popular tool chains, are less likely to have a problem in working with such a well-known format.
I think JSON's popularity (and dethroning of XML) it in no small part due to the fact that it "just works" in JavaScript (esp. since the admitted line/paragraph separator issue has since been fixed as of ES 2019). With JavaScript being apparently the most widely deployed programming language, as well as being accessible to beginners, and being the only real option for client-side web use, while available for server-side-use, in browser extensions, some desktop apps, etc., it makes sense for a universal data format to interoperate with it without extra hassle. (FWIW, Just came across the proposer of JSON Superset arguing for this (as part of the now accepted proposal): https://github.com/tc39/proposal-json-superset#objections .) However, with the opportunity given by linting to enforce dropping quotes, etc., it becomes more compelling to have something like JSON6 which will also just work--without one being forced to add double quotes everywhere. If that is not your intent with this project, then sure, it's your call of course. |
Another difference (inspired by ota-meshi/eslint-plugin-jsonc#7 -- which is included in a new release of the jsonc plugin which already supports some JSON6 parsing, btw) is:
|
re: +Infinity is also an error.. while -Infinity works. (pretty sure it's not valid); and is processed in a separate part of the state engine than numbers. It's not hard to fix, added 1.0.9.js test; not sure how it works in a streaming mode... probably need a whitespace after the number and before a + to get the next. |
Although I don't think + should work, I added it... which finished breaking base64 encoding of JSOX; the upper characters were '+/' the '/' character is a control character for comments, so it requires quotes, and now + outside of processing a number also needs a quote. Reviewing that this was based off a huge amount of research, some of the expressions like 123+545 are expressions and not data values... a serializer would never emit that. I am reminded this, because in fixing (adding) import *.json6 support, a stop-gap that worked was to just add 'export default ' before whatever source .json6 file there was, because JSON6 is basically JS without any operator or functions |
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**:
eval
complains about this for strict mode..123e2-45
,.123e3-45
{a:'abc\ndef'}
(ok with backticks)//
commentMy suggested lines of action (besides documenting any remaining differences):
${...}
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
ornyc run nyc-lite
). This branch: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)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)The text was updated successfully, but these errors were encountered: