Comments are attached to wrong nodes as inner position
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 772
- PR merge metrics
- No merged PRs in 30d
Description
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"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the Esprima demo parse page using the supplied JavaScript and the “Attach comments” option. Trace comment attachment from that entry point and verify that comments are not duplicated or attached to the wrong nodes, with Comment 3 retained as the inner comment for its block.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100