-
-
Notifications
You must be signed in to change notification settings - Fork 258
Diff in range data of Program vs other parsers for leading newline(s) #673
Comments
Hey @JamesHenry! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
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 `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. |
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
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
andtypescript-eslint-parser
(which behaves likeespree
/esprima
) for JS source fixtures.The diff essentially boils down to the inclusion of the leading newline (or not in the case of babylon):
I do have the ESTree plugin enabled, so I would theoretically expect to see parity here.
The text was updated successfully, but these errors were encountered: