jscodeshift-paths-in-range
A predicate for jscodeshift
Collection.filter
that only includes paths in the given source code range.
This is for building IDE codemod extensions that operate on the selected code/cursor position in an editor.
More specifically:
- If any paths are wholly contained within the range, use them (but not paths inside them)
- Otherwise, pick the topmost node that fully contains the range
pathsInRange(start: number, end: number = start)
Returns a predicate for Collection.filter
.
Arguments
start
- the index of the start of the range within the source codeend
- the index of the end of the range within the source code (defaults tostart
)
Example
const j = jscodeshift // editor is an example interface to a text editor in an IDE.
pathsIntersectingRange(start: number, end: number = start)
The only difference between this and pathsInRange
is it will include nodes that
extend beyond start
or end
.
Returns a predicate for Collection.filter
.
Arguments
start
- the index of the start of the range within the source codeend
- the index of the end of the range within the source code (defaults tostart
)