Skip to content

Question about building a new Abstract Syntax Tree #108

Answered by wooorm
tinchoz49 asked this question in Q&A
Discussion options

You must be logged in to vote

Regardless of the a/b choice, I’d suggest having two children: Parameters and Body (same as estree).

Now, the Q is to place them in children or directly on a node.
One idea I’ve had is to use both: the nodes are in children but there are also getters (and setters?) defined for node.params to get the first child if it’s a Parameters node.
But what’s not so nice about that is that typically unist is JSON only: it can be serialized and parsed again and results in an equivalent tree. Getters/setters will break that.

For MDX, which includes JSX, I recently went with an attributes array, which includes nodes, and it also has normal children (for the content in those tags). Maybe you could do th…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@tinchoz49
Comment options

@wooorm
Comment options

@ChristianMurphy
Comment options

@tinchoz49
Comment options

@tinchoz49
Comment options

Comment options

You must be logged in to vote
1 reply
@tinchoz49
Comment options

Answer selected by ChristianMurphy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants