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

Function edit

ark/aot/flat.ts:133–160  ·  view source on GitHub ↗
(
		module: SourceModule,
		edits: Repointed[],
		rename: (specifier: string) => string
	)

Source from the content-addressed store, hash-verified

131 for (const key of flattened) delete codes[key]
132 codes[specifier] = flat.writeModule([...read])
133 const edit = (
134 module: SourceModule,
135 edits: Repointed[],
136 rename: (specifier: string) => string
137 ): MagicString | undefined => {
138 let s: MagicString | undefined
139 for (const { start, end, imports } of edits) {
140 s ??= new MagicString(module.source)
141 s.overwrite(start, end, writeImports(imports, rename))
142 }
143 for (const match of module.source.matchAll(virtualSource)) {
144 const target = rename(match[1])
145 if (
146 target === match[1] ||
147 edits.some(
148 ({ start, end }) => start <= match.index && match.index < end
149 )
150 )
151 continue
152 s ??= new MagicString(module.source)
153 s.overwrite(
154 match.index,
155 match.index + match[0].length,
156 JSON.stringify(target)
157 )
158 }
159 return s
160 }
161 for (const [key, edits] of repointed) {
162 if (key in codes)
163 codes[key] = edit(parsed.get(key)!, edits, unrenamed)!.toString()

Callers 1

flattenBundleFunction · 0.70

Calls 2

writeImportsFunction · 0.70
renameFunction · 0.70

Tested by

no test coverage detected