Make comment node to normal node like others
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
### 💻
- [ ] Would you like to work on this feature?
### What problem are you trying to solve?
The current comment is a normal node, it cannot be traversed.
**leadingComments** and **trailingComments** behave very strangely.
the next node is `leadingComments` is the same as the previous node's `trailingComments`.
```js
const exp1 = 1 + 2 // foo
// new line
const exp2 = 3 + 4 // bar
```

If it is a normal node, there will be no such problem.
### Why am I concerned about this issue?
I'm writing a custom generator. Regarding how to generate annotated code, I found that the AST is not clear enough
### Describe the solution you'd like
Comments should be the same as other nodes(optional)
```json
[
{
"type": "VariableDeclaration"
...
},
{
"type": "CommentLine"
...
},
{
"type": "VariableDeclaration"
...
}
]
```
### Describe alternatives you've considered
none
### Documentation, Adoption, Migration Strategy
_No response_
Contributor guide
Research direction
Start by tracing how the AST represents and traverses leadingComments and trailingComments for the example with two variable declarations. The change would be complete when comments are represented as traversable CommentLine nodes alongside VariableDeclaration nodes, without the current duplicated attachment behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100