src/com/google/javascript/jscomp/NodeUtil.java
/**
   * Determines whether the given value may be assigned to a define.
   *
   * @param val The value being assigned.
   * @param defines The list of names of existing defines.
   */
Determines whether the given value may be assigned to a define.
@param val The value being assigned.
@param defines The list of names of existing defines.
Determines whether the given value may be assigned to a define . @param val The value being assigned . @param defines The list of names of existing defines .
static boolean isValidDefineValue(Node val, Set<String> defines) {
    switch (val.getToken()) {
      case STRING:
      case NUMBER:
      case TRUE:
      case FALSE:
        return true;
      case AND:
      case OR:
      case ADD:
      case BITAND:
      case BITNOT:
      case BITOR:
      case BITXOR:
      case DIV:
      case EQ:
      case EXPONENT:
      case GE:
      case GT:
      case LE:
      case LSH:
      case LT:
      case MOD:
      case MUL:
      case NE:
      case RSH:
      case SHEQ:
      case SHNE:
      case SUB:
      case URSH:
        return isValidDefineValue(val.getFirstChild(), defines)
            && isValidDefineValue(val.getLastChild(), defines);
      case HOOK:
        return isValidDefineValue(val.getFirstChild(), defines)
            && isValidDefineValue(val.getSecondChild(), defines)
            && isValidDefineValue(val.getLastChild(), defines);
      case NOT:
      case NEG:
      case POS:
        return isValidDefineValue(val.getFirstChild(), defines);
      case NAME:
      case GETPROP:
        if (val.isQualifiedName()) {
          return defines.contains(val.getQualifiedName());
        }
        break;
      default:
        break;
    }
    return false;
  }
static boolean isValidDefineValue ( Node val , Set < String > defines ) { switch ( val . getToken ( ) ) { case STRING : case NUMBER : case TRUE : case FALSE : return true ; case AND : case OR : case ADD : case BITAND : case BITNOT : case BITOR : case BITXOR : case DIV : case EQ : case EXPONENT : case GE : case GT : case LE : case LSH : case LT : case MOD : case MUL : case NE : case RSH : case SHEQ : case SHNE : case SUB : case URSH : return isValidDefineValue ( val . getFirstChild ( ) , defines ) && isValidDefineValue ( val . getLastChild ( ) , defines ) ; case HOOK : return isValidDefineValue ( val . getFirstChild ( ) , defines ) && isValidDefineValue ( val . getSecondChild ( ) , defines ) && isValidDefineValue ( val . getLastChild ( ) , defines ) ; case NOT : case NEG : case POS : return isValidDefineValue ( val . getFirstChild ( ) , defines ) ; case NAME : case GETPROP : if ( val . isQualifiedName ( ) ) { return defines . contains ( val . getQualifiedName ( ) ) ; } break ; default : break ; } return false ; }
Determines whether the given value may be assigned to a define.
Determines whether the given value may be assigned to a define .
// Binary operators are only valid if both children are valid. // Unary operators are valid if the child is valid. // Names are valid if and only if they are defines themselves.