src/com/google/javascript/jscomp/CheckJSDoc.java
/**
   * Check that JSDoc with a {@code @type} annotation is in a valid place.
   */
Check that JSDoc with a   annotation is in a valid place.
Check that JSDoc with a annotation is in a valid place .
private void validateTypeAnnotations(Node n, JSDocInfo info) {
    if (info != null && info.hasType()) {
      boolean valid = false;
      switch (n.getToken()) {
        case FUNCTION:
          valid = NodeUtil.isFunctionDeclaration(n);
          break;
        case NAME:
          valid = isTypeAnnotationAllowedForName(n);
          break;
        case ARRAY_PATTERN:
        case OBJECT_PATTERN:
          valid = n.getParent().isParamList();
          break;
        case CAST:
        case EXPORT:
        case STRING_KEY:
        case GETTER_DEF:
        case SETTER_DEF:
          valid = true;
          break;
        case VAR:
        case LET:
        case CONST:
          valid = !NodeUtil.isDestructuringDeclaration(n);
          break;
        case ASSIGN: {
          Node lvalue = n.getFirstChild();
          valid = n.getParent().isExprResult()
              && (lvalue.isGetProp()
                  || lvalue.isGetElem()
                  || lvalue.matchesQualifiedName("exports"));
          break;
        }
        case GETPROP:
          valid = n.getParent().isExprResult() && n.isQualifiedName();
          break;
        case CALL:
          valid = info.isDefine();
          break;
        default:
          break;
      }
      if (!valid) {
        reportMisplaced(n, "type", "Type annotations are not allowed here. "
            + "Are you missing parentheses?");
      }
    }
  }
private void validateTypeAnnotations ( Node n , JSDocInfo info ) { if ( info != null && info . hasType ( ) ) { boolean valid = false ; switch ( n . getToken ( ) ) { case FUNCTION : valid = NodeUtil . isFunctionDeclaration ( n ) ; break ; case NAME : valid = isTypeAnnotationAllowedForName ( n ) ; break ; case ARRAY_PATTERN : case OBJECT_PATTERN : valid = n . getParent ( ) . isParamList ( ) ; break ; case CAST : case EXPORT : case STRING_KEY : case GETTER_DEF : case SETTER_DEF : valid = true ; break ; case VAR : case LET : case CONST : valid = ! NodeUtil . isDestructuringDeclaration ( n ) ; break ; case ASSIGN : { Node lvalue = n . getFirstChild ( ) ; valid = n . getParent ( ) . isExprResult ( ) && ( lvalue . isGetProp ( ) || lvalue . isGetElem ( ) || lvalue . matchesQualifiedName ( "exports" ) ) ; break ; } case GETPROP : valid = n . getParent ( ) . isExprResult ( ) && n . isQualifiedName ( ) ; break ; case CALL : valid = info . isDefine ( ) ; break ; default : break ; } if ( ! valid ) { reportMisplaced ( n , "type" , "Type annotations are not allowed here. " + "Are you missing parentheses?" ) ; } } }
Check that JSDoc with a {@code @type} annotation is in a valid place.
Check that JSDoc with a { @code @type } annotation is in a valid place .
// Function declarations are valid // Object literal properties, catch declarations and variable // initializers are valid. // allow JSDoc like //   function f(/** !Object */ {x}) {} //   function f(/** !Array */ [x]) {} // Casts, exports, and Object literal properties are valid. // Declarations are valid iff they only contain simple names //   /** @type {number} */ var x = 3; // ok //   /** @type {number} */ var {x} = obj; // forbidden // Property assignments are valid, if at the root of an expression.