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

Method _split

src/MagicString.ts:922–945  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

920
921 /** @internal */
922 _split(index: number): boolean | void {
923 if (this.byStart.get(index) || this.byEnd.get(index))
924 return
925
926 if (DEBUG)
927 this.stats.time('_split')
928
929 let chunk = this.lastSearchedChunk
930 let previousChunk = chunk
931 const searchForward = index > chunk.end
932
933 while (chunk) {
934 if (chunk.contains(index))
935 return this._splitChunk(chunk, index)
936
937 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
938
939 // Prevent infinite loop (e.g. via empty chunks, where start === end)
940 if (chunk === previousChunk)
941 return
942
943 previousChunk = chunk
944 }
945 }
946
947 /** @internal */
948 _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 3

_splitChunkMethod · 0.95
timeMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected