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

Method _split

src/MagicString.ts:1150–1170  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

1148
1149 /** @internal */
1150 _split(index: number): boolean | void {
1151 if (this.byStart.get(index) || this.byEnd.get(index))
1152 return
1153
1154 let chunk: Chunk | undefined = this.lastSearchedChunk
1155 let previousChunk: Chunk | undefined = chunk
1156 const searchForward = index > chunk.end
1157
1158 while (chunk) {
1159 if (chunk.contains(index))
1160 return this._splitChunk(chunk, index)
1161
1162 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
1163
1164 // Prevent infinite loop (e.g. via empty chunks, where start === end)
1165 if (chunk === previousChunk)
1166 return
1167
1168 previousChunk = chunk
1169 }
1170 }
1171
1172 /** @internal */
1173 _splitChunk(chunk: Chunk, index: number): true {

Callers 8

appendLeftMethod · 0.95
appendRightMethod · 0.95
moveMethod · 0.95
updateMethod · 0.95
prependLeftMethod · 0.95
prependRightMethod · 0.95
removeMethod · 0.95
resetMethod · 0.95

Calls 2

_splitChunkMethod · 0.95
containsMethod · 0.45

Tested by

no test coverage detected