-
Hi everyone, I'm working on build an Abstract Syntax Tree for JSDoc and I got the next situation problem: I have this js file: /**
* @param {number} a
* @param {number} b
* @returns {number}
*/
function sum (a, b) {
return a + b
} I parse the syntax and then I have a node like:
Now my question is: should I define the Example 1:
Example 2:
Thank you!! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Interesting! I’m currently working with estree (the de facto JS AST). What’s your reason for making a unist based JS tree instead of estree? I’ve also thought about it. And indeed: programming languages have different places, not just “children”. Whereas content (XML, HTML, Markdown) typically only have “children”. |
Beta Was this translation helpful? Give feedback.
-
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 For MDX, which includes JSX, I recently went with an |
Beta Was this translation helpful? Give feedback.
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 fornode.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 normalchildren
(for the content in those tags). Maybe you could do th…