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

Function fieldValuesOf

ark/aot/graph.ts:6446–6488  ·  view source on GitHub ↗
(cls: Node)

Source from the content-addressed store, hash-verified

6444const fieldValuesByClass = new WeakMap<Node, Record<string, Node[]>>()
6445
6446const fieldValuesOf = (cls: Node): Record<string, Node[]> => {
6447 const cached = fieldValuesByClass.get(cls)
6448 if (cached) return cached
6449 const result: Record<string, Node[]> = Object.create(null)
6450 const add = (name: unknown, ...values: Node[]) => {
6451 if (typeof name === "string") (result[name] ??= []).push(...values)
6452 }
6453 walk(cls, node => {
6454 if (node.type === "PropertyDefinition" && !node.static && node.value)
6455 add(keyNameOf(node), node.value)
6456 else if (
6457 node.type === "AssignmentExpression" &&
6458 node.left.type === "MemberExpression" &&
6459 node.left.object.type === "ThisExpression"
6460 )
6461 add(memberNameOf(node.left), node.right)
6462 else if (
6463 node.type === "MethodDefinition" &&
6464 (node.kind === "get" || node.kind === "method") &&
6465 !node.static
6466 )
6467 add(keyNameOf(node), node.value)
6468 else if (
6469 node.type === "CallExpression" &&
6470 node.callee.type === "MemberExpression" &&
6471 node.callee.object.type === "MemberExpression" &&
6472 node.callee.object.object.type === "ThisExpression" &&
6473 (memberNameOf(node.callee) as never) in storingMethods
6474 )
6475 add(memberNameOf(node.callee.object), ...(node.arguments as Node[]))
6476 // e.g. `constructor(readonly schema: Schema) {}`, its binding's id
6477 else if (node.type === "TSParameterProperty") {
6478 const id =
6479 node.parameter.type === "AssignmentPattern" ?
6480 node.parameter.left
6481 : node.parameter
6482 if (id.type === "Identifier") add(id.name, id)
6483 }
6484 return true
6485 })
6486 fieldValuesByClass.set(cls, result)
6487 return result
6488}
6489
6490const memberWritesByModule = new WeakMap<SourceModule, Record<string, Node[]>>()
6491

Callers 3

instanceKindOfMethod · 0.85
fieldKindInMethod · 0.85
mayDeclareMethod · 0.85

Calls 6

walkFunction · 0.90
addFunction · 0.70
keyNameOfFunction · 0.70
memberNameOfFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected