RTI API Reference

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

optionsObject

Options for the annotator.

options.expandTypeimport('./parseJSDoc.js').ExpandType

Function to expand types.

Properties

import('./parseJSDoc.js').ExpandTypeexpandType #

import('@babel/types').Node[]parents #

Methods

annotate(ast) #

Annotates the AST by adding 'jsdoc' properties to relevant nodes.

Parameters

astimport('@babel/types').File|import('@babel/types').Program

The Babel AST to annotate.

Returns

import('@babel/types').File|import('@babel/types').Program

The annotated AST.

collectParamNames(paramNode, typeInfo, map) #

Recursively collects parameter names from a pattern with their types.

Parameters

paramNodeimport('@babel/types').PatternLike

The parameter node.

typeInfostring, object

The type information.

mapRecord.<string, (string|object)>

The map to collect into.

collectParamTypes(node) #

Collects the parameter names into a map of names to types.

Parameters

nodeimport('@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

nodeimport('@babel/types').Node

The starting node.

typestring

The type to search for.

Returns

import('@babel/types').Node|undefined

The ancestor node or undefined.

getJSDoc(node) #

Parses the JSDoc for a node.

Parameters

nodeimport('@babel/types').Node

The node.

Returns

Object, undefined

The parsed JSDoc.

getLeadingComment(node) #

Gets the leading comment string for a node.

Parameters

nodeimport('@babel/types').Node

The node.

Returns

string, undefined

The comment value.

getLeadingCommentsNodeForArrowFunctionExpression(node) #

Gets the leading comment node for ArrowFunctionExpression.

Parameters

nodeimport('@babel/types').Node

The node.

Returns

import('@babel/types').Node|undefined

The node with leading comments.

getLeadingCommentsNodeForFunctionExpression(node) #

Gets the leading comment node for FunctionExpression.

Parameters

nodeimport('@babel/types').Node

The node.

Returns

import('@babel/types').Node|undefined

The node with leading comments.

traverse(node) #

Traverses the AST node and annotates where applicable.

Parameters

nodeimport('@babel/types').Node

The node to traverse.