private void emitIndexSignature(JSType keyType, JSType returnType, boolean emitBreak) { emit("["); // TS allows only number or string as index type of an object // https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.9.4 if (keyType.isNumberValueType()) { emit("key: number"); } else { if (!keyType.isStringValueType()) { emit("/* warning: coerced from " + keyType + " */"); } emit("key: string"); } emit("]:"); visitType(returnType); if (emitBreak) { emit(";"); emitBreak(); } }
private boolean isNumeric(Node n) { return NodeUtil.isNumericResult(n) || (shouldUseTypes && n.getJSType() != null && n.getJSType().isNumberValueType()); }
private String getName(JSType type) { if (type.isInstanceType()) { return ((ObjectType) type).getReferenceName(); } else if (type.isNullType() || type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) { return type.toString(); } else { // Type unchecked at runtime, so we don't care about the sorting order. return ""; } } };
private String getName(JSType type) { if (type.isInstanceType()) { return ((ObjectType) type).getReferenceName(); } else if (type.isNullType() || type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) { return type.toString(); } else { // Type unchecked at runtime, so we don't care about the sorting order. return ""; } } };
/** * Return if the node is possibly a string. * * @param n The node. * @param useType If true and the node has a primitive type, return true if that type is string * and false otherwise. * @return Whether the results is possibly a string. */ static boolean mayBeString(Node n, boolean useType) { if (useType) { JSType type = n.getJSType(); if (type != null) { if (type.isStringValueType()) { return true; } else if (type.isNumberValueType() || type.isBooleanValueType() || type.isNullType() || type.isVoidType()) { return false; } } } return mayBeString(getKnownValueType(n)); }
/** * Return if the node is possibly a string. * * @param n The node. * @param useType If true and the node has a primitive type, return true if that type is string * and false otherwise. * @return Whether the results is possibly a string. */ static boolean mayBeString(Node n, boolean useType) { if (useType) { JSType type = n.getJSType(); if (type != null) { if (type.isStringValueType()) { return true; } else if (type.isNumberValueType() || type.isBooleanValueType() || type.isNullType() || type.isVoidType()) { return false; } } } return mayBeString(getKnownValueType(n)); }
return jsCode("nullChecker"); } else if (type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) {
|| type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) {