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

Method clone

src/MagicString.ts:291–334  ·  view source on GitHub ↗

* Does what you'd expect.

()

Source from the content-addressed store, hash-verified

289 * Does what you'd expect.
290 */
291 clone(): this {
292 const cloned = new MagicString(this.original, {
293 filename: this.filename,
294 ignoreList: this.ignoreList,
295 offset: this.offset,
296 })
297
298 let originalChunk = this.firstChunk
299 let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone())
300
301 while (originalChunk) {
302 cloned.byStart.set(clonedChunk.start, clonedChunk)
303 cloned.byEnd.set(clonedChunk.end, clonedChunk)
304
305 const nextOriginalChunk = originalChunk.next
306 const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone()
307
308 if (nextClonedChunk) {
309 clonedChunk.next = nextClonedChunk
310 nextClonedChunk.previous = clonedChunk
311
312 clonedChunk = nextClonedChunk
313 }
314
315 originalChunk = nextOriginalChunk
316 }
317
318 cloned.lastChunk = clonedChunk
319
320 if (this.indentExclusionRanges) {
321 cloned.indentExclusionRanges = this.indentExclusionRanges.slice() as
322 | ExclusionRange
323 | ExclusionRange[]
324 }
325
326 cloned.sourcemapLocations = new BitSet(this.sourcemapLocations)
327 cloned.storedNames = { ...this.storedNames }
328
329 cloned.intro = this.intro
330 cloned.outro = this.outro
331 cloned.hasMovedChunks = this.hasMovedChunks
332
333 return cloned as this
334 }
335
336 /**
337 * 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