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

Method split

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

Source from the content-addressed store, hash-verified

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

Callers 9

trimEndMethod · 0.95
trimStartMethod · 0.95
indent.test.tsFile · 0.45
generateDecodedMapMethod · 0.45
generateDecodedMapMethod · 0.45
_splitChunkMethod · 0.45
getRelativePathFunction · 0.45
guessIndentFunction · 0.45

Calls 2

editMethod · 0.95
sliceMethod · 0.45

Tested by

no test coverage detected