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

Function flatSiteOf

ark/aot/flat.ts:332–377  ·  view source on GitHub ↗
(
	site: SourceModule,
	s: MagicString | undefined,
	created: Creation[],
	kept: KeptCode,
	specifier: string,
	unwrapped: Set<string>
)

Source from the content-addressed store, hash-verified

330// a site importing what it creates from the flat module, without the
331// annotations on what it kept
332const flatSiteOf = (
333 site: SourceModule,
334 s: MagicString | undefined,
335 created: Creation[],
336 kept: KeptCode,
337 specifier: string,
338 unwrapped: Set<string>
339): FlatSite => {
340 const source = JSON.stringify(specifier)
341 for (const [start, end] of keptAnnotationsIn(site, kept)) {
342 if (
343 created.some(creation => creation.start <= start && end <= creation.end)
344 )
345 continue
346 s ??= new MagicString(site.source)
347 s.remove(start, end)
348 }
349 const prefix = prefixOf(site.source, site.id)
350 for (const { start, end, name, declared } of created) {
351 s ??= new MagicString(site.source)
352 // an import, which a bundler doesn't write as a variable holding another
353 if (declared) {
354 s.overwrite(
355 declared.start,
356 declared.end,
357 `import { ${name} as ${declared.name} } from ${source}\n${declared.exported ? `export { ${declared.name} }\n` : ""}`
358 )
359 // a read of its one member reads the validator it is
360 if (unwrapped.has(name)) {
361 for (const [start, end] of declared.memberReads!.spans)
362 s.remove(start, end)
363 }
364 } else {
365 const local = `${prefix}_${name}`
366 s.overwrite(start, end, local)
367 writeImportsAhead(
368 s,
369 site.program,
370 `\nimport { ${name} as ${local} } from ${source}`
371 )
372 }
373 }
374 return s ?
375 { code: s.toString(), map: s.generateMap({ hires: "boundary" }) }
376 : { code: site.source, map: undefined }
377}
378
379const unrenamed = (specifier: string) => specifier
380

Callers 1

flattenBundleFunction · 0.85

Calls 6

prefixOfFunction · 0.90
writeImportsAheadFunction · 0.90
keptAnnotationsInFunction · 0.85
removeMethod · 0.80
toStringMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected