Skip to main content

Module: util/nodeMatchers

Functions

ancestorChainNodeMatcher

ancestorChainNodeMatcher(nodeFinders, nodeToReturn?, selector?): NodeMatcher

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

ancestorChainNodeMatcher([patternFinder("foo", "bar"), patternFinder("bongo")], 0)

is equivalent to:

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

Parameters

NameTypeDefault valueDescription
nodeFindersNodeFinder[]undefinedA list of node finders to apply in sequence
nodeToReturnnumber0The index of the node from the sequence to return. For example, 0 returns the top ancestor in the chain
selectorSelectionExtractorsimpleSelectionExtractorThe selector to apply to the final node

Returns

NodeMatcher

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

Defined in

util/nodeMatchers.ts:89


argumentMatcher

argumentMatcher(...parentTypes): NodeMatcher

Parameters

NameType
...parentTypesstring[]

Returns

NodeMatcher

Defined in

util/nodeMatchers.ts:108


cascadingMatcher

cascadingMatcher(...matchers): NodeMatcher

Create a new matcher that will try the given matchers in sequence until one returns non-null

Parameters

NameTypeDescription
...matchersNodeMatcher[]A list of matchers to try in sequence until one doesn't return null

Returns

NodeMatcher

A NodeMatcher that tries the given matchers in sequence

Defined in

util/nodeMatchers.ts:158


chainedMatcher

chainedMatcher(finders, selector?): NodeMatcher

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

Parameters

NameTypeDefault valueDescription
findersNodeFinder[]undefined-
selectorSelectionExtractorsimpleSelectionExtractorThe selector to apply to the final node

Returns

NodeMatcher

A matcher which is a chain of the input node finders

Defined in

util/nodeMatchers.ts:50


conditionMatcher

conditionMatcher(...patterns): NodeMatcher

Parameters

NameType
...patternsstring[]

Returns

NodeMatcher

Defined in

util/nodeMatchers.ts:115


createPatternMatchers

createPatternMatchers(nodeMatchers): Record<SimpleScopeTypeType, NodeMatcher>

Parameters

NameType
nodeMatchersPartial<Record<SimpleScopeTypeType, NodeMatcherAlternative>>

Returns

Record<SimpleScopeTypeType, NodeMatcher>

Defined in

util/nodeMatchers.ts:178


leadingMatcher

leadingMatcher(patterns, delimiters?): NodeMatcher

Given patterns, creates a node matcher that will add leading delimiter to removal range.

Parameters

NameTypeDefault valueDescription
patternsstring[]undefinedPatterns for pattern finder
delimitersstring[][]-

Returns

NodeMatcher

A node matcher

Defined in

util/nodeMatchers.ts:125


matcher

matcher(finder, selector?): NodeMatcher

Parameters

NameTypeDefault value
finderNodeFinderundefined
selectorSelectionExtractorsimpleSelectionExtractor

Returns

NodeMatcher

Defined in

util/nodeMatchers.ts:25


notSupported

Const notSupported(selection, node): null | NodeMatcherValue[]

Parameters

NameType
selectionSelectionWithEditor
nodeSyntaxNode

Returns

null | NodeMatcherValue[]

Defined in

util/nodeMatchers.ts:171


patternMatcher

patternMatcher(...patterns): NodeMatcher

Parameters

NameType
...patternsstring[]

Returns

NodeMatcher

Defined in

util/nodeMatchers.ts:104


trailingMatcher

trailingMatcher(patterns, delimiters?): NodeMatcher

Given patterns, creates a node matcher that will add trailing delimiter to removal range.

Parameters

NameTypeDefault valueDescription
patternsstring[]undefinedPatterns for pattern finder
delimitersstring[][]-

Returns

NodeMatcher

A node matcher

Defined in

util/nodeMatchers.ts:141


typeMatcher

typeMatcher(...typeNames): NodeMatcher

Parameters

NameType
...typeNamesstring[]

Returns

NodeMatcher

Defined in

util/nodeMatchers.ts:100