@@ -0,0 +1,3154 @@
+/*%0A * Copyright 2017 The Closure Compiler Authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.google.javascript.jscomp;%0A%0Aimport com.google.javascript.jscomp.NodeTraversal.Callback;%0Aimport com.google.javascript.rhino.Node;%0A%0A/** A simple pass to ensure that all AST nodes that are expressions have types */%0Aclass TypeInfoCheck implements Callback, CompilerPass %7B%0A  private final AbstractCompiler compiler;%0A  private boolean requiresTypes = false;%0A%0A  TypeInfoCheck(AbstractCompiler compiler) %7B%0A    this.compiler = compiler;%0A  %7D%0A%0A  public void setCheckSubTree(Node root) %7B%0A    requiresTypes = true;%0A    NodeTraversal.traverseEs6(compiler, root, this);%0A  %7D%0A%0A  @Override%0A  public void process(Node externs, Node root) %7B%0A    requiresTypes = false;%0A    NodeTraversal.traverseEs6(compiler, root, this);%0A  %7D%0A%0A  @Override%0A  public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent) %7B%0A    if (n.isScript()) %7B%0A      // Each JavaScript file is rooted in a script node, so we'll only%0A      // have type information inside the script node.%0A      requiresTypes = true;%0A    %7D else if (n.isParamList()) %7B%0A      // typeI information is not included for children of PARAM_LIST,%0A      // so we turn off requireTypes for these nodes.%0A      requiresTypes = false;%0A    %7D%0A    return true;%0A  %7D%0A%0A  @Override%0A  public void visit(NodeTraversal nodeTraversal, Node n, Node parent) %7B%0A    if (n.isScript()) %7B%0A      requiresTypes = false;%0A    %7D else if (requiresTypes && shouldHaveTypeInformation(n)) %7B%0A      if (n.isString() && (parent.isGetProp() %7C%7C parent.isGetElem())) %7B%0A        return;%0A      %7D%0A      if (n.isParamList()) %7B%0A        requiresTypes = true;%0A        return;%0A      %7D%0A      if (n.isName() && parent.isFunction()) %7B%0A        // function names does not need to have type information.%0A        return;%0A      %7D%0A      if (n.getTypeI() == null) %7B%0A        throw new IllegalStateException(%0A            %22No type information associated with %22%0A                + n%0A                + %22 Most likely a Node has been created after type checking%22%0A                + %22 without setting the type.%22);%0A      %7D%0A    %7D%0A  %7D%0A%0A  private static boolean shouldHaveTypeInformation(Node node) %7B%0A    switch (node.getToken()) %7B%0A      case EMPTY:%0A      case BLOCK:%0A      case BREAK:%0A      case CLASS:%0A      case CONST:%0A      case CONTINUE:%0A      case DEBUGGER:%0A      case DO:%0A      case EXPR_RESULT:%0A      case FOR:%0A      case IF:%0A      case LABEL:%0A      case LET:%0A      case SWITCH:%0A      case THROW:%0A      case TRY:%0A      case VAR:%0A      case WHILE:%0A      case WITH:%0A      case RETURN:%0A        return false;%0A%0A      default:%0A        return true;%0A    %7D%0A  %7D%0A%7D%0A

Add file TypeInfoCheck to check that nodes that should have TypeI information actually does have TypeI information.