MCPcopy Create free account
hub / github.com/arktypeio/arktype / reaches

Function reaches

ark/schema/node.ts:636–674  ·  view source on GitHub ↗
(
		flag: "alters" | "ctxPred",
		resolvesIntersections = false
	)

Source from the content-addressed store, hash-verified

634 }
635
636 private reaches(
637 flag: "alters" | "ctxPred",
638 resolvesIntersections = false
639 ): boolean {
640 if (this[flag] || !this.hasAlias) return this[flag]
641 const cached = flag === "alters" ? "tfs" : "checksCtx"
642 let reachesOperands = false
643 // a Map visits the ids added while it's iterated
644 const reached = new Map<string, BaseNode>([[this.id, this]])
645 for (const node of reached.values()) {
646 for (const reference of referencesWithoutCases(node)) {
647 // an intersection can drop what its operands reach, so only resolving it decides
648 if (reference[flag]) return !reachesOperands || this.reaches(flag, true)
649 if (!reference.is("alias")) continue
650 // resolving an intersection can create others or reenter an operand still resolving
651 if (
652 reference.operator === "&" &&
653 !(resolvesIntersections && reference.hasResolvableOperands)
654 ) {
655 reachesOperands ||= !resolvesIntersections
656 for (const operand of reference.operands!)
657 reached.set(operand.id, operand)
658 continue
659 }
660 const registered =
661 $ark.nodesById.get(reference.reference) ?? reference.target
662 const resolution =
663 isNode(registered) ? registered
664 : !reference.isIo ? reference.resolution
665 : flag !== "alters" ? (reference.operands![0] as AliasNode).resolution
666 : undefined
667 if (resolution && resolution.c[cached] !== false)
668 reached.set(resolution.id, resolution)
669 }
670 }
671 // a node this reaches reaches nothing this doesn't
672 if (isIoFinal()) for (const node of reached.values()) node.c[cached] = false
673 return false
674 }
675
676 // entered directly, it keys its output by id as an alias resolving to it does
677 get tfsById(): boolean {

Callers

nothing calls this directly

Calls 7

isNodeFunction · 0.90
isIoFinalFunction · 0.90
referencesWithoutCasesFunction · 0.85
isMethod · 0.80
getMethod · 0.65
reachesMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected