Package com.google.javascript.jscomp
Class NodeTraversal
java.lang.Object
com.google.javascript.jscomp.NodeTraversal
NodeTraversal allows an iteration through the nodes in the parse tree,
and facilitates the optimizations on the parse tree.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Abstract callback to visit a pruned set of nodes.static class
Abstract callback to visit all nodes in post order.static class
Abstract scoped callback to visit all nodes in post order.static class
Abstract callback to visit all nodes but not traverse into function bodies.static class
Abstract callback to visit all structure and statement nodes but doesn't traverse into functions or expressions.static interface
Callbackstatic interface
Callback that also knows about scope changes -
Field Summary
-
Constructor Summary
ConstructorDescriptionNodeTraversal
(AbstractCompiler compiler, NodeTraversal.Callback cb) Creates a node traversal using the specified callback interface.NodeTraversal
(AbstractCompiler compiler, NodeTraversal.Callback cb, com.google.javascript.jscomp.ScopeCreator scopeCreator) Creates a node traversal using the specified callback interface and the scope creator. -
Method Summary
Modifier and TypeMethodDescriptionGets the compiler.com.google.javascript.jscomp.ControlFlowGraph<Node>
Gets the control flow graph for the current JS scope.Returns the node currently being traversed.Examines the functions stack for the last instance of a function node.getInput()
Gets the current input source.int
Gets the current line number, or zero if it cannot be determined.Gets the current input module.getScope()
Gets the current scope.Returns the current scope's root.Gets the current input source name.boolean
hasScope()
makeError
(Node n, CheckLevel level, DiagnosticType type, String... arguments) Creates a JSError during NodeTraversal.makeError
(Node n, DiagnosticType type, String... arguments) Creates a JSError during NodeTraversal.void
report
(Node n, DiagnosticType diagnosticType, String... arguments) Reports a diagnostic (error or warning)static void
traverse
(AbstractCompiler compiler, Node root, NodeTraversal.Callback cb) Traverses a node recursively.void
Traverses a parse tree recursively.protected void
traverseInnerNode
(Node node, Node parent, Scope refinedScope) Traverses an inner node recursively with a refined scope.static void
traverseRoots
(AbstractCompiler compiler, NodeTraversal.Callback cb, Node... roots) static void
traverseRoots
(AbstractCompiler compiler, List<Node> roots, NodeTraversal.Callback cb) Traverses a list of node trees.void
traverseRoots
(Node... roots) void
traverseRoots
(List<Node> roots)
-
Field Details
-
NODE_TRAVERSAL_ERROR
-
-
Constructor Details
-
NodeTraversal
Creates a node traversal using the specified callback interface. -
NodeTraversal
public NodeTraversal(AbstractCompiler compiler, NodeTraversal.Callback cb, com.google.javascript.jscomp.ScopeCreator scopeCreator) Creates a node traversal using the specified callback interface and the scope creator.
-
-
Method Details
-
traverse
Traverses a parse tree recursively. -
traverseRoots
-
traverseRoots
-
traverseInnerNode
Traverses an inner node recursively with a refined scope. An inner node may be any node with a nonnull
parent (i.e. all nodes except the root).- Parameters:
node
- the node to traverseparent
- the node's parent, it may not benull
refinedScope
- the refined scope of the scope currently at the top of the scope stack or in trivial cases that very scope ornull
-
getCompiler
Gets the compiler. -
getLineNumber
public int getLineNumber()Gets the current line number, or zero if it cannot be determined. The line number is retrieved lazily as a running time optimization. -
getSourceName
Gets the current input source name.- Returns:
- A string that may be empty, but not null
-
getInput
Gets the current input source. -
getModule
Gets the current input module. -
getCurrentNode
Returns the node currently being traversed. -
traverse
Traverses a node recursively. -
traverseRoots
public static void traverseRoots(AbstractCompiler compiler, List<Node> roots, NodeTraversal.Callback cb) Traverses a list of node trees. -
traverseRoots
public static void traverseRoots(AbstractCompiler compiler, NodeTraversal.Callback cb, Node... roots) -
getEnclosingFunction
Examines the functions stack for the last instance of a function node. -
getScope
Gets the current scope. -
getControlFlowGraph
Gets the control flow graph for the current JS scope. -
getScopeRoot
Returns the current scope's root. -
hasScope
public boolean hasScope() -
report
Reports a diagnostic (error or warning) -
makeError
Creates a JSError during NodeTraversal.- Parameters:
n
- Determines the line and char position within the source file nametype
- The DiagnosticTypearguments
- Arguments to be incorporated into the message
-
makeError
Creates a JSError during NodeTraversal.- Parameters:
n
- Determines the line and char position within the source file nametype
- The DiagnosticTypearguments
- Arguments to be incorporated into the message
-