β¬ οΈ Back to Table of Contents
π getParentFunctionNode¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 1 |
| π¦ Imports | 2 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/util/getParentFunctionNode.ts
π¦ Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
Functions¶
getParentFunctionNode(node: TSESTree.Node): | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDecla⦶
Parameters:
nodeTSESTree.Node
Returns: | TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression
| null
Internal Comments:
// this shouldn't happen in correct code, but someone may attempt to parse bad code
// the parser won't error, so we shouldn't throw here
/* istanbul ignore next */
Code
export function getParentFunctionNode(
node: TSESTree.Node,
):
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression
| null {
let current = node.parent;
while (current) {
if (
current.type === AST_NODE_TYPES.ArrowFunctionExpression ||
current.type === AST_NODE_TYPES.FunctionDeclaration ||
current.type === AST_NODE_TYPES.FunctionExpression
) {
return current;
}
current = current.parent;
}
// this shouldn't happen in correct code, but someone may attempt to parse bad code
// the parser won't error, so we shouldn't throw here
/* istanbul ignore next */ return null;
}
Generated by Syntax Scribe