Class TypeCheck

java.lang.Object
com.google.javascript.jscomp.TypeCheck
All Implemented Interfaces:
CompilerPass, NodeTraversal.Callback

public class TypeCheck extends Object implements NodeTraversal.Callback, CompilerPass

Checks the types of JS expressions against any declared type information.

  • Field Details

    • OVERRIDING_PROTOTYPE_WITH_NON_OBJECT

      protected static final String OVERRIDING_PROTOTYPE_WITH_NON_OBJECT
      See Also:
    • NOT_A_CONSTRUCTOR

      protected static final DiagnosticType NOT_A_CONSTRUCTOR
  • Constructor Details

  • Method Details

    • process

      public void process(Node externsRoot, Node jsRoot)
      Main entry point for this phase of processing. This follows the pattern for JSCompiler phases.
      Specified by:
      process in interface CompilerPass
      Parameters:
      externsRoot - The root of the externs parse tree.
      jsRoot - The root of the input parse tree to be checked.
    • processForTesting

      public Scope processForTesting(Node externsRoot, Node jsRoot)
      Main entry point of this phase for testing code.
    • check

      public void check(Node node, boolean externs)
    • shouldTraverse

      public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
      Description copied from interface: NodeTraversal.Callback

      Visits a node in pre order (before visiting its children) and decides whether this node's children should be traversed. If children are traversed, they will be visited by NodeTraversal.Callback.visit(NodeTraversal, Node, Node) in post order.

      Implementations can have side effects (e.g. modifying the parse tree).

      Specified by:
      shouldTraverse in interface NodeTraversal.Callback
      Returns:
      whether the children of this node should be visited
    • visit

      public void visit(NodeTraversal t, Node n, Node parent)
      This is the meat of the type checking. It is basically one big switch, with each case representing one type of parse tree node. The individual cases are usually pretty straightforward.
      Specified by:
      visit in interface NodeTraversal.Callback
      Parameters:
      t - The node traversal object that supplies context, such as the scope chain to use in name lookups as well as error reporting.
      n - The node being visited.
      parent - The parent of the node n.