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

Function bindRef

ark/schema/scope.ts:536–572  ·  view source on GitHub ↗

`reference` copied into this scope, unless it's already this scope's or an alias

(
		reference: reference
	)

Source from the content-addressed store, hash-verified

534
535 /** `reference` copied into this scope, unless it's already this scope's or an alias */
536 bindRef<reference extends BaseNode | GenericRoot>(
537 reference: reference
538 ): reference {
539 if (
540 reference.$ === this ||
541 (isNode(reference) ?
542 reference.is("alias")
543 // a generic bound to this scope keeps the one it was defined in as its $
544 : reference.arg$ === this)
545 )
546 return reference
547 let bound = this.boundRefs.get(reference)
548 if (!bound) {
549 bound =
550 isNode(reference) ?
551 composing(() => {
552 const copy = new (reference.constructor as any)(reference, this)
553 copy.c.boundFrom = reference
554 // a bound node keeps the descriptions of the scope that created it
555 if (reference.keptDesc || !this.describesLike(reference.$)) {
556 copy.keptDesc = true
557 copy.c.description = reference.description
558 }
559 return resolveDescription(copy as BaseNode)
560 })
561 : new GenericRoot(
562 reference.params as never,
563 reference.bodyDef,
564 reference.$,
565 this as never,
566 reference.hkt,
567 reference.alias
568 )
569 this.boundRefs.set(reference, bound)
570 }
571 return bound as never
572 }
573
574 // a keyword resolved by name is described by this scope, except through a cycle
575 bindKw<reference extends BaseNode | GenericRoot>(

Callers

nothing calls this directly

Calls 6

isNodeFunction · 0.90
composingFunction · 0.90
resolveDescriptionFunction · 0.90
isMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected