Search code examples
babeljsabstract-syntax-treejsdoc

Babel (@babel/types) JSDoc ast, where are the typings?


Looking at AST explorer, JSDoc comments are parsed into a nice domain specific AST. Example:

https://astexplorer.net/#/gist/72b1e9eb9b8e91a5bcf0af8eb281788c/c6944194a73654cf234ad79a004558ca8e67e286

So the following code:

/**
 * @mytag Test comment
 */
const X = 1

Looks something like this parsed:

VariableStatement
|- declarationList... (irrelevant)
|- jsDoc
   |- JSDocComment
      |- tags
         |-JSDocCommentTag

Now in the package @babel/types there are no factories for jsDoc nodes also no ast node has a jsDoc field like on astexplorer.net

What is the situation with this? I'd like to construct ast nodes with JSDoc tags. Does typings+factories live in separate package?


Solution

  • The ASTExplorer link has the Typescript parser enabled, not Babel's. Typescript parses JSDoc comments, because Typescript lets you use JSDoc annotations for types.