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

Function resolveReachedAliases

ark/schema/node.ts:1941–1956  ·  view source on GitHub ↗
(root: BaseNode)

Source from the content-addressed store, hash-verified

1939// without listing it for a Type that may never compile. what a node reaches
1940// resolved once, so a Type sharing it doesn't walk it again
1941export const resolveReachedAliases = (root: BaseNode): void => {
1942 const reached = new Set<BaseNode>()
1943 const aliases: AliasNode[] = []
1944 const include = (node: BaseNode): void => {
1945 if (!node.hasAlias || node.c.reachedResolved || reached.has(node)) return
1946 reached.add(node)
1947 if (node.is("alias")) aliases.push(node)
1948 for (let i = 0; i < node.children.length; i++) include(node.children[i])
1949 // a union's cases hold what its branches do, and aren't created until it's used
1950 if (node.is("union")) return
1951 for (const referenced of node.otherRefs) include(referenced)
1952 }
1953 include(root)
1954 for (let i = 0; i < aliases.length; i++) include(aliases[i].resolution)
1955 for (const node of reached) node.c.reachedResolved = true
1956}
1957
1958/** a literal key (named property) or a node (index signatures) representing part of a type structure */
1959export type KeyOrKeyNode = Key | BaseRoot

Callers 1

finFunction · 0.90

Calls 1

includeFunction · 0.70

Tested by

no test coverage detected