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

Method _split

src/MagicString.ts:969–992  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

967
968 /** @internal */
969 _split(index: number): boolean | void {
970 if (this.byStart.get(index) || this.byEnd.get(index))
971 return
972
973 if (DEBUG)
974 this.stats.time('_split')
975
976 let chunk = this.lastSearchedChunk
977 let previousChunk = chunk
978 const searchForward = index > chunk.end
979
980 while (chunk) {
981 if (chunk.contains(index))
982 return this._splitChunk(chunk, index)
983
984 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
985
986 // Prevent infinite loop (e.g. via empty chunks, where start === end)
987 if (chunk === previousChunk)
988 return
989
990 previousChunk = chunk
991 }
992 }
993
994 /** @internal */
995 _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