private boolean isStringTyped(Node n) { // We could also accept !String, but it is unlikely to be very common. return NodeUtil.isStringResult(n) || (shouldUseTypes && n.getJSType() != null && n.getJSType().isStringValueType()); }
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(); } }
@Override public void visit(Node n) { if (n.isName()) { Node parent = n.getParent(); String name = n.getString(); if (!name.isEmpty() && parent.isVar() && !locals.contains(name)) { locals.add(n.getString()); } if (params.contains(name)) { JSType type = paramTypes.get(name); boolean isStringLiteral = type.isStringValueType() && name.startsWith("string_literal"); replaceNodeInPlace( n, createTemplateParameterNode(params.indexOf(name), type, isStringLiteral)); } else if (locals.contains(name)) { replaceNodeInPlace(n, createTemplateLocalNameNode(locals.indexOf(name))); } } } });
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)); }
&& (isStringLiteral || (stringNode.getJSType() != null && stringNode.getJSType().isStringValueType()))) { if (subtree.hasXChildren(3)) { Double maybeStart = NodeUtil.getNumberValue(firstArg);
|| type.isStringValueType() || type.isVoidType()) { return IR.call(
} else if (type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) { return IR.call(jsCode("valueChecker"), IR.string(type.toString()));