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

Method readHolder

ark/aot/usage.ts:813–862  ·  view source on GitHub ↗
(
		node: Node,
		parent: Node | null | undefined,
		runtime: RuntimeModule,
		path: readonly string[]
	)

Source from the content-addressed store, hash-verified

811 // a read of an object holding a validator at path: on to the member at its
812 // next key, or one at a computed key, which may be it
813 private readHolder(
814 node: Node,
815 parent: Node | null | undefined,
816 runtime: RuntimeModule,
817 path: readonly string[]
818 ): void {
819 const { module } = runtime
820 if (
821 parent?.type === "MemberExpression" &&
822 parent.object === node &&
823 !isWriteTarget(parent)
824 ) {
825 const name = memberNameOf(parent)
826 const [member, memberParent] = operatorOf(parent)
827 const isCall =
828 (memberParent?.type === "CallExpression" &&
829 memberParent.callee === member) ||
830 (memberParent?.type === "TaggedTemplateExpression" &&
831 memberParent.tag === member)
832 // returns its receiver, whatever it holds
833 if (name === "valueOf" && path[0] !== name && isCall) {
834 const [call, callParent] = operatorOf(memberParent)
835 return this.read(call, callParent, runtime, path)
836 }
837 // a patched builtin prototype method or computed call (e.g. `o[k]()`,
838 // where k may be "valueOf") needs Readers to follow or lose safely
839 if (
840 isCall &&
841 ((name === undefined && path.length > 0) ||
842 (String(name) !== path[0] && this.thisReads.patchesBuiltins))
843 ) {
844 this.handedOff ??= `${module.positionOf(node)} calls ${module.snippetOf(member)} on what holds a validator at ${path.join(".")}`
845 return
846 }
847 if (
848 (typeof name === "string" || typeof name === "number") &&
849 String(name) !== path[0]
850 )
851 return
852 return this.read(member, memberParent, runtime, path.slice(1))
853 }
854 const holder = `${module.snippetOf(node)}, which holds a validator at ${path.join(".")},`
855 const passed =
856 parent?.type === "CallExpression" || parent?.type === "NewExpression"
857 this.handedOff ??= `${module.positionOf(node)} ${
858 passed ?
859 `passes ${holder} to a function, which may read any member`
860 : `reads ${holder} other than to read a member`
861 }`
862 }
863
864 // a call's second argument is where its failure may pipe
865 private readArguments(call: Extract<Node, { type: "CallExpression" }>): void {

Callers 1

readMethod · 0.95

Calls 7

readMethod · 0.95
isWriteTargetFunction · 0.90
memberNameOfFunction · 0.90
operatorOfFunction · 0.90
StringInterface · 0.85
positionOfMethod · 0.80
snippetOfMethod · 0.80

Tested by

no test coverage detected