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

Method writeInto

ark/aot/precompile.ts:8433–8467  ·  view source on GitHub ↗
(
		id: Node,
		module: SourceModule,
		isWritten: (value: unknown) => boolean
	)

Source from the content-addressed store, hash-verified

8431 }
8432
8433 private writeInto(
8434 id: Node,
8435 module: SourceModule,
8436 isWritten: (value: unknown) => boolean
8437 ): [write: Node, value: Node, isDirect: boolean] | undefined {
8438 // reads since the last call, any of which may be arktype's
8439 const objects: Node[] = [id]
8440 for (let node = id; ; node = node.parent!) {
8441 const parent = node.parent!
8442 if (isTransparent(parent)) continue
8443 let write: Node | undefined
8444 if (parent.type === "MemberExpression" && parent.object === node) {
8445 if (isWriteTarget(parent)) write = writeOf(parent)
8446 } else if (parent.type === "CallExpression" && parent.callee === node)
8447 objects.length = 0
8448 else if (
8449 parent.type === "CallExpression" &&
8450 parent.arguments[0] === node &&
8451 isObjectWrite(parent.callee, module)
8452 )
8453 write = parent
8454 else return
8455 if (write) {
8456 for (let i = objects.length - 1; i >= 0; i--) {
8457 const state = this.interpreter.evaluateSite(
8458 createSiteState(objects[i], module, { readsLiterals: true })
8459 )
8460 if (isWritten(state.value))
8461 return [write, objects[i], i === objects.length - 1]
8462 }
8463 return
8464 }
8465 objects.push(parent)
8466 }
8467 }
8468
8469 // e.g. `(await import("arktype")).type`, loading arktype/runtime with no
8470 // definition to precompile

Callers 2

writeReasonsInMethod · 0.95

Calls 8

isTransparentFunction · 0.90
isWriteTargetFunction · 0.90
writeOfFunction · 0.90
isObjectWriteFunction · 0.90
createSiteStateFunction · 0.90
isWrittenFunction · 0.85
evaluateSiteMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected