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

Function mapToSource

ark/aot/host.ts:605–633  ·  view source on GitHub ↗
(
	emitted: EmittedMap,
	precompiled: EmittedMap | undefined,
	source: string
)

Source from the content-addressed store, hash-verified

603}
604
605export const mapToSource = (
606 emitted: EmittedMap,
607 precompiled: EmittedMap | undefined,
608 source: string
609): EmittedMap => {
610 if (!precompiled) return emitted
611 const lines = decode(precompiled.mappings)
612 const mappings: SourceMapMappings = decode(emitted.mappings).map(line =>
613 line.flatMap((segment): SourceMapSegment[] => {
614 if (segment.length === 1) return [segment]
615 const [column, sourceIndex, sourceLine, sourceColumn] = segment
616 const original = segmentAt(lines[sourceLine], sourceColumn)
617 // what the precompiler wrote maps to no line of the source
618 if (!original) return []
619 const traced: SourceMapSegment = [
620 column,
621 sourceIndex,
622 original[2],
623 original[3] + sourceColumn - original[0]
624 ]
625 return [segment.length === 5 ? [...traced, segment[4]] : traced]
626 })
627 )
628 return {
629 ...emitted,
630 mappings: encode(mappings),
631 ...(emitted.sourcesContent && { sourcesContent: [source] })
632 }
633}
634
635// the last segment starting at or before the column, sorted by column
636const segmentAt = (

Callers 3

linkStrategyMethod · 0.90
flatWrittenOfFunction · 0.90
writeOutputsFunction · 0.90

Calls 4

segmentAtFunction · 0.85
mapMethod · 0.65
decodeFunction · 0.50
encodeFunction · 0.50

Tested by

no test coverage detected