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

Method isSameRead

ark/aot/sameEachRun.ts:203–239  ·  view source on GitHub ↗
(
		id: Node & { name: string },
		fn: Node,
		module: SourceModule,
		seen: Set<Node>
	)

Source from the content-addressed store, hash-verified

201 }
202
203 private isSameRead(
204 id: Node & { name: string },
205 fn: Node,
206 module: SourceModule,
207 seen: Set<Node>
208 ): boolean {
209 const reference = module.scopes.byId.get(id)
210 // e.g. a member's or key's name
211 if (!reference) return true
212 const { binding } = reference
213 if (!binding) return id.name !== "eval"
214 const isSelf = binding.kind === "function" && binding.declaration === fn
215 if (!isSelf && contains(fn, binding.id)) return true
216 const located = this.locate(binding, module)
217 if (located === "arktype") return true
218 if (!located) return false
219 const [origin, declaring] = located
220 const source =
221 origin.kind === "function" ?
222 !origin.writes.length && origin.declaration
223 : origin.kind === "const" && initOf(origin)
224 if (!source) return false
225 // a read passing a function on could write what's on it, and nothing
226 // keeps a run's from another's where one compares them
227 if (isFunctionNode(source)) {
228 const [callee, parent] = operatorOf(id)
229 return (
230 parent?.type === "CallExpression" &&
231 parent.callee === callee &&
232 this.reads(source, declaring, seen)
233 )
234 }
235 return (
236 this.fixedDepthOfBinding(origin, declaring, new Set()) !== undefined ||
237 this.isSameType(origin, declaring, seen)
238 )
239 }
240
241 // a Type is immutable, so it differs only by the functions it holds
242 private isSameType(

Callers 1

readsMethod · 0.95

Calls 9

locateMethod · 0.95
readsMethod · 0.95
fixedDepthOfBindingMethod · 0.95
isSameTypeMethod · 0.95
containsFunction · 0.90
initOfFunction · 0.90
isFunctionNodeFunction · 0.90
operatorOfFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected