-1

Esprima is a good library for parse, analyse for multi-purpose javascript code. But I am not understand loc and range in esprima. In the website, they said that:

  • loc Nodes have line and column-based location info.
  • range Nodes have an index-based location range (array)

I used example code to understand what it is.

var x = 42;
console.log(1);

And the result is :

"range": [
        0,
        27
    ],

Could you help me to understand range meaning.

Thanks and regards,

tkha
  • 3
  • 3
  • Looks like string indices in the input text to me. – Bergi Dec 08 '15 at 17:29
  • @Bergi You can view full AST tree in this [link](http://esprima.org/demo/parse.html?code=var%20x%20%3D%2042%3B%0Aconsole.log(1)%3B) and stick on Index-based range. – tkha Dec 09 '15 at 02:44
  • That page is broken for me. Try http://astexplorer.net/#/MrUNU1X4xg :-) – Bergi Dec 09 '15 at 02:53
  • @Bergi, I think range is index character in code. For example: `var x = 42;` then range is `[0,11]`. – tkha Dec 09 '15 at 03:11
  • That's what I said. The code is the input text to esprima. – Bergi Dec 09 '15 at 03:15

1 Answers1

0

Just be aware that Esprima loc and range isn't accurate for template nodes. It starts +1 from current index instead of 0. Just compare with either Acorn or Cherow and you see it yourself. Not sure for tagged templates.

Confused
  • 24
  • 2