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

Method alternativesOf

ark/aot/graph.ts:4038–4069  ·  view source on GitHub ↗
(
		{ node, module, kindOfKey }: Located,
		distributed: Set<Node>
	)

Source from the content-addressed store, hash-verified

4036 // a const or import holds it, e.g. `globalForSteam.steam` and
4037 // `new SteamClient(key)` for `steam = globalForSteam.steam || new SteamClient(key)`
4038 private alternativesOf(
4039 { node, module, kindOfKey }: Located,
4040 distributed: Set<Node>
4041 ): Located[] | undefined {
4042 node = unwrapChain(node)
4043 if (node.type === "Identifier") {
4044 const init = this.constInitOf(node, module, kindOfKey)
4045 if (!init) return
4046 ;({ module, kindOfKey } = init)
4047 node = unwrapChain(init.node)
4048 }
4049 if (
4050 (node.type !== "LogicalExpression" &&
4051 node.type !== "ConditionalExpression") ||
4052 distributed.has(node)
4053 )
4054 return
4055 distributed.add(node)
4056 const result: Located[] = []
4057 const collect = (node: Node) => {
4058 node = unwrapChain(node)
4059 if (node.type === "LogicalExpression") {
4060 collect(node.left)
4061 collect(node.right)
4062 } else if (node.type === "ConditionalExpression") {
4063 collect(node.consequent)
4064 collect(node.alternate)
4065 } else result.push({ node, module, kindOfKey })
4066 }
4067 collect(node)
4068 return result
4069 }
4070
4071 // e.g. `Object.freeze(A)` or `new Proxy(A, {})`, as a builtin may return
4072 // what it's passed

Callers 1

memberKindInMethod · 0.95

Calls 5

constInitOfMethod · 0.95
unwrapChainFunction · 0.90
collectFunction · 0.50
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected