esprima
esprima copied to clipboard
Comments are attached to wrong nodes as inner position
Steps to reproduce:
- Use Esprima demo page: https://esprima.org/demo/parse.html
- Copy paste this code inside the editor
function a() {
var b = 5;
/* Comment1 */
}
/* Comment2 */
{
/* Comment 3 */
}
- Check option (checkbox) "Attach comments"
Expected output: All comments are trailing or leading with exception of the inner comment for "Comment 3"
Actual output:
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a"
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "b"
},
"init": {
"type": "Literal",
"value": 5,
"raw": "5"
}
}
],
"kind": "var",
"trailingComments": [
{
"type": "Block",
"value": " Comment1 ",
"range": [
32,
46
]
}
]
}
]
},
"generator": false,
"expression": false,
"async": false,
"trailingComments": [
{
"type": "Block",
"value": " Comment2 ",
"range": [
49,
63
]
}
]
},
{
"type": "BlockStatement",
"body": [],
"innerComments": [
{
"type": "Block",
"value": " Comment1 ",
"range": [
32,
46
]
},
{
"type": "Block",
"value": " Comment2 ",
"range": [
49,
63
]
},
{
"type": "Block",
"value": " Comment 3 ",
"range": [
69,
84
]
}
]
}
],
"sourceType": "script"
}