Java Code Examples for com.google.javascript.rhino.Token#NUMBER

The following examples show how to use com.google.javascript.rhino.Token#NUMBER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this is an immutable value.
 */
static boolean isImmutableValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.NULL:
    case Token.TRUE:
    case Token.FALSE:
      return true;
    case Token.CAST:
    case Token.NOT:
      return isImmutableValue(n.getFirstChild());
    case Token.VOID:
    case Token.NEG:
      return isImmutableValue(n.getFirstChild());
    case Token.NAME:
      String name = n.getString();
      // We assume here that programs don't change the value of the keyword
      // undefined to something other than the value undefined.
      return "undefined".equals(name)
          || "Infinity".equals(name)
          || "NaN".equals(name);
  }

  return false;
}
 
Example 2
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this is an immutable value.
 */
static boolean isImmutableValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.NULL:
    case Token.TRUE:
    case Token.FALSE:
      return true;
    case Token.NOT:
      return isImmutableValue(n.getFirstChild());
    case Token.VOID:
    case Token.NEG:
      return isImmutableValue(n.getFirstChild());
    case Token.NAME:
      String name = n.getString();
      // We assume here that programs don't change the value of the keyword
      // undefined to something other than the value undefined.
      return "undefined".equals(name)
          || "Infinity".equals(name)
          || "NaN".equals(name);
  }

  return false;
}
 
Example 3
Source File: Cardumen_0014_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns true if this is an immutable value.
 */
static boolean isImmutableValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.NULL:
    case Token.TRUE:
    case Token.FALSE:
      return true;
    case Token.NOT:
      return isImmutableValue(n.getFirstChild());
    case Token.VOID:
    case Token.NEG:
      return isImmutableValue(n.getFirstChild());
    case Token.NAME:
      String name = n.getString();
      // We assume here that programs don't change the value of the keyword
      // undefined to something other than the value undefined.
      return "undefined".equals(name)
          || "Infinity".equals(name)
          || "NaN".equals(name);
  }

  return false;
}
 
Example 4
Source File: Closure_84_IRFactory_t.java    From coming with MIT License 5 votes vote down vote up
@Override
Node processUnaryExpression(UnaryExpression exprNode) {
  int type = transformTokenType(exprNode.getType());
  Node operand = transform(exprNode.getOperand());
  if (type == Token.NEG && operand.getType() == Token.NUMBER) {
    operand.setDouble(-operand.getDouble());
    return operand;
  } else {
    if (type == Token.INC || type == Token.DEC) {
      if (!validAssignmentTarget(operand)) {
        String msg = (type == Token.INC)
            ? "invalid increment target"
            : "invalid decrement target";
        errorReporter.error(
          msg,
          sourceName,
          operand.getLineno(), "", 0);
      }
    }

    Node node = newNode(type, operand);
    if (exprNode.isPostfix()) {
      node.putBooleanProp(Node.INCRDECR_PROP, true);
    }
    return node;
  }
}
 
Example 5
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
static boolean isNumericResultHelper(Node n) {
  switch (n.getType()) {
    case Token.ADD:
      return !mayBeString(n.getFirstChild())
          && !mayBeString(n.getLastChild());
    case Token.BITNOT:
    case Token.BITOR:
    case Token.BITXOR:
    case Token.BITAND:
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:
    case Token.SUB:
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:
    case Token.INC:
    case Token.DEC:
    case Token.POS:
    case Token.NEG:
    case Token.NUMBER:
      return true;
    case Token.NAME:
      String name = n.getString();
      if (name.equals("NaN")) {
        return true;
      }
      if (name.equals("Infinity")) {
        return true;
      }
      return false;
    default:
      return false;
  }
}
 
Example 6
Source File: Closure_86_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function.
 */
static TernaryValue getBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
    case Token.REGEXP:
      return TernaryValue.TRUE;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 7
Source File: Closure_75_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the name of an object literal key.
 *
 * @param key A node
 */
static String getObjectLitKeyName(Node key) {
  switch (key.getType()) {
    case Token.NUMBER:
      return NodeUtil.getStringValue(key);
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      return key.getString();
  }
  throw new IllegalStateException("Unexpected node type: " + key);
}
 
Example 8
Source File: Closure_75_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
static boolean isNumericResultHelper(Node n) {
  switch (n.getType()) {
    case Token.ADD:
      return !mayBeString(n.getFirstChild())
          && !mayBeString(n.getLastChild());
    case Token.BITNOT:
    case Token.BITOR:
    case Token.BITXOR:
    case Token.BITAND:
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:
    case Token.SUB:
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:
    case Token.INC:
    case Token.DEC:
    case Token.POS:
    case Token.NEG:
    case Token.NUMBER:
      return true;
    case Token.NAME:
      String name = n.getString();
      if (name.equals("NaN")) {
        return true;
      }
      if (name.equals("Infinity")) {
        return true;
      }
      return false;
    default:
      return false;
  }
}
 
Example 9
Source File: Closure_43_TypedScopeCreator_s.java    From coming with MIT License 5 votes vote down vote up
private void attachLiteralTypes(NodeTraversal t, Node n) {
  switch (n.getType()) {
    case Token.NULL:
      n.setJSType(getNativeType(NULL_TYPE));
      break;

    case Token.VOID:
      n.setJSType(getNativeType(VOID_TYPE));
      break;

    case Token.STRING:
      // Defer keys to the Token.OBJECTLIT case
      if (!NodeUtil.isObjectLitKey(n, n.getParent())) {
        n.setJSType(getNativeType(STRING_TYPE));
      }
      break;

    case Token.NUMBER:
      n.setJSType(getNativeType(NUMBER_TYPE));
      break;

    case Token.TRUE:
    case Token.FALSE:
      n.setJSType(getNativeType(BOOLEAN_TYPE));
      break;

    case Token.REGEXP:
      n.setJSType(getNativeType(REGEXP_TYPE));
      break;

    case Token.OBJECTLIT:
        defineObjectLiteral(n);
      break;

      // NOTE(nicksantos): If we ever support Array tuples,
      // we will need to put ARRAYLIT here as well.
  }
}
 
Example 10
Source File: Closure_50_PeepholeReplaceKnownMethods_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Try to evaluate String.indexOf/lastIndexOf:
 *     "abcdef".indexOf("bc") -> 1
 *     "abcdefbc".indexOf("bc", 3) -> 6
 */
private Node tryFoldStringIndexOf(
    Node n, String functionName, Node lstringNode, Node firstArg) {
  Preconditions.checkArgument(n.getType() == Token.CALL);
  Preconditions.checkArgument(lstringNode.getType() == Token.STRING);

  String lstring = NodeUtil.getStringValue(lstringNode);
  boolean isIndexOf = functionName.equals("indexOf");
  Node secondArg = firstArg.getNext();
  String searchValue = NodeUtil.getStringValue(firstArg);
  // searchValue must be a valid string.
  if (searchValue == null) {
    return n;
  }
  int fromIndex = isIndexOf ? 0 : lstring.length();
  if (secondArg != null) {
    // Third-argument and non-numeric second arg are problematic. Discard.
    if ((secondArg.getNext() != null) ||
        (secondArg.getType() != Token.NUMBER)) {
      return n;
    } else {
      fromIndex = (int) secondArg.getDouble();
    }
  }
  int indexVal = isIndexOf ? lstring.indexOf(searchValue, fromIndex)
                           : lstring.lastIndexOf(searchValue, fromIndex);
  Node newNode = Node.newNumber(indexVal);
  n.getParent().replaceChild(n, newNode);

  reportCodeChange();

  return newNode;
}
 
Example 11
Source File: Closure_80_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function.
 */
static TernaryValue getBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
    case Token.REGEXP:
      return TernaryValue.TRUE;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 12
Source File: Cardumen_00200_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 13
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 14
Source File: Closure_50_PeepholeReplaceKnownMethods_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Try to fold .substr() calls on strings
 */
private Node tryFoldStringSubstr(Node n, Node stringNode, Node arg1) {
  Preconditions.checkArgument(n.getType() == Token.CALL);
  Preconditions.checkArgument(stringNode.getType() == Token.STRING);

  int start, length;
  String stringAsString = stringNode.getString();

  // TODO(nicksantos): We really need a NodeUtil.getNumberValue
  // function.
  if (arg1 != null && arg1.getType() == Token.NUMBER) {
    start = (int) arg1.getDouble();
  } else {
    return n;
  }

  Node arg2 = arg1.getNext();
  if (arg2 != null) {
    if (arg2.getType() == Token.NUMBER) {
      length = (int) arg2.getDouble();
    } else {
      return n;
    }

    if (arg2.getNext() != null) {
      // If we got more args than we expected, bail out.
      return n;
    }
  } else {
    // parameter 2 not passed
    length = stringAsString.length() - start;
  }

  // Don't handle these cases. The specification actually does
  // specify the behavior in some of these cases, but we haven't
  // done a thorough investigation that it is correctly implemented
  // in all browsers.
  if ((start + length) > stringAsString.length() ||
      (length < 0) ||
      (start < 0)) {
    return n;
  }

  String result = stringAsString.substring(start, start + length);
  Node resultNode = Node.newString(result);

  Node parent = n.getParent();
  parent.replaceChild(n, resultNode);
  reportCodeChange();
  return resultNode;
}
 
Example 15
Source File: Closure_10_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the value of a node as a Number, or null if it cannot be converted.
 * When it returns a non-null Double, this method effectively emulates the
 * <code>Number()</code> JavaScript cast function.
 */
static Double getNumberValue(Node n) {
  switch (n.getType()) {
    case Token.TRUE:
      return 1.0;

    case Token.FALSE:
    case Token.NULL:
      return 0.0;

    case Token.NUMBER:
      return n.getDouble();

    case Token.VOID:
      if (mayHaveSideEffects(n.getFirstChild())) {
        return null;
      } else {
        return Double.NaN;
      }

    case Token.NAME:
      // Check for known constants
      String name = n.getString();
      if (name.equals("undefined")) {
        return Double.NaN;
      }
      if (name.equals("NaN")) {
        return Double.NaN;
      }
      if (name.equals("Infinity")) {
        return Double.POSITIVE_INFINITY;
      }
      return null;

    case Token.NEG:
      if (n.getChildCount() == 1 && n.getFirstChild().isName()
          && n.getFirstChild().getString().equals("Infinity")) {
        return Double.NEGATIVE_INFINITY;
      }
      return null;

    case Token.NOT:
      TernaryValue child = getPureBooleanValue(n.getFirstChild());
      if (child != TernaryValue.UNKNOWN) {
        return child.toBoolean(true) ? 0.0 : 1.0; // reversed.
      }
      break;

    case Token.STRING:
      return getStringNumberValue(n.getString());

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      String value = getStringValue(n);
      return value != null ? getStringNumberValue(value) : null;
  }

  return null;
}
 
Example 16
Source File: Closure_86_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * 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.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.TRUE:
    case Token.FALSE:
      return true;

    // Binary operators are only valid if both children are valid.
    case Token.ADD:
    case Token.BITAND:
    case Token.BITNOT:
    case Token.BITOR:
    case Token.BITXOR:
    case Token.DIV:
    case Token.EQ:
    case Token.GE:
    case Token.GT:
    case Token.LE:
    case Token.LSH:
    case Token.LT:
    case Token.MOD:
    case Token.MUL:
    case Token.NE:
    case Token.RSH:
    case Token.SHEQ:
    case Token.SHNE:
    case Token.SUB:
    case Token.URSH:
      return isValidDefineValue(val.getFirstChild(), defines)
          && isValidDefineValue(val.getLastChild(), defines);

    // Uniary operators are valid if the child is valid.
    case Token.NOT:
    case Token.NEG:
    case Token.POS:
      return isValidDefineValue(val.getFirstChild(), defines);

    // Names are valid if and only if they are defines themselves.
    case Token.NAME:
    case Token.GETPROP:
      if (val.isQualifiedName()) {
        return defines.contains(val.getQualifiedName());
      }
  }
  return false;
}
 
Example 17
Source File: Closure_54_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
private void attachLiteralTypes(NodeTraversal t, Node n) {
  switch (n.getType()) {
    case Token.NULL:
      n.setJSType(getNativeType(NULL_TYPE));
      break;

    case Token.VOID:
      n.setJSType(getNativeType(VOID_TYPE));
      break;

    case Token.STRING:
      // Defer keys to the Token.OBJECTLIT case
      if (!NodeUtil.isObjectLitKey(n, n.getParent())) {
        n.setJSType(getNativeType(STRING_TYPE));
      }
      break;

    case Token.NUMBER:
      n.setJSType(getNativeType(NUMBER_TYPE));
      break;

    case Token.TRUE:
    case Token.FALSE:
      n.setJSType(getNativeType(BOOLEAN_TYPE));
      break;

    case Token.REGEXP:
      n.setJSType(getNativeType(REGEXP_TYPE));
      break;

    case Token.REF_SPECIAL:
      n.setJSType(getNativeType(UNKNOWN_TYPE));
      break;

    case Token.OBJECTLIT:
      defineObjectLiteral(t, n);
      break;

      // NOTE(nicksantos): If we ever support Array tuples,
      // we will need to put ARRAYLIT here as well.
  }
}
 
Example 18
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.ARRAYLIT:
    case Token.CALL:
    case Token.EMPTY:
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.GETELEM:
    case Token.GETPROP:
    case Token.GET_REF:
    case Token.IF:
    case Token.LP:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.RETURN:
    case Token.STRING:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Node.tokenToName(type) +
                             " (type " + type + ")");
  }
}
 
Example 19
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.TRUE:
    case Token.FALSE:
      return true;

    // Binary operators are only valid if both children are valid.
    case Token.ADD:
    case Token.BITAND:
    case Token.BITNOT:
    case Token.BITOR:
    case Token.BITXOR:
    case Token.DIV:
    case Token.EQ:
    case Token.GE:
    case Token.GT:
    case Token.LE:
    case Token.LSH:
    case Token.LT:
    case Token.MOD:
    case Token.MUL:
    case Token.NE:
    case Token.RSH:
    case Token.SHEQ:
    case Token.SHNE:
    case Token.SUB:
    case Token.URSH:
      return isValidDefineValue(val.getFirstChild(), defines)
          && isValidDefineValue(val.getLastChild(), defines);

    // Uniary operators are valid if the child is valid.
    case Token.NOT:
    case Token.NEG:
    case Token.POS:
      return isValidDefineValue(val.getFirstChild(), defines);

    // Names are valid if and only if they are defines themselves.
    case Token.NAME:
    case Token.GETPROP:
      if (val.isQualifiedName()) {
        return defines.contains(val.getQualifiedName());
      }
  }
  return false;
}
 
Example 20
Source File: Closure_54_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
private void attachLiteralTypes(NodeTraversal t, Node n) {
  switch (n.getType()) {
    case Token.NULL:
      n.setJSType(getNativeType(NULL_TYPE));
      break;

    case Token.VOID:
      n.setJSType(getNativeType(VOID_TYPE));
      break;

    case Token.STRING:
      // Defer keys to the Token.OBJECTLIT case
      if (!NodeUtil.isObjectLitKey(n, n.getParent())) {
        n.setJSType(getNativeType(STRING_TYPE));
      }
      break;

    case Token.NUMBER:
      n.setJSType(getNativeType(NUMBER_TYPE));
      break;

    case Token.TRUE:
    case Token.FALSE:
      n.setJSType(getNativeType(BOOLEAN_TYPE));
      break;

    case Token.REGEXP:
      n.setJSType(getNativeType(REGEXP_TYPE));
      break;

    case Token.REF_SPECIAL:
      n.setJSType(getNativeType(UNKNOWN_TYPE));
      break;

    case Token.OBJECTLIT:
      defineObjectLiteral(t, n);
      break;

      // NOTE(nicksantos): If we ever support Array tuples,
      // we will need to put ARRAYLIT here as well.
  }
}