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

Method _split

src/MagicString.ts:964–987  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

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