MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / clone

Method clone

src/MagicString.ts:283–326  ·  view source on GitHub ↗

* Does what you'd expect.

()

Source from the content-addressed store, hash-verified

281 * Does what you'd expect.
282 */
283 clone(): this {
284 const cloned = new MagicString(this.original, {
285 filename: this.filename,
286 ignoreList: this.ignoreList,
287 offset: this.offset,
288 })
289
290 let originalChunk = this.firstChunk
291 let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone())
292
293 while (originalChunk) {
294 cloned.byStart.set(clonedChunk.start, clonedChunk)
295 cloned.byEnd.set(clonedChunk.end, clonedChunk)
296
297 const nextOriginalChunk = originalChunk.next
298 const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone()
299
300 if (nextClonedChunk) {
301 clonedChunk.next = nextClonedChunk
302 nextClonedChunk.previous = clonedChunk
303
304 clonedChunk = nextClonedChunk
305 }
306
307 originalChunk = nextOriginalChunk
308 }
309
310 cloned.lastChunk = clonedChunk
311
312 if (this.indentExclusionRanges) {
313 cloned.indentExclusionRanges = this.indentExclusionRanges.slice() as
314 | ExclusionRange
315 | ExclusionRange[]
316 }
317
318 cloned.sourcemapLocations = new BitSet(this.sourcemapLocations)
319 cloned.storedNames = { ...this.storedNames }
320
321 cloned.intro = this.intro
322 cloned.outro = this.outro
323 cloned.hasMovedChunks = this.hasMovedChunks
324
325 return cloned as this
326 }
327
328 /**
329 * Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.

Callers 1

snipMethod · 0.95

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected