当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript collection-utils.setUnionInto函数代码示例

本文整理汇总了TypeScript中collection-utils.setUnionInto函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setUnionInto函数的具体用法?TypeScript setUnionInto怎么用?TypeScript setUnionInto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setUnionInto函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getChildren

 getChildren(): Set<Type> {
     let children = super.getChildren();
     for (const xfer of this.transformers) {
         setUnionInto(children, xfer.getChildren());
     }
     return children;
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:7,代码来源:Transformers.ts

示例2: proposedNames

 get proposedNames(): ReadonlySet<string> {
     const set = new Set([this.combinedName]);
     if (this._alternativeNames === undefined) {
         return set;
     }
     setUnionInto(set, this._alternativeNames);
     return set;
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:8,代码来源:TypeNames.ts

示例3: getChildren

 getChildren(): ReadonlySet<Type> {
     let result = this.getNonAttributeChildren();
     for (const [k, v] of this.getAttributes()) {
         if (k.children === undefined) continue;
         setUnionInto(result, k.children(v));
     }
     return result;
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:8,代码来源:Type.ts

示例4: getCliqueProperties

function getCliqueProperties(
    clique: ObjectType[],
    builder: TypeBuilder,
    makePropertyType: (types: ReadonlySet<Type>) => TypeRef
): [ReadonlyMap<string, ClassProperty>, TypeRef | undefined, boolean] {
    let lostTypeAttributes = false;
    let propertyNames = new Set<string>();
    for (const o of clique) {
        setUnionInto(propertyNames, o.getProperties().keys());
    }

    let properties = Array.from(propertyNames).map(name => [name, new Set(), false] as [string, Set<Type>, boolean]);
    let additionalProperties: Set<Type> | undefined = undefined;
    for (const o of clique) {
        let additional = o.getAdditionalProperties();
        if (additional !== undefined) {
            if (additionalProperties === undefined) {
                additionalProperties = new Set();
            }
            if (additional !== undefined) {
                additionalProperties.add(additional);
            }
        }

        for (let i = 0; i < properties.length; i++) {
            let [name, types, isOptional] = properties[i];
            const maybeProperty = o.getProperties().get(name);
            if (maybeProperty === undefined) {
                isOptional = true;
                if (additional !== undefined && additional.kind !== "any") {
                    types.add(additional);
                }
            } else {
                if (maybeProperty.isOptional) {
                    isOptional = true;
                }
                types.add(maybeProperty.type);
            }

            properties[i][2] = isOptional;
        }
    }

    const unifiedAdditionalProperties =
        additionalProperties === undefined ? undefined : makePropertyType(additionalProperties);

    const unifiedPropertiesArray = properties.map(([name, types, isOptional]) => {
        return [name, builder.makeClassProperty(makePropertyType(types), isOptional)] as [string, ClassProperty];
    });
    const unifiedProperties = new Map(unifiedPropertiesArray);

    return [unifiedProperties, unifiedAdditionalProperties, lostTypeAttributes];
}
开发者ID:nrkn,项目名称:quicktype,代码行数:53,代码来源:UnifyClasses.ts

示例5: add

    add(namesArray: TypeNames[], startIndex: number = 0): TypeNames {
        let newNames = new Set(this.names);
        let newDistance = this.distance;
        let newAlternativeNames = definedMap(this._alternativeNames, s => new Set(s));

        for (let i = startIndex; i < namesArray.length; i++) {
            const other = namesArray[i];

            if (other instanceof RegularTypeNames && other._alternativeNames !== undefined) {
                if (newAlternativeNames === undefined) {
                    newAlternativeNames = new Set();
                }
                setUnionInto(newAlternativeNames, other._alternativeNames);
            }

            if (other.distance > newDistance) continue;

            if (!(other instanceof RegularTypeNames)) {
                assert(other instanceof TooManyTypeNames, "Unknown TypeNames instance");
                // The other one is at most our distance, so let it sort it out
                return other.add(namesArray, i + 1);
            }

            if (other.distance < newDistance) {
                // The other one is closer, so take its names
                newNames = new Set(other.names);
                newDistance = other.distance;
                newAlternativeNames = definedMap(other._alternativeNames, s => new Set(s));
            } else {
                // Same distance, merge them
                assert(other.distance === newDistance, "This should be the only case left");
                setUnionInto(newNames, other.names);
            }
        }
        return TypeNames.makeWithDistance(newNames, newAlternativeNames, newDistance);
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:36,代码来源:TypeNames.ts

示例6: makeObject

    protected makeObject(
        objectRefs: TypeRef[],
        typeAttributes: TypeAttributes,
        forwardingRef: TypeRef | undefined
    ): TypeRef {
        const maybeTypeRef = this.typeBuilder.lookupTypeRefs(objectRefs, forwardingRef);
        if (maybeTypeRef !== undefined) {
            assert(
                forwardingRef === undefined || maybeTypeRef === forwardingRef,
                "The forwarding ref must be consumed"
            );
            this.typeBuilder.addAttributes(maybeTypeRef, typeAttributes);
            return maybeTypeRef;
        }

        if (objectRefs.length === 1) {
            return this.typeBuilder.reconstituteTypeRef(objectRefs[0], typeAttributes, forwardingRef);
        }

        const objectTypes = objectRefs.map(r => assertIsObject(derefTypeRef(r, this.typeBuilder)));
        const { hasProperties, hasAdditionalProperties, hasNonAnyAdditionalProperties } = countProperties(objectTypes);

        if (!this._makeObjectTypes && (hasNonAnyAdditionalProperties || (!hasProperties && hasAdditionalProperties))) {
            const propertyTypes = new Set<TypeRef>();
            for (const o of objectTypes) {
                setUnionInto(propertyTypes, Array.from(o.getProperties().values()).map(cp => cp.typeRef));
            }
            const additionalPropertyTypes = new Set(
                objectTypes
                    .filter(o => o.getAdditionalProperties() !== undefined)
                    .map(o => defined(o.getAdditionalProperties()).typeRef)
            );
            setUnionInto(propertyTypes, additionalPropertyTypes);
            return this.typeBuilder.getMapType(typeAttributes, this._unifyTypes(Array.from(propertyTypes)));
        } else {
            const [properties, additionalProperties, lostTypeAttributes] = getCliqueProperties(
                objectTypes,
                this.typeBuilder,
                types => {
                    assert(types.size > 0, "Property has no type");
                    return this._unifyTypes(Array.from(types).map(t => t.typeRef));
                }
            );
            if (lostTypeAttributes) {
                this.typeBuilder.setLostTypeAttributes();
            }
            if (this._makeObjectTypes) {
                return this.typeBuilder.getUniqueObjectType(
                    typeAttributes,
                    properties,
                    additionalProperties,
                    forwardingRef
                );
            } else {
                assert(additionalProperties === undefined, "We have additional properties but want to make a class");
                return this.typeBuilder.getUniqueClassType(
                    typeAttributes,
                    this._makeClassesFixed,
                    properties,
                    forwardingRef
                );
            }
        }
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:64,代码来源:UnifyClasses.ts

示例7: visitComponent

        function visitComponent(component: ReadonlySet<Type>): void {
            if (visitedComponents.has(component)) return;
            visitedComponents.add(component);

            // console.log(`visiting component ${componentName(component)}`);

            const declarationNeeded = setFilter(component, needsDeclaration);

            // 1. Only one node in the cycle needs a declaration, in which
            // case it's the breaker, and no forward declaration is necessary.
            if (declarationNeeded.size === 1) {
                declarations.push({ kind: "define", type: defined(iterableFirst(declarationNeeded)) });
                return;
            }

            // 2. No node in the cycle needs a declaration, but it's also
            // the only node, so we don't actually need a declaration at all.
            if (declarationNeeded.size === 0 && component.size === 1) {
                return;
            }

            // 3. No node in the cycle needs a declaration, but there's more.
            // than one node total.  We have to pick a node to make a
            // declaration, so we can pick any one. This is not a forward
            // declaration, either.
            if (declarationNeeded.size === 0) {
                declarations.push({ kind: "define", type: defined(iterableFirst(component)) });
                return;
            }

            // 4. More than one node needs a declaration, and we don't need
            // forward declarations.  Just declare all of them and be done
            // with it.
            if (canBeForwardDeclared === undefined) {
                for (const t of declarationNeeded) {
                    declarations.push({ kind: "define", type: t });
                }
                return;
            }

            // 5. More than one node needs a declaration, and we have
            // to make forward declarations.  We do the simple thing and first
            // forward-declare all forward-declarable types in the SCC.  If
            // there are none, we're stuck.  If there are, we take them out of
            // the component and try the whole thing again recursively.  Then
            // we declare the types we previously forward-declared.
            const forwardDeclarable = setFilter(component, canBeForwardDeclared);
            if (forwardDeclarable.size === 0) {
                return messageError("IRNoForwardDeclarableTypeInCycle", {});
            }
            for (const t of forwardDeclarable) {
                declarations.push({ kind: "forward", type: t });
            }
            setUnionInto(forwardedTypes, forwardDeclarable);
            const rest = setSubtract(component, forwardDeclarable);
            const restGraph = new Graph(rest, true, t => setIntersect(childrenOfType(t), rest));
            processGraph(restGraph, false);
            for (const t of forwardDeclarable) {
                declarations.push({ kind: "define", type: t });
            }
            return;
        }
开发者ID:nrkn,项目名称:quicktype,代码行数:62,代码来源:DeclarationIR.ts


注:本文中的collection-utils.setUnionInto函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。