MCPcopy
hub / github.com/arktypeio/arktype / bindPrecompilation

Function bindPrecompilation

ark/schema/scope.ts:182–211  ·  view source on GitHub ↗
(
	references: readonly BaseNode[],
	precompiler: CompiledFunction<() => PrecompiledReferences>,
	owningScope?: BaseScope
)

Source from the content-addressed store, hash-verified

180 bindPrecompilation(references, precompileReferences(references))
181
182const bindPrecompilation = (
183 references: readonly BaseNode[],
184 precompiler: CompiledFunction<() => PrecompiledReferences>,
185 owningScope?: BaseScope
186): void => {
187 const precompilation = precompiler.write(rootScopeFnName, 4)
188 const compiledTraversals = precompiler.compile()()
189
190 for (const node of references) {
191 if (node.precompilation && (!owningScope || node.$ !== owningScope)) {
192 // if node has already been bound to another scope or anonymous type, don't rebind it
193 continue
194 }
195 node.traverseAllows =
196 compiledTraversals[`${node.id}Allows`].bind(compiledTraversals)
197 if (node.isRoot() && !node.allowsRequiresContext) {
198 // if the reference doesn't require context, we can assign over
199 // it directly to avoid having to initialize it
200 node.allows = node.traverseAllows as never
201 }
202 node.traverseApply =
203 compiledTraversals[`${node.id}Apply`].bind(compiledTraversals)
204
205 if (compiledTraversals[`${node.id}Optimistic`]) {
206 ;(node as UnionNode).traverseOptimistic =
207 compiledTraversals[`${node.id}Optimistic`].bind(compiledTraversals)
208 }
209 node.precompilation = precompilation
210 }
211}
212
213export type PrecompiledReferences = {
214 [k: `${string}Allows`]: TraverseAllows

Callers 2

precompileFunction · 0.85
exportFunction · 0.85

Calls 2

writeMethod · 0.80
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…