Skip to content
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

Range information is inconsistent for Program nodes with leading whitespace #349

Closed
not-an-aardvark opened this issue Jul 24, 2017 · 8 comments

Comments

@not-an-aardvark
Copy link
Member

// espree 3.4.3

require('espree').parse('/* foo */ bar /* baz */', { range: true })
Output
{
  "type": "Program",
  "start": 0,
  "end": 23,
  "range": [
    10,
    13
  ],
  "body": [
    {
      "type": "ExpressionStatement",
      "start": 10,
      "end": 13,
      "range": [
        10,
        13
      ],
      "expression": {
        "type": "Identifier",
        "start": 10,
        "end": 13,
        "range": [
          10,
          13
        ],
        "name": "bar"
      }
    }
  ],
  "sourceType": "script"
}

The Program node has start: 0 and end: 23, but its range is [10, 13].

This happens because espree transforms the range property to match Esprima's behavior. The transformation is correct, but we should also update the start and end properties, since they're equivalent in all other cases.

@JamesHenry
Copy link
Member

JamesHenry commented Oct 23, 2017

Ah I didn't originally see this issue, but see mine in babylon @babel/parser for more comparisons:

babel/babylon#673

(Was auto-migrated to) babel/babel#6681

@platinumazure
Copy link
Member

@not-an-aardvark Is this still an issue?

@fisker
Copy link
Contributor

fisker commented Nov 19, 2020

Is this going to get fixed?

@nzakas
Copy link
Member

nzakas commented Nov 24, 2020

@fisker can you confirm that this is still an issue?

@fisker
Copy link
Contributor

fisker commented Nov 24, 2020

Yes, I'm sure, I found this during working on Prettier, flow and espree are different from other parsers, so I filed issue on flow facebook/flow#8537, and comment here.

@mdjermanovic
Copy link
Member

TemplateElement nodes also have start and end different from range.

@nzakas
Copy link
Member

nzakas commented Nov 25, 2020

This is already marked as accepted, so any volunteers? 😄

@anikethsaha
Copy link
Member

I am working on this. This should probably be a breaking change.

anikethsaha added a commit to anikethsaha/espree that referenced this issue Dec 4, 2020
@nzakas nzakas added the breaking label Dec 4, 2020
@nzakas nzakas added this to Needs Triage in Triage via automation Apr 16, 2021
@nzakas nzakas moved this from Needs Triage to Pull Request Opened in Triage Apr 16, 2021
@nzakas nzakas closed this as completed in dffb7aa Apr 28, 2021
Triage automation moved this from Pull Request Opened to Complete Apr 28, 2021
nzakas added a commit that referenced this issue Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

8 participants