本文整理汇总了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;
}
示例2: proposedNames
get proposedNames(): ReadonlySet<string> {
const set = new Set([this.combinedName]);
if (this._alternativeNames === undefined) {
return set;
}
setUnionInto(set, this._alternativeNames);
return set;
}
示例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;
}
示例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];
}
示例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);
}
示例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
);
}
}
}
示例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;
}