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

Method _split

src/MagicString.ts:921–944  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

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