Skip to main content

Module: util/nodeFinders

Functions

ancestorChainNodeFinder

ancestorChainNodeFinder(nodeToReturn, ...nodeFinders): (node: SyntaxNode) => null | SyntaxNode

Given a sequence of node finders, returns a new node finder which applies them in reverse, walking up the ancestor chain from node. Returns null if any finder in the chain returns null. For example:

ancestorChainNodeFinder(0, patternFinder("foo", "bar"), patternFinder("bongo"))

is equivalent to:

patternFinder("foo.bongo", "bar.bongo")

Parameters

NameTypeDescription
nodeToReturnnumberThe index of the node from the sequence to return. For example, 0 returns the top ancestor in the chain
...nodeFindersNodeFinder[]A list of node finders to apply in sequence

Returns

fn

A node finder which is a chain of the input node finders

▸ (node): null | SyntaxNode

Parameters
NameType
nodeSyntaxNode
Returns

null | SyntaxNode

Defined in

util/nodeFinders.ts:75


argumentNodeFinder

Const argumentNodeFinder(...parentTypes): NodeFinder

Parameters

NameType
...parentTypesstring[]

Returns

NodeFinder

Defined in

util/nodeFinders.ts:110


chainedNodeFinder

chainedNodeFinder(...nodeFinders): (node: SyntaxNode) => null | SyntaxNode

Given a list of node finders returns a new node finder which applies them in sequence returning null if any of the sequence returns null otherwise returning the output of the final node finder

Parameters

NameTypeDescription
...nodeFindersNodeFinder[]A list of node finders to apply in sequence

Returns

fn

A node finder which is a chain of the input node finders

▸ (node): null | SyntaxNode

Parameters
NameType
nodeSyntaxNode
Returns

null | SyntaxNode

Defined in

util/nodeFinders.ts:45


findPossiblyWrappedNode

findPossiblyWrappedNode(isWrapperNode, isTargetNode, getWrappedNodes): NodeFinder

Creates a matcher that can match potentially wrapped nodes. For example typescript export statements or python decorators

Parameters

NameTypeDescription
isWrapperNodeNodeFinderReturns node if the given node has the right type to be a wrapper node
isTargetNodeNodeFinderReturns node if the given node has the right type to be the target
getWrappedNodes(node: SyntaxNode) => (null | SyntaxNode)[]Given a wrapper node returns a list of possible target nodes

Returns

NodeFinder

A matcher that will return the given target node or the wrapper node, if it is wrapping a target node

Defined in

util/nodeFinders.ts:170


leadingSiblingNodeFinder

leadingSiblingNodeFinder(nodeFinder): (node: SyntaxNode) => null | SyntaxNode

Returns a new node finder which applies nodeFinder to the given node and then to each of its previous siblings in turn, returning the first one that is non null.

Parameters

NameTypeDescription
nodeFinderNodeFinderThe node finder to use

Returns

fn

A node finder

▸ (node): null | SyntaxNode

Parameters
NameType
nodeSyntaxNode
Returns

null | SyntaxNode

Defined in

util/nodeFinders.ts:20


nodeFinder

Const nodeFinder(isTargetNode): NodeFinder

Parameters

NameType
isTargetNode(node: SyntaxNode) => boolean

Returns

NodeFinder

Defined in

util/nodeFinders.ts:5


patternFinder

patternFinder(...patterns): NodeFinder

Parameters

NameType
...patternsstring[]

Returns

NodeFinder

Defined in

util/nodeFinders.ts:197


typedNodeFinder

Const typedNodeFinder(...typeNames): NodeFinder

Parameters

NameType
...typeNamesstring[]

Returns

NodeFinder

Defined in

util/nodeFinders.ts:104