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

Function reachesUserCode

ark/schema/structure/structure.ts:226–245  ·  view source on GitHub ↗
(root: BaseNode)

Source from the content-addressed store, hash-verified

224// a keyword's predicate isn't user code. a union's cases hold what its branches
225// do. every node finding none reaches none too, so a cycle is walked once
226const reachesUserCode = (root: BaseNode): boolean => {
227 const final = isResolutionFinal()
228 const reached = new Set<BaseNode>()
229 const reaches = (node: BaseNode): boolean => {
230 if (node.userCode) return true
231 if (!node.hasAlias || reached.has(node)) return false
232 if (node.c.reachesUserCode !== undefined) return node.c.reachesUserCode
233 reached.add(node)
234 const found =
235 node.is("alias") ?
236 reaches(node.resolution)
237 : node.children.some(reaches) ||
238 (!node.is("union") && node.otherRefs.some(reaches))
239 if (found && final) node.c.reachesUserCode = true
240 return found
241 }
242 if (reaches(root)) return true
243 if (final) for (const node of reached) node.c.reachesUserCode = false
244 return false
245}
246
247// 0 compares data itself, 1 reads a primitive it points to, 2 walks an object
248const branchCost = (branch: BaseRoot): number => {

Callers 1

orderedForAllowsFunction · 0.85

Calls 2

isResolutionFinalFunction · 0.90
reachesFunction · 0.70

Tested by

no test coverage detected