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
| Name | Type | Description |
|---|---|---|
nodeToReturn | number | The index of the node from the sequence to return. For example, 0 returns the top ancestor in the chain |
...nodeFinders | NodeFinder[] | 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
| Name | Type |
|---|---|
node | SyntaxNode |
Returns
null | SyntaxNode
Defined in
util/nodeFinders.ts:75
argumentNodeFinder
▸ Const argumentNodeFinder(...parentTypes): NodeFinder
Parameters
| Name | Type |
|---|---|
...parentTypes | string[] |
Returns
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
| Name | Type | Description |
|---|---|---|
...nodeFinders | NodeFinder[] | 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
| Name | Type |
|---|---|
node | SyntaxNode |
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
| Name | Type | Description |
|---|---|---|
isWrapperNode | NodeFinder | Returns node if the given node has the right type to be a wrapper node |
isTargetNode | NodeFinder | Returns 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
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
| Name | Type | Description |
|---|---|---|
nodeFinder | NodeFinder | The node finder to use |
Returns
fn
A node finder
▸ (node): null | SyntaxNode
Parameters
| Name | Type |
|---|---|
node | SyntaxNode |
Returns
null | SyntaxNode
Defined in
util/nodeFinders.ts:20
nodeFinder
▸ Const nodeFinder(isTargetNode): NodeFinder
Parameters
| Name | Type |
|---|---|
isTargetNode | (node: SyntaxNode) => boolean |
Returns
Defined in
util/nodeFinders.ts:5
patternFinder
▸ patternFinder(...patterns): NodeFinder
Parameters
| Name | Type |
|---|---|
...patterns | string[] |
Returns
Defined in
util/nodeFinders.ts:197
typedNodeFinder
▸ Const typedNodeFinder(...typeNames): NodeFinder
Parameters
| Name | Type |
|---|---|
...typeNames | string[] |
Returns
Defined in
util/nodeFinders.ts:104