Giter Site home page Giter Site logo

Comments (8)

lo1tuma avatar lo1tuma commented on September 24, 2024

Related esprima issue

from espree.

nzakas avatar nzakas commented on September 24, 2024

Ah yes, I've run into this as well. I'll need to dig into the spec a bit to figure out the right thing to do (I'm not sure if ASI means the semicolon is inserted at the end of input in this case or immediately after the paren).

from espree.

btmills avatar btmills commented on September 24, 2024

This annoyed me as I was working on the token API, but I looked at the spec's rules for ASI, which seem to indicate that this is the correct behavior.

a semicolon is automatically inserted before the offending token

Then in an example,

{ 1
2 } 3

gets transformed into

{ 1
;2 ;} 3;

from espree.

btmills avatar btmills commented on September 24, 2024

And more relevant to this case in particular:

When, as the program is parsed from left to right, the end of the input stream of tokens is encountered and the parser is unable to parse the input token stream as a single complete ECMAScript Program, then a semicolon is automatically inserted at the end of the input stream.

(Emphasis mine)

from espree.

nzakas avatar nzakas commented on September 24, 2024

Thanks for the research, that matched up with my expectation. So it seems like we are doing the right thing in this case.

from espree.

lo1tuma avatar lo1tuma commented on September 24, 2024

Thanks for the clarification 🍻.

from espree.

aaronabramov avatar aaronabramov commented on September 24, 2024

is this still considered the right behavior?
https://github.com/jquery/esprima seems to not have this issue any more

a()



{
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 1,
            "column": 3
        }
    },
    "type": "Program",
    "body": [
        {
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 3
                }
            },
            "type": "ExpressionStatement",
            "expression": {
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 0
                    },
                    "end": {
                        "line": 1,
                        "column": 3
                    }
                },
                "type": "CallExpression",
                "callee": {
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 0
                        },
                        "end": {
                            "line": 1,
                            "column": 1
                        }
                    },
                    "type": "Identifier",
                    "name": "a"
                },
                "arguments": []
            }
        }
    ],
    "sourceType": "script"
}

from espree.

aaronabramov avatar aaronabramov commented on September 24, 2024

the problem that i found is that when comment option is set to true, the comment range overlaps with node ranges and it's very hard to identify where the comment belongs to
e.g.

// nodes
{
  type: 'Identifier',
  range: [20, 36]
}
/// comments
{
  type: 'Line',
  range: [25, 36]

from espree.

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.