Class TypeCheck
- All Implemented Interfaces:
CompilerPass,NodeTraversal.Callback
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DiagnosticGroupstatic final DiagnosticTypestatic final DiagnosticTypestatic final DiagnosticType -
Constructor Summary
ConstructorsConstructorDescriptionTypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry) TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, @Nullable TypedScope topScope, @Nullable com.google.javascript.jscomp.TypedScopeCreator scopeCreator) -
Method Summary
Modifier and TypeMethodDescriptionvoidMain entry point for this phase of processing.processForTesting(Node externsRoot, Node jsRoot) Main entry point of this phase for testing code.booleanshouldTraverse(NodeTraversal t, Node n, Node parent) Visits a node in preorder (before its children) and decides whether the node and its children should be traversed.voidvisit(NodeTraversal t, Node n, Node parent) This is the meat of the type checking.
-
Field Details
-
INEXISTENT_PROPERTY
-
STRICT_INEXISTENT_PROPERTY
-
STRICT_INEXISTENT_UNION_PROPERTY
-
ES5_INHERITANCE_DIAGNOSTIC_GROUP
-
-
Constructor Details
-
TypeCheck
public TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, @Nullable TypedScope topScope, @Nullable com.google.javascript.jscomp.TypedScopeCreator scopeCreator) -
TypeCheck
public TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry)
-
-
Method Details
-
process
Main entry point for this phase of processing. This follows the pattern for JSCompiler phases.- Specified by:
processin interfaceCompilerPass- Parameters:
externsRoot- The root of the externs parse tree.jsRoot- The root of the input parse tree to be checked.
-
processForTesting
Main entry point of this phase for testing code.- Parameters:
externsRoot- may be null or a ROOT node. If null the externs are not typechecked. Note: the externs node must always exist in the AST, even if not typechecked.jsRoot- must be a ROOT node and the second child of the global ROOT.
-
shouldTraverse
Description copied from interface:NodeTraversal.CallbackVisits a node in preorder (before its children) and decides whether the node and its children should be traversed.If this method returns true, the node will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)in postorder and its children will be visited by bothNodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)in preorder and byNodeTraversal.Callback.visit(NodeTraversal, Node, Node)in postorder.If this method returns false, the node will not be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)and its children will neither be visited byNodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)norNodeTraversal.Callback.visit(NodeTraversal, Node, Node).Siblings are always visited left-to-right.
Implementations can have side-effects (e.g. modify the parse tree). Removing the current node is legal, but removing or reordering nodes above the current node may cause nodes to be visited twice or not at all.
- Specified by:
shouldTraversein interfaceNodeTraversal.Callback- Parameters:
t- The current traversal.n- The current node.parent- The parent of the current node.- Returns:
- whether the children of this node should be visited
-
visit
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:
visitin interfaceNodeTraversal.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.
-