oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
10.97k stars 402 forks source link

ast: improve AST node documentation #2803

Closed Boshen closed 1 month ago

Boshen commented 6 months ago

While I was working with syn, I found the documentation on AST nodes really helpful, we should do the same.

https://docs.rs/syn/latest/syn/index.html#structs

rzvxa commented 6 months ago

On this subject, one thing that makes me struggle is that I can't find a clear way to get AstNode from a given ast struct/enum. How should it be done? I guess it is possible to search for it through the nodes but I was looking for a faster way.


Edit

I'm looking for a way to get either AstNode or the AstNodeId for a given expression(or any other AST type for that matter).

rzvxa commented 6 months ago

Is it possible to add the ast_node_id to every AST node referencable via an AstNode? It can be stored in a cell similar to identifiers so we can assign them in the semantic.

It will make getting the node's parent, etc easier and would eliminate the need to pass reference on enter_node and leave_node while also providing a way to access the AstNode in VisitMut, Both enter and leave events can pass the AstNodeId instead of AstNode, and we can also access the AstNode easily within our visit methods.

Right now I can't see any clear way to access an AstNode from its let's say expression, statement, etc.

Having AstNodeId on the struct itself would also allow us to get rid of the AstNode structure and make the AstNodes struct SOA.

Boshen commented 6 months ago

The requirement for ast_node_id has been brought up a couple times in the past, I think it's worthy to create a separate issue, bike-shed it and then implement it.

re-taro commented 3 months ago

We're working on it...