8000 Align program range/start/loc with other parsers · Issue #488 · eslint/js · GitHub
[go: up one dir, main page]

Skip to content
Align program range/start/loc with other parsers #488
@fisker

Description

@fisker
require('@babel/parser').parse('   /**/   a /**/      ', {ranges: true}).program

// {start:0, end: 22, range: [0, 22]}
require('acorn').parse('   /**/   a /**/      ', {ranges: true})
// {start:0, end: 22, range: [0, 22]}
require('meriyah').parse('   /**/   a /**/      ', {ranges: true})

// {start:0, end: 22, range: [0, 22]}
require('@typescript-eslint/typescript-estree').parse('   /**/   a /**/      ', {range: true})
// {range: [10, 22]}

(I think they are starting from 10 only to align with espree)

require('espree').parse('   /**/   a /**/      ', {range: true, loc: true})
// {range: [10, 11], start: 0, end: 22}  ({start: 10, end: 11} on master branch)

It doesn't make sense at all, if there is no statement, just comments and whitespace, what should it be?(currently we count from 0)

Image this, I have a function to check comment is inside node, isInsideNode(comment, node), If only comments, it's true, if I wrote a letter or number anywhere, it's false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0