Diff in range data of Program vs other parsers for leading newline(s)
JamesHenry opened this issue Β· comments
Eurgh...
I am honestly not sure on what to suggest to address this, but if you take this really simple source (the leading newline is key but not that clear in the codeblock):
Input Code
function foo() {
}
You end up with different range data for the Program
node across the different parsers.
Please see: http://astexplorer.net/#/gist/c336be172990d7b467d1ed3dbc1882ee/215640e9e6eece750582ef00b16a884a5c66530a
...and take a look at the different parsers.
I found this when running AST comparison tests between babylon
and typescript-eslint-parser
(which behaves like espree
/esprima
) for JS source fixtures.
The diff essentially boils down to the inclusion of the leading newline (or not in the case of babylon):
"column": 0,
"line": 1,
},
},
"range": Array [
- 1,
+ 0,
28,
],
"sourceType": "script",
"type": "Program",
}
I do have the ESTree plugin enabled, so I would theoretically expect to see parity here.
Hey @JamesHenry! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.
Same thing with leading comments:
/* foo */
if (/* bar */ a) {}
It appears Espree, Esprima, Flow and Recast have one view of the world, Acorn and Babylon have another.
Espree:
{
"type": "Program",
"start": 0,
"end": 31,
"range": [
10,
30
],
...
Esprima:
{
"type": "Program",
"range": [
10,
30
]
...
Flow:
{
"type": "Program",
"range": [
10,
30
],
...
Recast:
{
"type": "Program",
"range": [
10,
30
],
...
Acorn:
{
"type": "Program",
"start": 0,
"end": 31,
"range": [
0,
31
],
...
Babylon:
{
"type": "Program",
"start": 0,
"end": 31,
"range": [
0,
31
],
...
It seems the same groupings of parsers hold true for observed differences in TemplateLiteral.quasis
location data too...
`42`;
Espree:
{
"quasis": [{
"type": "TemplateElement",
"start": 1, // This combined with the range seems like a bug?
"end": 3, // This combined with the range seems like a bug?
"range": [
0,
4
],
...
Esprima:
{
"quasis": [{
"type": "TemplateElement",
"range": [
0,
4
],
...
Flow:
{
"quasis": [{
"type": "TemplateElement",
"range": [
0,
4
],
...
Recast:
{
"quasis": [{
"type": "TemplateElement",
"range": [
0,
4
],
...
Acorn:
{
"quasis": [{
"type": "TemplateElement",
"start": 1,
"end": 3,
"range": [
1,
3
],
...
Babylon:
{
"quasis": [{
"type": "TemplateElement",
"start": 1,
"end": 3,
"range": [
1,
3
],
...
This issue has been moved to babel/babel#6681.