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

Function getInstantiationsContributedByNode

ark/attest/cache/utils.ts:111–141  ·  view source on GitHub ↗
(
	file: ts.SourceFile,
	benchBlock: ts.FunctionExpression | ts.ArrowFunction
)

Source from the content-addressed store, hash-verified

109const instantiationsByPath: { [path: string]: number } = {}
110
111export const getInstantiationsContributedByNode = (
112 file: ts.SourceFile,
113 benchBlock: ts.FunctionExpression | ts.ArrowFunction
114): number => {
115 const originalPath = filePath(file.fileName)
116 const fakePath = originalPath + ".nonexistent.ts"
117
118 const baselineFile = getBaselineSourceFile(file)
119
120 const baselineFileWithBenchBlock =
121 baselineFile + `\nconst $attestIsolatedBench = ${benchBlock.getFullText()}`
122
123 if (!instantiationsByPath[fakePath]) {
124 const instantiationsWithoutNode = getInstantiationsWithFile(
125 baselineFile,
126 fakePath
127 )
128
129 instantiationsByPath[fakePath] = instantiationsWithoutNode
130 }
131
132 const instantiationsWithNode = getInstantiationsWithFile(
133 baselineFileWithBenchBlock,
134 fakePath,
135 // a generic block's result would be inferred from constraints it's
136 // never called with
137 !benchBlock.typeParameters?.length
138 )
139
140 return instantiationsWithNode - instantiationsByPath[fakePath]
141}
142
143/**
144 * TS only evaluates the members of many types, e.g. mapped types, once

Callers 2

Calls 3

filePathFunction · 0.90
getBaselineSourceFileFunction · 0.85

Tested by

no test coverage detected