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

Function unitTextsOf

ark/aot/flat.ts:1111–1138  ·  view source on GitHub ↗
(
	units: UnitModule[],
	creations: Creation[]
)

Source from the content-addressed store, hash-verified

1109
1110// each unit's declaration, then each creation's, unless a name is declared twice
1111const unitTextsOf = (
1112 units: UnitModule[],
1113 creations: Creation[]
1114): UnitTexts | undefined => {
1115 const specifiersByName = new Map<string, string>()
1116 const texts: string[] = []
1117 for (const unit of units) {
1118 for (const declaration of unit.declarations) {
1119 texts.push(unit.module.source.slice(declaration.start, declaration.end))
1120 specifiersByName.set(declaredNameOf(declaration), unit.specifier)
1121 }
1122 }
1123 const created = new Set<string>()
1124 const creators = new Set<string>()
1125 for (const { name, creator, shared, args } of creations) {
1126 if (specifiersByName.has(name) || created.has(name)) return
1127 created.add(name)
1128 if (shared && specifiersByName.has(shared)) return
1129 if (shared && !creators.has(shared)) {
1130 creators.add(shared)
1131 texts.push(`const ${shared} = (${creator})`)
1132 }
1133 texts.push(
1134 `const ${name} = ${shared ?? `(${creator})`}(${args.join(", ")})`
1135 )
1136 }
1137 return { texts, specifiersByName, created }
1138}
1139
1140const writeFlat = (
1141 units: UnitModule[],

Callers 1

writeFlatFunction · 0.85

Calls 5

declaredNameOfFunction · 0.70
pushMethod · 0.45
setMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected