Skip to content

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

@not-an-aardvark

Description

@not-an-aardvark
// 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy