JSDocAnnotator
Summary
Properties
| expandType | |
| parents | |
| typedefs |
Methods
| annotate | Annotates the AST by adding 'jsdoc' properties to relevant nodes. |
| collectParamNames | Recursively collects parameter names from a pattern with their types. |
| collectParamTypes | Collects the parameter names into a map of names to types. |
| findParentOfType | Finds the closest ancestor of the given node that matches the specified type. |
| getJSDoc | Parses the JSDoc for a node. |
| getLeadingComment | Gets the leading comment string for a node. |
| getLeadingCommentsNodeForArrowFunctionExpression | Gets the leading comment node for ArrowFunctionExpression. |
| getLeadingCommentsNodeForFunctionExpression | Gets the leading comment node for FunctionExpression. |
| traverse | Traverses the AST node and annotates where applicable. |
Details
Constructor
JSDocAnnotator([options]) #
Parameters
| options | Object | Options for the annotator. |
| options.expandType | import('./parseJSDoc.js').ExpandType | Function to expand types. |
Properties
Methods
annotate(ast) #
Annotates the AST by adding 'jsdoc' properties to relevant nodes.
Parameters
| ast | import('@babel/types').File|import('@babel/types').Program | The Babel AST to annotate. |
Returns
import('@babel/types').File|import('@babel/types').ProgramThe annotated AST.
collectParamNames(paramNode, typeInfo, map) #
Recursively collects parameter names from a pattern with their types.
Parameters
| paramNode | import('@babel/types').PatternLike | The parameter node. |
| typeInfo | string, object | The type information. |
| map | Record.<string, (string|object)> | The map to collect into. |
collectParamTypes(node) #
Collects the parameter names into a map of names to types.
Parameters
| node | import('@babel/types').ArrowFunctionExpression | import('@babel/types').FunctionDeclaration | import('@babel/types').FunctionExpression | import('@babel/types').ObjectMethod | import('@babel/types').ClassMethod | import('@babel/types').ClassPrivateMethod | The function-like node. |
Returns
Record.<string, (string|object)>The map of parameter names to types.
findParentOfType(node, type) #
Finds the closest ancestor of the given node that matches the specified type.
Parameters
| node | import('@babel/types').Node | The starting node. |
| type | string | The type to search for. |
Returns
import('@babel/types').Node|undefinedThe ancestor node or undefined.
getJSDoc(node) #
Parses the JSDoc for a node.
Parameters
| node | import('@babel/types').Node | The node. |
Returns
Object, undefinedThe parsed JSDoc.
getLeadingComment(node) #
Gets the leading comment string for a node.
Parameters
| node | import('@babel/types').Node | The node. |
Returns
string, undefinedThe comment value.
getLeadingCommentsNodeForArrowFunctionExpression(node) #
Gets the leading comment node for ArrowFunctionExpression.
Parameters
| node | import('@babel/types').Node | The node. |
Returns
import('@babel/types').Node|undefinedThe node with leading comments.
getLeadingCommentsNodeForFunctionExpression(node) #
Gets the leading comment node for FunctionExpression.
Parameters
| node | import('@babel/types').Node | The node. |
Returns
import('@babel/types').Node|undefinedThe node with leading comments.
traverse(node) #
Traverses the AST node and annotates where applicable.
Parameters
| node | import('@babel/types').Node | The node to traverse. |