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

Method clone

src/MagicString.ts:195–238  ·  view source on GitHub ↗

* Does what you'd expect.

()

Source from the content-addressed store, hash-verified

193 * Does what you'd expect.
194 */
195 clone(): this {
196 const cloned = new MagicString(this.original, {
197 filename: this.filename,
198 ignoreList: this.ignoreList,
199 offset: this.offset,
200 })
201
202 let originalChunk = this.firstChunk
203 let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone())
204
205 while (originalChunk) {
206 cloned.byStart.set(clonedChunk.start, clonedChunk)
207 cloned.byEnd.set(clonedChunk.end, clonedChunk)
208
209 const nextOriginalChunk = originalChunk.next
210 const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone()
211
212 if (nextClonedChunk) {
213 clonedChunk.next = nextClonedChunk
214 nextClonedChunk.previous = clonedChunk
215
216 clonedChunk = nextClonedChunk
217 }
218
219 originalChunk = nextOriginalChunk
220 }
221
222 cloned.lastChunk = clonedChunk
223
224 if (this.indentExclusionRanges) {
225 cloned.indentExclusionRanges = this.indentExclusionRanges.slice() as
226 | ExclusionRange
227 | ExclusionRange[]
228 }
229
230 cloned.sourcemapLocations = new BitSet(this.sourcemapLocations)
231 cloned.storedNames = { ...this.storedNames }
232
233 cloned.intro = this.intro
234 cloned.outro = this.outro
235 cloned.hasMovedChunks = this.hasMovedChunks
236
237 return cloned as this
238 }
239
240 /**
241 * 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