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

Function bindUnit

ark/schema/units.ts:271–308  ·  view source on GitHub ↗
(
	declared: readonly BaseNode[],
	unitFn: CompiledUnit,
	compiledTraversals: PrecompiledTraversals[],
	byId: Record<string, BaseNode>,
	owningScope?: BaseScope,
	unbound?: UnboundTraversals
)

Source from the content-addressed store, hash-verified

269}
270
271const bindUnit = (
272 declared: readonly BaseNode[],
273 unitFn: CompiledUnit,
274 compiledTraversals: PrecompiledTraversals[],
275 byId: Record<string, BaseNode>,
276 owningScope?: BaseScope,
277 unbound?: UnboundTraversals
278): void => {
279 for (let i = 0; i < declared.length; i++) {
280 const node = declared[i]
281 if (unbound?.has(node)) {
282 unbound.set(node, compiledTraversals[i])
283 continue
284 }
285 // if node has already been bound to another scope or anonymous type, don't rebind it
286 if (node.unitFn && (!owningScope || node.$ !== owningScope)) continue
287 if (!Object.isExtensible(node)) {
288 node.c.preJit = undefined
289 continue
290 }
291 const [tAllows, tApply, tTransform] = compiledTraversals[i]
292 if (node.c.preJit) {
293 node.allows = node.c.preJit
294 node.c.preJit = undefined
295 }
296 node.tAllows = tAllows
297 if (node.isRoot() && !node.allowsCtx) {
298 // if the reference doesn't require context, we can assign over
299 // it directly to avoid having to initialize it
300 node.allows = tAllows as never
301 }
302 node.tApply = tApply
303 if (tTransform) node.tTransform = tTransform
304 node.unitFn = unitFn
305 delete node.c.rootApply
306 node.c.isReusableLeaf = isLeafIn(node, byId)
307 }
308}
309
310type PrecompiledTraversals = [
311 allows: TraverseAllows,

Callers 2

precompileFunction · 0.85
bindPrecompiledFunction · 0.85

Calls 3

isLeafInFunction · 0.85
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected