Asserter
Summary
Properties
| addLaterImportNamespaceSpecifier | |
| parent | |
| stats | |
| typedefs |
Methods
| ArrowFunctionExpression | We expand type-asserted ArrowFunctionExpressions in order to add type assertions. |
| BinaryExpression | |
| ClassDeclaration | |
| File | |
| findParentOfType | Finds the closest ancestor of the given node that matches the specified type. |
| generateTypeChecks | Generates a string containing type checks for a given Babel AST node based on associated JSDoc information. |
| getHeader | Alternatively "import * as rti from . |
| getJSDoc | |
| getLeadingComment | |
| getLeadingCommentsNodeForArrowFunctionExpression | Retrieves the node associated with the leading comments for an arrow function expression. |
| getName | |
| getNameForFunctionExpression | |
| getNameOfParam | Retrieves the name of a parameter from a Babel AST node. |
| getStatsForNode | Retrieves statistical information for a given Babel AST node of this instance. |
| ImportDeclaration | |
| ImportNamespaceSpecifier | |
| MemberExpression | |
| nodeHasParamName | Checks if a provided Babel AST node has a parameter with the given name. |
| VariableDeclaration | |
| warn | Emits a warning message to the console, optionally prefixed with the instance's filename. |
Details
Constructor
Properties
Methods
ArrowFunctionExpression(node) #
We expand type-asserted ArrowFunctionExpressions in order to add type assertions.
Parameters
| node | import("@babel/types").ArrowFunctionExpression | The Babel AST node. |
Returns
stringStringification of the node.
BinaryExpression(node) #
Parameters
| node | import("@babel/types").BinaryExpression | The Babel AST node. |
Returns
stringStringification of the node.
ClassDeclaration(node) #
Parameters
| node | import("@babel/types").ClassDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
File(node) #
Parameters
| node | import("@babel/types").File | The Babel AST node. |
Returns
stringStringification of the node.
findParentOfType(node, type) #
Finds the closest ancestor of the given node that matches the specified type.
Parameters
| node | Node | The starting node to search from. |
| type | T | Type name of the node to search for. |
Returns
Extract<Node, {type: T}>, undefinedThe first ancestor node of the specified type, or undefined if none is found.
generateTypeChecks(node) #
Generates a string containing type checks for a given Babel AST node based on associated JSDoc information.
This function analyzes the node and its JSDoc annotations to construct runtime type check expressions. It handles various parameter patterns and outputs code that performs actual type assertions. If a node does not correspond to any known or supported pattern, it returns an empty string.
Parameters
| node | Node | The Babel AST node for which to generate type checks. |
Returns
stringA string of code with type check assertions, based on the JSDoc comments associated with the given node.
getHeader() #
Alternatively "import * as rti from ..." would also prevent "Unused external imports" warning... or keeping log of every single call during RTI parsing.
Parameters
Returns
stringThe import declaration header for importing RTI.
getLeadingComment(node) #
Parameters
| node | Node | The Babel AST node. |
Returns
string, undefinedThe JSDoc comment of node.
getLeadingCommentsNodeForArrowFunctionExpression(node) #
Retrieves the node associated with the leading comments for an arrow function expression.
This method travels up the syntax tree from the given node to find a parent node with leading comments. This search is bounded by function boundaries or a 'CallExpression' node, as per the logic defined within the loop.
Parameters
| node | Node | The node representing the arrow function expression for which to find the leading comments node. |
Returns
Node, undefinedThe node that contains the leading comments, or undefined
if none is found before reaching a different function or 'CallExpression'.
getNameForFunctionExpression(node) #
Parameters
| node | Node | The Babel AST node. |
Returns
stringBest possible human-readable name of given node.
getNameOfParam(param) #
Retrieves the name of a parameter from a Babel AST node.
This function expects a node representing a function parameter and attempts to extract the parameter's name directly or from an AssignmentPattern.
Parameters
| param | Node | The AST node representing the function parameter from which to extract the name. |
Returns
stringThe name of the parameter as a string, or the parameter's source code if the extraction fails.
getStatsForNode(node) #
Retrieves statistical information for a given Babel AST node of this instance.
Parameters
| node | Node | The Babel AST node for which the statistical data is retrieved. |
Returns
StatAn object containing the statistical data for the specified node. If the node type is unhandled, defaults to returning a dummy object with 'checked' and 'unchecked' properties both set to 0.
ImportDeclaration(node) #
Parameters
| node | import("@babel/types").ImportDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ImportNamespaceSpecifier(node) #
Parameters
| node | import("@babel/types").ImportNamespaceSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
MemberExpression(node) #
Parameters
| node | import("@babel/types").MemberExpression | The Babel AST node. |
Returns
stringStringification of the node.
nodeHasParamName(node, name) #
Checks if a provided Babel AST node has a parameter with the given name.
This function will look at the node's parameters if available and determine whether one of them matches the provided name. Supports various parameter types such as Identifiers and AssignmentPatterns.
Parameters
| node | Node | The Babel AST node to inspect. If it's a BlockStatement, the parent node is used instead. |
| name | string | The name of the parameter to look for within the node's parameters. |
Returns
booleanTrue if the node has a parameter with the given name; false otherwise.