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

Method reaches

ark/aot/graph.ts:5065–5188  ·  view source on GitHub ↗
(
		node: Node,
		module: SourceModule,
		held: boolean,
		reach: Reach
	)

Source from the content-addressed store, hash-verified

5063 }
5064
5065 private reaches(
5066 node: Node,
5067 module: SourceModule,
5068 held: boolean,
5069 reach: Reach
5070 ): boolean {
5071 const seen = held ? reach.held : reach.exact
5072 if (seen.has(node)) return false
5073 seen.add(node)
5074 const follow = (next: Node) => this.reaches(next, module, held, reach)
5075 const followExact = (next: Node) => this.reaches(next, module, false, reach)
5076 const followHeld = (next: Node) => this.reaches(next, module, true, reach)
5077 const [operand, operator] = operatorOf(node)
5078 switch (operator?.type) {
5079 case "MemberExpression": {
5080 if (operator.object !== operand || isWriteTarget(operator)) return false
5081 // a read off what may be a Scope is checked by scopeReadOf
5082 if (!held) return !mayBeOtherArk(this.kindOf(operand, module))
5083 const kind = this.kindOf(operator, module)
5084 return (
5085 (mayBeOtherArk(kind) && followExact(operator)) ||
5086 (mayHoldArk(kind) && follow(operator))
5087 )
5088 }
5089 case "CallExpression":
5090 case "NewExpression": {
5091 if (operator.callee === operand) return held
5092 const fn = this.functionOf(operator.callee, module)
5093 if (fn?.[1] !== module) return true
5094 // e.g. `hand($)` with `hand = s => each(s)`
5095 const param = runtimeParamsOf(fn[0])[
5096 operator.arguments.indexOf(operand as never)
5097 ]
5098 return (
5099 param?.type !== "Identifier" ||
5100 this.readsReachUnseen(
5101 module.scopes.bindingsById.get(param),
5102 module,
5103 held,
5104 reach
5105 )
5106 )
5107 }
5108 case "ConditionalExpression":
5109 case "LogicalExpression":
5110 return (
5111 (operator.type === "LogicalExpression" ||
5112 operator.test !== operand) &&
5113 follow(operator)
5114 )
5115 case "SequenceExpression":
5116 return (
5117 operator.expressions[operator.expressions.length - 1] === operand &&
5118 follow(operator)
5119 )
5120 case "AwaitExpression":
5121 return follow(operator)
5122 case "ArrowFunctionExpression":

Callers 6

reachesUnseenMethod · 0.95
followMethod · 0.95
followExactMethod · 0.95
followHeldMethod · 0.95
readsReachUnseenMethod · 0.95
returnReachesUnseenMethod · 0.95

Calls 14

kindOfMethod · 0.95
functionOfMethod · 0.95
readsReachUnseenMethod · 0.95
returnReachesUnseenMethod · 0.95
operatorOfFunction · 0.90
isWriteTargetFunction · 0.90
runtimeParamsOfFunction · 0.90
mayBeOtherArkFunction · 0.85
mayHoldArkFunction · 0.85
enclosingFunctionOfFunction · 0.85
followFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected