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

Method mayWritesThroughThis

ark/aot/graph.ts:5354–5378  ·  view source on GitHub ↗
(
		fn: FunctionNode,
		module: SourceModule,
		held: Held
	)

Source from the content-addressed store, hash-verified

5352 // what a method a value holds may write of it through `this`, as
5353 // `swap() { this.t = T }` does once the program calls `o.swap()`
5354 mayWritesThroughThis(
5355 fn: FunctionNode,
5356 module: SourceModule,
5357 held: Held
5358 ): Node[] {
5359 const key = `${held.depth}:${held.copied}`
5360 let byHeld = this.thisWritesByFn.get(fn)
5361 if (!byHeld) this.thisWritesByFn.set(fn, (byHeld = new Map()))
5362 let result = byHeld.get(key)
5363 if (result) return result
5364 byHeld.set(key, (result = []))
5365 for (const node of [...fn.params, fn.body!]) {
5366 walk(node, child => {
5367 if (child.type === "ThisExpression") {
5368 const write = this.mayWriteFrom(child, module, held)
5369 if (write) result.push(write)
5370 }
5371 // a function other than an arrow has a `this` of its own
5372 return (
5373 !isFunctionNode(child) || child.type === "ArrowFunctionExpression"
5374 )
5375 })
5376 }
5377 return result
5378 }
5379
5380 // reads the whole program, whose other modules may write what one exports
5381 readView(view: ProgramView | undefined): void {

Callers 2

mayWriteFromMethod · 0.95
writtenThroughThisMethod · 0.80

Calls 6

mayWriteFromMethod · 0.95
walkFunction · 0.90
isFunctionNodeFunction · 0.85
getMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected