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

Function gatherInlineInstantiationData

ark/attest/cache/utils.ts:45–87  ·  view source on GitHub ↗
(
	file: ts.SourceFile,
	assertionsByFile: Record<string, any[]>,
	instantiationMethodCalls: string[]
)

Source from the content-addressed store, hash-verified

43 * Preserves any JSDoc comments that are associated with the original expression
44 */
45export const gatherInlineInstantiationData = (
46 file: ts.SourceFile,
47 assertionsByFile: Record<string, any[]>,
48 instantiationMethodCalls: string[]
49): void => {
50 const expressions = getCallExpressionsByName(file, instantiationMethodCalls)
51 if (!expressions.length) return
52
53 const enclosingFunctions = expressions.map(expression => {
54 const attestInstantiationsExpression = getFirstAncestorByKindOrThrow(
55 expression,
56 ts.SyntaxKind.ExpressionStatement
57 )
58 return {
59 ancestor: getFirstAncestorByKindOrThrow(
60 attestInstantiationsExpression,
61 ts.SyntaxKind.ExpressionStatement
62 ),
63 position: getCallLocationFromCallExpression(expression)
64 }
65 })
66 const instantiationInfo = enclosingFunctions.map(enclosingFunction => {
67 const body = getDescendants(enclosingFunction.ancestor).find(
68 node => ts.isArrowFunction(node) || ts.isFunctionExpression(node)
69 ) as ts.ArrowFunction | ts.FunctionExpression | undefined
70 if (!body) {
71 throwInternalError(
72 `Unable to resolve source associated with TS Node:
73${enclosingFunction.ancestor.getText()}`
74 )
75 }
76
77 return {
78 location: enclosingFunction.position,
79 count: getInstantiationsContributedByNode(file, body)
80 }
81 })
82 const assertions = assertionsByFile[getFileKey(file.fileName)] ?? []
83 assertionsByFile[getFileKey(file.fileName)] = [
84 ...assertions,
85 ...instantiationInfo
86 ]
87}
88
89export const getCallExpressionsByName = (
90 startNode: ts.Node,

Callers 1

analyzeProjectAssertionsFunction · 0.90

Calls 9

getDescendantsFunction · 0.90
throwInternalErrorFunction · 0.90
getFileKeyFunction · 0.90
findMethod · 0.80
getCallExpressionsByNameFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected