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

Function methodIn

ark/aot/graph.ts:729–754  ·  view source on GitHub ↗
(
	cls: Class,
	name: string,
	module: SourceModule
)

Source from the content-addressed store, hash-verified

727
728// a method each instance of a class runs, unless one may replace it
729const methodIn = (
730 cls: Class,
731 name: string,
732 module: SourceModule
733): [FunctionNode, SourceModule] | undefined => {
734 let method: FunctionNode | undefined
735 for (const element of cls.body.body) {
736 if (
737 (element.type !== "MethodDefinition" &&
738 element.type !== "PropertyDefinition") ||
739 element.static ||
740 keyNameOf(element) !== name
741 )
742 continue
743 const value = element.value && unwrapExpression(element.value)
744 if (
745 method ||
746 !value ||
747 !isFunctionNode(value) ||
748 (element.type === "MethodDefinition" && element.kind !== "method")
749 )
750 return
751 method = value
752 }
753 return method && !replacesMember(cls, name) ? [method, module] : undefined
754}
755
756// e.g. `store` read only as `store.add(...)` or `new Store()`, so nothing
757// can replace a member its instances run

Callers 1

instanceMethodOfMethod · 0.85

Calls 4

unwrapExpressionFunction · 0.90
isFunctionNodeFunction · 0.85
replacesMemberFunction · 0.85
keyNameOfFunction · 0.70

Tested by

no test coverage detected