Dispatches a node to its specific visit<NodeType>/visit_<NodeType>
method if one is defined on the instance, falling back to
NodeVisitor.genericVisit otherwise.
The AST node to visit.
Whatever the matched visitor method (or genericVisit)
returns; the base implementation imposes no fixed return type since
subclasses may return arbitrary values from their visit methods.
Default transform behavior used when a subclass has not defined a
visit<NodeType>/visit_<NodeType> method for node's type: it
shallow-clones node and replaces each child (found by scanning own
properties for arrays/objects that look like AST nodes) with the
result of visiting it via NodeVisitor.visit. Array children
whose visited result is itself an array are spliced in flattened;
null/undefined results are dropped from arrays.
The AST node to clone and transform.
A new node of the same shape as node with its children
replaced by their transformed results.
A NodeVisitor subclass that can rewrite an AST while walking it, mirroring Python's
ast.NodeTransformer.Like
NodeVisitor, subclasses definevisit<NodeType>/visit_<NodeType>methods for the node types they want to transform. A visitor method should return: the (possibly modified) node to replace the original with, an array of nodes to splice in its place, ornull/undefinedto drop the node entirely. Node types without a matching method fall back to NodeTransformer.genericVisit, which shallow-clones the node and recursively transforms its children, leaving nodes without children unchanged.Example