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

Function writeUnit

ark/schema/units.ts:546–567  ·  view source on GitHub ↗
(
	dependencyNames: string[],
	refNames: string[],
	members: UnitMember[],
	traversals: string[][]
)

Source from the content-addressed store, hash-verified

544}
545
546const writeUnit = (
547 dependencyNames: string[],
548 refNames: string[],
549 members: UnitMember[],
550 traversals: string[][]
551) => {
552 // passed as arrays: too many args overflow a call
553 const unit = new CompiledFunction<CompiledUnit, ["dependencies", "refs"]>(
554 "dependencies",
555 "refs"
556 )
557 // strict, as a module is
558 unit.line(`"use strict"`)
559 for (let i = 0; i < dependencyNames.length; i++)
560 unit.const(dependencyNames[i], `dependencies[${i}]`)
561 for (let i = 0; i < refNames.length; i++)
562 unit.const(refNames[i], `refs[${i}]`)
563 for (const [name, source] of members) unit.const(name, source)
564 return unit.return(
565 `[${traversals.map(names => `[${names.join(", ")}]`).join(", ")}]`
566 )
567}
568
569export type UnitMember = [name: string, source: string]
570

Callers 3

precompileInPlaceFunction · 0.85
precompileReferencesFunction · 0.85
writePrecompiledUnitFunction · 0.85

Calls 4

lineMethod · 0.95
constMethod · 0.95
returnMethod · 0.95
mapMethod · 0.65

Tested by

no test coverage detected