public class NodeTraversal
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
NodeTraversal.AbstractModuleCallback
Abstract callback that knows when goog.provide, goog.module, and ES modules are entered and
exited.
|
static class |
NodeTraversal.AbstractPostOrderCallback
Abstract callback to visit all nodes in postorder.
|
static interface |
NodeTraversal.AbstractPostOrderCallbackInterface
Abstract callback to visit all nodes in postorder.
|
static class |
NodeTraversal.AbstractPreOrderCallback
Abstract callback to visit all nodes in preorder.
|
static class |
NodeTraversal.AbstractScopedCallback
Abstract scoped callback to visit all nodes in postorder.
|
static class |
NodeTraversal.AbstractShallowCallback
Abstract callback to visit all nodes but not traverse into function
bodies.
|
static class |
NodeTraversal.AbstractShallowStatementCallback
Abstract callback to visit all structure and statement nodes but doesn't traverse into
functions or expressions.
|
static interface |
NodeTraversal.Callback
Callback for tree-based traversals
|
static interface |
NodeTraversal.ChangeScopeRootCallback
Callback for passes that iterate over a list of change scope roots (FUNCTIONs and SCRIPTs)
|
static class |
NodeTraversal.ExternsSkippingCallback
Abstract callback to visit all non-extern nodes in postorder.
|
static interface |
NodeTraversal.ScopedCallback
Callback that also knows about scope changes
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
AbstractScope<?,?> |
getAbstractScope()
Gets the current scope.
|
int |
getCharno()
Gets the current char number, or zero if it cannot be determined.
|
AbstractScope<?,?> |
getClosestContainerScope() |
AbstractScope<?,?> |
getClosestHoistScope() |
Node |
getClosestHoistScopeRoot() |
AbstractCompiler |
getCompiler() |
ControlFlowGraph<Node> |
getControlFlowGraph()
Gets the control flow graph for the current JS scope.
|
Node |
getCurrentNode()
Returns the node currently being traversed.
|
Node |
getEnclosingFunction()
Examines the functions stack for the last instance of a function node.
|
CompilerInput |
getInput()
Gets the current input source.
|
int |
getLineNumber()
Gets the current line number, or zero if it cannot be determined.
|
JSModule |
getModule()
Gets the current input module.
|
Scope |
getScope() |
com.google.javascript.jscomp.ScopeCreator |
getScopeCreator() |
Node |
getScopeRoot()
Returns the current scope's root.
|
java.lang.String |
getSourceName()
Gets the current input source name.
|
TypedScope |
getTypedScope() |
boolean |
inFunctionBlockScope()
Determines whether the traversal is currently in the scope of the block of a function.
|
boolean |
inGlobalHoistScope()
Determines whether the hoist scope of the current traversal is global.
|
boolean |
inGlobalScope()
Determines whether the traversal is currently in the global scope.
|
boolean |
inModuleHoistScope()
Determines whether the hoist scope of the current traversal is global.
|
boolean |
inModuleScope()
Determines whether the traversal is currently in the global scope.
|
boolean |
isHoistScope() |
void |
report(Node n,
DiagnosticType diagnosticType,
java.lang.String... arguments)
Reports a diagnostic (error or warning)
|
void |
reportCodeChange() |
void |
reportCodeChange(Node n) |
static void |
traverse(AbstractCompiler compiler,
Node root,
NodeTraversal.Callback cb)
Traverses using the SyntacticScopeCreator
|
void |
traverse(Node root)
Traverses a parse tree recursively.
|
static void |
traverseChangedFunctions(AbstractCompiler compiler,
NodeTraversal.ChangeScopeRootCallback callback)
Traversal for passes that work only on changed functions.
|
void |
traverseFunctionOutOfBand(Node node,
AbstractScope<?,?> scope)
Traverse a function out-of-band of normal traversal.
|
static void |
traversePostOrder(AbstractCompiler compiler,
Node root,
NodeTraversal.AbstractPostOrderCallbackInterface cb)
Traverses in post order.
|
static void |
traverseRoots(AbstractCompiler compiler,
NodeTraversal.Callback cb,
Node externs,
Node root) |
static void |
traverseScopeRoots(AbstractCompiler compiler,
Node root,
java.util.List<Node> scopeNodes,
NodeTraversal.Callback cb,
boolean traverseNested)
Traverses *just* the contents of provided scope nodes (and optionally scopes nested within
them) but will fall back on traversing the entire AST from root if a null scope nodes list is
provided.
|
static void |
traverseScopeRoots(AbstractCompiler compiler,
Node root,
java.util.List<Node> scopeNodes,
NodeTraversal.Callback cb,
NodeTraversal.ChangeScopeRootCallback changeCallback,
boolean traverseNested)
Traverses *just* the contents of provided scope nodes (and optionally scopes nested within
them) but will fall back on traversing the entire AST from root if a null scope nodes list is
provided.
|
public NodeTraversal(AbstractCompiler compiler, NodeTraversal.Callback cb, com.google.javascript.jscomp.ScopeCreator scopeCreator)
public void traverse(Node root)
public static void traverse(AbstractCompiler compiler, Node root, NodeTraversal.Callback cb)
public static void traversePostOrder(AbstractCompiler compiler, Node root, NodeTraversal.AbstractPostOrderCallbackInterface cb)
public static void traverseRoots(AbstractCompiler compiler, NodeTraversal.Callback cb, Node externs, Node root)
public static void traverseScopeRoots(AbstractCompiler compiler, @Nullable Node root, @Nullable java.util.List<Node> scopeNodes, NodeTraversal.Callback cb, boolean traverseNested)
root
- If scopeNodes is null, this method will just traverse 'root' instead. If scopeNodes
is not null, this parameter is ignored.public static void traverseScopeRoots(AbstractCompiler compiler, @Nullable Node root, @Nullable java.util.List<Node> scopeNodes, NodeTraversal.Callback cb, @Nullable NodeTraversal.ChangeScopeRootCallback changeCallback, boolean traverseNested)
root
- If scopeNodes is null, this method will just traverse 'root' instead. If scopeNodes
is not null, this parameter is ignored.public void traverseFunctionOutOfBand(Node node, AbstractScope<?,?> scope)
node
- The function node.scope
- The scope the function is contained in. Does not fire enter/exit
callback events for this scope.public AbstractCompiler getCompiler()
public int getLineNumber()
public int getCharno()
public java.lang.String getSourceName()
public CompilerInput getInput()
public JSModule getModule()
public Node getCurrentNode()
public static void traverseChangedFunctions(AbstractCompiler compiler, NodeTraversal.ChangeScopeRootCallback callback)
Most changes are reported with calls to Compiler.reportCodeChange(), which doesn't know which scope changed. We keep track of the current scope by calling Compiler.setScope inside pushScope and popScope. The automatic tracking can be wrong in rare cases when a pass changes scope w/out causing a call to pushScope or popScope. Passes that do cross-scope modifications call Compiler.reportChangeToEnclosingScope(Node n).
public Node getEnclosingFunction()
public AbstractScope<?,?> getAbstractScope()
public boolean isHoistScope()
public Node getClosestHoistScopeRoot()
public AbstractScope<?,?> getClosestContainerScope()
public AbstractScope<?,?> getClosestHoistScope()
public Scope getScope()
public TypedScope getTypedScope()
public ControlFlowGraph<Node> getControlFlowGraph()
public Node getScopeRoot()
public com.google.javascript.jscomp.ScopeCreator getScopeCreator()
public boolean inGlobalScope()
public boolean inFunctionBlockScope()
public boolean inGlobalHoistScope()
public boolean inModuleScope()
public boolean inModuleHoistScope()
public void report(Node n, DiagnosticType diagnosticType, java.lang.String... arguments)
public void reportCodeChange()
public void reportCodeChange(Node n)
Copyright © 2009-2019 Google. All Rights Reserved.