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

Method split

src/Chunk.ts:115–152  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

113 }
114
115 split(index: number): Chunk {
116 const sliceIndex = index - this.start
117
118 const originalBefore = this.original.slice(0, sliceIndex)
119 const originalAfter = this.original.slice(sliceIndex)
120
121 this.original = originalBefore
122
123 const newChunk = new Chunk(index, this.end, originalAfter)
124 newChunk.outro = this.outro
125 this.outro = ''
126
127 this.end = index
128
129 if (this.edited) {
130 // after split we should save the edit content record into the correct chunk
131 // to make sure sourcemap correct
132 // For example:
133 // ' test'.trim()
134 // split -> ' ' + 'test'
135 // ✔️ edit -> '' + 'test'
136 // ✖️ edit -> 'test' + ''
137 // TODO is this block necessary?...
138 newChunk.edit('', false)
139 this.content = ''
140 }
141 else {
142 this.content = originalBefore
143 }
144
145 newChunk.next = this.next
146 if (newChunk.next)
147 newChunk.next.previous = newChunk
148 newChunk.previous = this
149 this.next = newChunk
150
151 return newChunk
152 }
153
154 toString(): string {
155 return this.intro + this.content + this.outro

Callers 10

trimEndMethod · 0.95
trimStartMethod · 0.95
generateDecodedMapMethod · 0.45
generateDecodedMapMethod · 0.45
_splitChunkMethod · 0.45
getRelativePathFunction · 0.45
getLocatorFunction · 0.45
guessIndentFunction · 0.45
advanceMethod · 0.45

Calls 2

editMethod · 0.95
sliceMethod · 0.45

Tested by

no test coverage detected