/** * Creates a type representing nullable values of the given type. * @return the union of the type and the Null type */ public JSType createDefaultObjectUnion(JSType type) { if (type.isTemplateType()) { // Template types represent the substituted type exactly and should // not be wrapped. return type; } else { return createNullableType(type); } }
/** * Creates a type representing nullable values of the given type. * @return the union of the type and the Null type */ public JSType createDefaultObjectUnion(JSType type) { if (type.isTemplateType()) { // Template types represent the substituted type exactly and should // not be wrapped. return type; } else { return createNullableType(type); } }
Es6RewriteGenerators(AbstractCompiler compiler) { checkNotNull(compiler); this.compiler = compiler; registry = compiler.getTypeRegistry(); if (compiler.hasTypeCheckingRun()) { // typechecking has run, so we must preserve and propagate type information shouldAddTypes = true; unknownType = registry.getNativeType(JSTypeNative.UNKNOWN_TYPE); numberType = registry.getNativeType(JSTypeNative.NUMBER_TYPE); booleanType = registry.getNativeType(JSTypeNative.BOOLEAN_TYPE); nullType = registry.getNativeType(JSTypeNative.NULL_TYPE); nullableStringType = registry.createNullableType(registry.getNativeType(JSTypeNative.STRING_TYPE)); voidType = registry.getNativeType(JSTypeNative.VOID_TYPE); } else { shouldAddTypes = false; unknownType = null; numberType = null; booleanType = null; nullType = null; nullableStringType = null; voidType = null; } }
@Override public JSType getPropertyType(String name) { if (!hasOwnProperty(name)) { // Define the "call", "apply", and "bind" functions lazily. boolean isCall = "call".equals(name); boolean isBind = "bind".equals(name); if (isCall || isBind) { defineDeclaredProperty(name, getCallOrBindSignature(isCall), source); } else if ("apply".equals(name)) { // Define the "apply" function lazily. FunctionParamBuilder builder = new FunctionParamBuilder(registry); // ECMA-262 says that apply's second argument must be an Array // or an arguments object. We don't model the arguments object, // so let's just be forgiving for now. // TODO(nicksantos): Model the Arguments object. builder.addOptionalParams( registry.createNullableType(getTypeOfThis()), registry.createNullableType( registry.getNativeType(JSTypeNative.OBJECT_TYPE))); defineDeclaredProperty(name, new FunctionBuilder(registry) .withParamsNode(builder.build()) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()) .build(), source); } } return super.getPropertyType(name); }
@Override public final JSType getPropertyType(String name) { if (!hasOwnProperty(name)) { // Define the "call", "apply", and "bind" functions lazily. boolean isCall = "call".equals(name); boolean isBind = "bind".equals(name); if (isCall || isBind) { defineDeclaredProperty(name, getCallOrBindSignature(isCall), source); } else if ("apply".equals(name)) { // Define the "apply" function lazily. FunctionParamBuilder builder = new FunctionParamBuilder(registry); // ECMA-262 says that apply's second argument must be an Array // or an arguments object. We don't model the arguments object, // so let's just be forgiving for now. // TODO(nicksantos): Model the Arguments object. builder.addOptionalParams( registry.createNullableType(getTypeOfThis()), registry.createNullableType(registry.getNativeType(JSTypeNative.OBJECT_TYPE))); defineDeclaredProperty( name, new FunctionBuilder(registry) .withParamsNode(builder.build()) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()) .build(), source); } } return super.getPropertyType(name); }
return getNativeType(UNKNOWN_TYPE); return createNullableType( createFromTypeNodesInternal( firstChild, sourceName, scope));
return getNativeType(UNKNOWN_TYPE); return createNullableType( createFromTypeNodesInternal( firstChild, sourceName, scope, recordUnresolvedTypes));