Code Monkey home page Code Monkey logo

Comments (5)

Midar avatar Midar commented on September 25, 2024

Any news? It kinda sucks to get a different result depending on whether you use a JSON lib or eval(). I still suggest dropping newline support until this is fixed in ECMAScript.

from json5.

aseemk avatar aseemk commented on September 25, 2024

Good question and thanks for the nudge!

I haven't taken any action yet, but instead of dropping newline support altogether (I think there's value in keeping it, e.g. for a build tool where inconsistency between browsers isn't an issue), how about I just update the documentation to explicitly call out this behavior for now?

In particular, is it good enough if the documentation encourages only using newline support like this?

{
    this: "is a newline \
string where each newline backslash \
is preceded by a space, and \
each newline explicitly begins \
with *no* spaces."
}

Using newlines like this appears to work consistently across all browsers, and still adheres to the ES5 spec. Would that work for you?

Optionally or additionally, perhaps the compiler could warn or throw an error if it encounters newline usage not like this. But that might be unnecessary.

from json5.

aseemk avatar aseemk commented on September 25, 2024

Hey @Midar, sorry for the delay! But good news: this was fixed in V8 (to match other browsers and the ES5 spec) last year, and even Node actually seems to behave correctly when running in a file (rather than the REPL).

http://code.google.com/p/v8/issues/detail?id=2165

And indeed, the current multi-line string test case tests this behavior and passes in both Node and Chrome as well as Firefox. So I'm thinking the current behavior of this JSON5 implementation is just fine. Sound reasonable to you?

from json5.

aseemk avatar aseemk commented on September 25, 2024

Released in 0.2.0 FYI:

https://github.com/aseemk/json5/blob/develop/CHANGELOG.md#v020-code-diff

Edit: oops, what I meant was that I updated the readme example, at least, to put the whitespace before the newline rather than after. At least that will always work. But I'm pretty happy and confident now that the multi-line spec and implementation are both correct and consistent with every implementation out there now.

from json5.

Midar avatar Midar commented on September 25, 2024

I don't see any problem anymore now that node seems to be compatible to the rest, so yes, this can stay closed :).

from json5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.