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

Method _split

src/MagicString.ts:938–961  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

936
937 /** @internal */
938 _split(index: number): boolean | void {
939 if (this.byStart.get(index) || this.byEnd.get(index))
940 return
941
942 if (DEBUG)
943 this.stats.time('_split')
944
945 let chunk = this.lastSearchedChunk
946 let previousChunk = chunk
947 const searchForward = index > chunk.end
948
949 while (chunk) {
950 if (chunk.contains(index))
951 return this._splitChunk(chunk, index)
952
953 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
954
955 // Prevent infinite loop (e.g. via empty chunks, where start === end)
956 if (chunk === previousChunk)
957 return
958
959 previousChunk = chunk
960 }
961 }
962
963 /** @internal */
964 _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