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

Method _split

src/MagicString.ts:977–1000  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

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