Code Monkey home page Code Monkey logo

Comments (12)

mishoo avatar mishoo commented on July 19, 2024

It was discussed some time back in UglifyJS too. My decision was to not support such comment style.

from acorn.

mathiasbynens avatar mathiasbynens commented on July 19, 2024

@mishoo Why?

from acorn.

mishoo avatar mishoo commented on July 19, 2024

Found it by Google: mishoo/UglifyJS#346

@mathiasbynens I might reconsider if there's enough interest, but right now I feel it's uselessly complicating the lexer.

Edit: @getify — nope, your example doesn't make me change my mind… should it?

from acorn.

getify avatar getify commented on July 19, 2024

[edit: moving my uglifyjs questions to the uglifyjs repo :)]

from acorn.

mishoo avatar mishoo commented on July 19, 2024

@getify my decision is based on the fact that ES5 doesn't define such comment format, and the syntax of this language is already awfully complex. Every little thing, no matter how insignificant, just adds to the mess. I don't even wanna think about parsing ES6 yet… :-(

But we're discussing this on Acorn's issue tracker. Let's see what @marijnh has to say. :-) If he decides to implement it in Acorn, that'll weight more for me than “popular demand”.

from acorn.

getify avatar getify commented on July 19, 2024

It's apparently slated to standardize in ES6: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-B.1.3

from acorn.

marijnh avatar marijnh commented on July 19, 2024

Can anyone give some background on where this bizarre convention came from? A bug that was canonized as standard? Treating <!-- to --> as a block comment, I could understand, but treating both as line comment markers is just... crazy.

from acorn.

mishoo avatar mishoo commented on July 19, 2024

treating both as line comment markers is just... crazy.

I concur on that feeling. The reason must be that --> is encountered frequently as a valid construct, i.e. while (x-->0) … so a block comment would end in the wrong place anyway. But this kinda makes the whole thing a nonsense.

Any case, I implemented it in UglifyJS2. The fact that V8 supports the syntax is too strong a reason...

from acorn.

ljharb avatar ljharb commented on July 19, 2024

@marijnh because really old browsers (Netscape 1.0 I think) didn't understand <script> tags, and at the time, this was the only way to get JS to work in the "modern" browsers while still supporting the "older" ones.

What I don't understand is why it needed to be supported in any context besides a <script> tag - but since it is…

from acorn.

mathiasbynens avatar mathiasbynens commented on July 19, 2024

Note that --> is only a line comment marker if it is the first thing on the line, optionally preceded by only whitespace or multi-line comments.

from acorn.

mathiasbynens avatar mathiasbynens commented on July 19, 2024

What I don't understand is why it needed to be supported in any context besides a <script> tag - but since it is…

Because doing so would needlessly complicate JavaScript engines even more.

from acorn.

marijnh avatar marijnh commented on July 19, 2024

I guess it grew out of a very crude strategy to deal with the old hack of putting <!-- and --> around the content of script tags to deal with non-script-supporting browsers, then?

I think attached patch should solve the issue. Though I am still puzzled how anyone would still want to be relying on this behavior.

from acorn.

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.