Class NodeTraversal


  • public class NodeTraversal
    extends java.lang.Object
    NodeTraversal allows an iteration through the nodes in the parse tree, and facilitates the optimizations on the parse tree.
    • Method Detail

      • traverseScopeRoots

        public static void traverseScopeRoots​(AbstractCompiler compiler,
                                              @Nullable
                                              Node root,
                                              @Nullable
                                              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.
        Parameters:
        root - If scopeNodes is null, this method will just traverse 'root' instead. If scopeNodes is not null, this parameter is ignored.
      • getSourceName

        public java.lang.String getSourceName()
        Gets the current input source name.
        Returns:
        A string that may be empty, but not null
      • getInput

        public CompilerInput getInput()
        Gets the current input source.
      • getChunk

        public JSChunk getChunk()
        Gets the current input module.
      • getCurrentNode

        public Node getCurrentNode()
        Returns the node currently being traversed.
      • getEnclosingFunction

        public Node getEnclosingFunction()
        Examines the functions stack for the last instance of a function node. When possible, prefer this method over NodeUtil.getEnclosingFunction() because this in general looks at less nodes.
      • getAbstractScope

        public AbstractScope<?,​?> getAbstractScope()
        Gets the current scope.
      • isHoistScope

        public boolean isHoistScope()
      • getClosestHoistScopeRoot

        public Node getClosestHoistScopeRoot()
      • getClosestContainerScope

        public AbstractScope<?,​?> getClosestContainerScope()
      • getClosestHoistScope

        public AbstractScope<?,​?> getClosestHoistScope()
      • getScope

        public Scope getScope()
      • getTypedScope

        public TypedScope getTypedScope()
      • getControlFlowGraph

        public ControlFlowGraph<Node> getControlFlowGraph()
        Gets the control flow graph for the current JS scope.
      • getScopeRoot

        public Node getScopeRoot()
        Returns the current scope's root.
      • getScopeCreator

        public com.google.javascript.jscomp.ScopeCreator getScopeCreator()
      • inGlobalScope

        public boolean inGlobalScope()
        Determines whether the traversal is currently in the global scope. Note that this returns false in a global block scope.
      • inModuleScope

        public boolean inModuleScope()
        Determines whether the traversal is currently in the global scope. Note that this returns false in a global block scope.
      • inGlobalOrModuleScope

        public boolean inGlobalOrModuleScope()
      • inFunctionBlockScope

        public boolean inFunctionBlockScope()
        Determines whether the traversal is currently in the scope of the block of a function.
      • inGlobalHoistScope

        public boolean inGlobalHoistScope()
        Determines whether the hoist scope of the current traversal is global.
      • inModuleHoistScope

        public boolean inModuleHoistScope()
        Determines whether the hoist scope of the current traversal is global.
      • report

        public void report​(Node n,
                           DiagnosticType diagnosticType,
                           java.lang.String... arguments)
        Reports a diagnostic (error or warning)
      • reportCodeChange

        public void reportCodeChange()
      • reportCodeChange

        public void reportCodeChange​(Node n)