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

Method clone

src/MagicString.ts:192–229  ·  view source on GitHub ↗

* Does what you'd expect.

()

Source from the content-addressed store, hash-verified

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