lib/ast-utils
lib/ast-utils.js
Functions(6)
Collect every descendant of `node` whose `kind` equals `kind`.
Unconditional full descent -- does NOT stop at function-like boundaries.
Callers that need boundary-stopping behavior (e.g. "only look inside this
function, not nested ones") should use `findFirstDescendant` with a
predicate that encodes that boundary instead.
depth-first document order. Empty array if none found.
| Parameter | Type | Optional | Description |
|---|---|---|---|
node | import("typescript").Node | - Root node to search from. | |
kind | import("typescript").SyntaxKind | - The SyntaxKind to match. |
Returns:
import("typescript").Node[] — All matching descendants, inSignature
getDescendantsOfKind(node: any, kind: any): any
Depth-first search for the first descendant of `node` matching `predicate`.
Short-circuits on first match -- does not continue walking siblings/children
once found.
An optional `stopAt` predicate lets the caller prune descent into a
subtree (checked only when `predicate` did not already match on that same
node) -- e.g. to stop at nested function boundaries the way
`extractor.js`'s original `hasReturnWithValue` did. Omit it for
unconditional full descent.
a non-matching node, its children are not visited.
`undefined` if none found.
| Parameter | Type | Optional | Description |
|---|---|---|---|
node | import("typescript").Node | - Root node to search from. | |
predicate | (n: import("typescript").Node) => boolean | - Match test. | |
stopAt | (n: import("typescript").Node) => boolean | yes | - When true for |
Returns:
import("typescript").Node|undefined — The first matching node, orSignature
findFirstDescendant(node: any, predicate: any, stopAt: any): any
Narrow `node` to a class declaration, or return `null`.
Thin wrapper over `ts.isClassDeclaration` -- exists purely to cut the
`ts.isClassDeclaration(node) ? node : null` boilerplate at call sites.
| Parameter | Type | Optional | Description |
|---|---|---|---|
node | import("typescript").Node | - Node to test. |
Returns:
import("typescript").ClassDeclaration|null Signature
asClass(node: any): any
Narrow `node` to a function-like expression, or return `null`.
Matches exactly the set lib/extractor.js's own `isFunctionLike()` already
treats as function-like: arrow functions and function expressions (NOT
function declarations, which extractor.js handles as a separate case).
| Parameter | Type | Optional | Description |
|---|---|---|---|
node | import("typescript").Node | - Node to test. |
Returns:
import("typescript").ArrowFunction|import("typescript").FunctionExpression|null Signature
asFunctionLike(node: any): any