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

Method _split

src/MagicString.ts:1083–1106  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

1081
1082 /** @internal */
1083 _split(index: number): boolean | void {
1084 if (this.byStart.get(index) || this.byEnd.get(index))
1085 return
1086
1087 if (DEBUG)
1088 this.stats.time('_split')
1089
1090 let chunk = this.lastSearchedChunk
1091 let previousChunk = chunk
1092 const searchForward = index > chunk.end
1093
1094 while (chunk) {
1095 if (chunk.contains(index))
1096 return this._splitChunk(chunk, index)
1097
1098 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
1099
1100 // Prevent infinite loop (e.g. via empty chunks, where start === end)
1101 if (chunk === previousChunk)
1102 return
1103
1104 previousChunk = chunk
1105 }
1106 }
1107
1108 /** @internal */
1109 _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