-
Notifications
You must be signed in to change notification settings - Fork 479
jscodeshift Documentation
TODO
NodePath
s (aka Path
s) wrap the actual AST node and provide information that is not available when looking at the node in isolation. Refer to ast-types for a more elaborate description.
The wrapped AST node's parent, wrapped in another NodePath
.
Scope information about the wrapped AST node. See ast-types for more info.
The wrapped AST node.
Same as node
A Collection
is a generic collection of NodePath
s. It only has a generic API to access and process the elements of the list. It doesn't know anything about AST types.
Returns a new collection containing the nodes for which the callback returns true
.
Executes callback for each node/path in the collection.
Executes the callback for every path in the collection and returns a new collection from the return values (which must be paths).
The callback can return null to indicate to exclude the element from the new collection.
If an array is returned, the array will be flattened into the result collection.
Returns the number of elements in this collection.
Returns an array of AST nodes in this collection.
Returns a new collection containing only the element at position index.
In case of a negative index, the element is taken from the end:
- .at(0) - first element
- .at(-1) - last element
Proxies to NodePath#get of the first path.
Returns true if this collection has the type 'type'.
Returns pretty printed JS code.
TODO
Find nodes of a specific type within the nodes of this collection.
Returns a collection containing the paths that create the scope of the currently selected paths. Dedupes the paths.
Traverse the AST up and finds the closest node of the provided type.
Finds the declaration for each selected path. Useful for member expressions or JSXElements. Expects a callback function that maps each path to the name to look for.
If the callback returns a falsey value, the element is skipped.
Simply replaces the selected nodes with the provided node. If a function is provided it is executed for every node and the node is replaced with the functions return value.
Inserts a new node before the current one.
Inserts a new node after the current one.
Removes all the paths in the current collection from the AST.
Finds all variable declarators, optionally filtered by name.
Returns a function that returns true if the provided path is a variable declarator and requires one of the specified module names.
Renames a variable and all its occurrences.
Finds all JSXElements optionally filtered by name
Finds all JSXElements by module name. Given
var Bar = require('Foo');
<Bar />
findJSXElementsByModuleName('Foo') will find , without having to know the variable name.
Filter method for attributes.
Filter elements which contain a specific child type
Returns all child nodes, including literals and expressions.
Returns all children that are JSXElements.
Given a JSXElement, returns its "root" name. E.g. it would return Foo
for both <Foo />
and <Foo.Bar />
.
TODO