This checks whether or not we're in one of the following positions:
for (KEY in right); for (KEY;;);
This is because these spots allow VariableDeclarations AND normal expressions so we need to tell the path replacement that it's ok to replace this with an expression.
This checks whether we are swapping an arrow function's body between an expression and a block statement (or vice versa).
This is because arrow functions may implicitly return an expression, which is the same as containing a block statement.
Check whether the path node key
strict equals value
.
Walk the input node
and statically evaluate it.
Returns an object in the form { confident, value }
. confident
indicates
whether or not we had to drop out of evaluating the expression because of
hitting an unknown node that we couldn't confidently find the value of.
Example:
t.evaluate(parse("5 + 5")) // { confident: true, value: 10 } t.evaluate(parse("!true")) // { confident: true, value: false } t.evaluate(parse("foo + foo")) // { confident: false, value: undefined }
Walk the input node
and statically evaluate if it's truthy.
Returning true
when we're sure that the expression will evaluate to a
truthy value, false
if we're sure that it will evaluate to a falsy
value and undefined
if we aren't sure. Because of this please do not
rely on coercion when using this method and check with === if it's false.
Build an array of node paths containing the entire ancestry of the current node path.
NOTE: The current node path is included in this.
Get the parent function of the current path.
Get the source code associated with this node.
Walk up the tree until we hit a parent node path in a list.
Infer the type of the current NodePath
.
Check whether we have the input key
. If the key
references an array then we check
if the array has any items, otherwise we just check if it's falsy.
Hoist the current node to the highest scope possible and return a UID referencing it.
Alias of has
.
Check whether the current path references a completion record
Check the type against our stored internal type of the node. This is handy when a node has been removed yet we still internally know the type and need it to calculate node replacement.
Check whether or not the current key
allows either a single statement or block statement
so we can explode it if necessary.
Opposite of has
.
Match the current node if it matches the provided pattern
.
For example, given the match React.createClass
it would match the
parsed nodes of React.createClass
and React["createClass"]
.
Check if the currently assigned path references the importName
of moduleSource
.
Replace a node with an array of multiple. This method performs the following steps:
Parse a string as an expression and replace the current node with the result.
NOTE: This is typically not a good idea to use. Building source strings when transforming ASTs is an antipattern and SHOULD NOT be encouraged. Even if it's easier to use, your transforms will be extremely brittle.
Share comments amongst siblings.
Update all sibling node paths after fromIndex
by incrementBy
.
Check if the current path will maybe execute before another path
Give node
comments
of the specifiedtype
.