/** Whether the type was written as the literal 'Function' type */ private boolean isLiteralFunction(JSType type) { return type.equals(typeRegistry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE)); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof TypeMismatch.LazyError) { TypeMismatch.LazyError that = (TypeMismatch.LazyError) o; return (this.message.equals(that.message())) && (this.node.equals(that.node())) && (this.sourceType.equals(that.sourceType())) && (this.targetType.equals(that.targetType())); } return false; }
/** * If we access a property of a symbol, then that symbol is not * null or undefined. */ private FlowScope tightenTypeAfterDereference(Node n, FlowScope scope) { if (n.isQualifiedName()) { JSType type = getJSType(n); JSType narrowed = type.restrictByNotNullOrUndefined(); if (!type.equals(narrowed)) { scope = narrowScope(scope, n, narrowed); } } return scope; }
/** * Special handling for simple typing returning polymorphic this type in TypeScript. Prefer * `func(): this` instead of `func<T>(this: T): T` when any params are not templatized. */ private boolean shouldSkipEmittingThisTemplateAndParam(FunctionType ftype) { final JSType typeOfThis = ftype.getTypeOfThis(); if (typeOfThis == null || !typeOfThis.isTemplateType() || !typeOfThis.equals(ftype.getReturnType())) { return false; } Iterator<Node> parameters = ftype.getParameters().iterator(); while (parameters.hasNext()) { final JSType paramType = parameters.next().getJSType(); if (!paramType.isTemplatizedType()) { continue; } final TemplateTypeMap templateTypeMap = paramType.getTemplateTypeMap(); for (TemplateType key : templateTypeMap.getTemplateKeys()) { if (templateTypeMap.getResolvedTemplateType(key).equals(typeOfThis)) { return false; } } } return true; }
private Void emitTemplatizedType(TemplatizedType type, boolean inImplementsExtendsPosition) { ObjectType referencedType = type.getReferencedType(); String templateTypeName = getAbsoluteName(type); if (typeRegistry.getNativeType(ARRAY_TYPE).equals(referencedType) && type.getTemplateTypes().size() == 1) { if (typeRegistry.getNativeType(OBJECT_TYPE).equals(referencedType)) { emit("{"); emitIndexSignature(it.next(), it.next(), false);
private void visitFunctionDeclaration(FunctionType ftype, List<String> skipTemplateParams) { visitFunctionParameters(ftype, true, skipTemplateParams); JSType type = ftype.getReturnType(); final JSType typeOfThis = ftype.getTypeOfThis(); if (type == null) return; emit(":"); // Closure conflates 'undefined' and 'void', and in general visitType always emits `undefined` // for that type. // In idiomatic TypeScript, `void` is used for function return types, and the "void", // "undefined" types are not the same. if (type.isVoidType()) { emit("void"); } else if (typeOfThis != null && typeOfThis.isTemplateType() && typeOfThis.equals(type)) { // Special case: prefer polymorphic `this` type to templatized `this` param emit("this"); } else { visitType(type); } }
&& !typeRegistry.getNativeType(OBJECT_TYPE).equals(type)) { return emitTemplatizedType( typeRegistry.createTemplatizedType(type), inExtendsImplementsPosition);
if (type.equals(registry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE))) { return "/** @type {!Function} */\n"; JSType thisType = funType.getTypeOfThis(); if (thisType != null && !thisType.isUnknownType() && !thisType.isVoidType()) { if (fnNode == null || !thisType.equals(findMethodOwner(fnNode))) { sb.append(" * "); appendAnnotation(sb, "this", thisType.toAnnotationString(Nullability.EXPLICIT));
void defineGetterSetter(Node n) { // GETTER_DEF -> CLASS_MEMBERS -> CLASS if (getterSetterTypes == null) { this.getterSetterTypes = HashBasedTable.create(); } FunctionType methodType = n.getLastChild().getJSType().toMaybeFunctionType(); JSType propertyType = n.isGetterDef() ? determineGetterType(methodType) : Iterables.getFirst(methodType.getParameterTypes(), null); propertyType = propertyType != null ? propertyType : unknownType; String name = n.getString(); JSType previousType = getterSetterTypes.get(name, n.isGetterDef() ? Token.SETTER_DEF : Token.GETTER_DEF); if (previousType != null && !previousType.equals(propertyType)) { // TODO(sdh): make this not an error - instead, store the getter and setter types separately report( JSError.make( n, CONFLICTING_GETTER_SETTER_TYPE, name, n.isGetterDef() ? propertyType.toString() : previousType.toString(), n.isGetterDef() ? previousType.toString() : propertyType.toString())); } else if (previousType == null) { ObjectType ownerType = determineOwnerTypeForClassMember(n); ownerType.defineDeclaredProperty(name, propertyType, n); getterSetterTypes.put(name, n.getToken(), propertyType); } }
private void checkPrivatePropertyVisibility( NodeTraversal t, Node getprop, Node parent, boolean isClassType, JSType ownerType) { JSType currentClass = getCurrentClass(); if (currentClass != null && ownerType.isEquivalentTo(currentClass)) { return; } if (isClassType && isValidPrivateConstructorAccess(parent)) { return; } // private access is not allowed outside the file from a different // enclosing class. JSType accessedType = getprop.getFirstChild().getJSType(); String propertyName = getprop.getLastChild().getString(); String readableTypeName = ownerType.equals(accessedType) ? typeRegistry.getReadableTypeName(getprop.getFirstChild()) : ownerType.toString(); compiler.report( t.makeError(getprop, BAD_PRIVATE_PROPERTY_ACCESS, propertyName, readableTypeName)); }
Node astParameter, JSType declaredParameterType, @Nullable Node iifeArgumentNode) { JSType paramType = declaredParameterType; boolean isInferred = paramType.equals(unknownType);