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

Method _split

src/MagicString.ts:1176–1200  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

1174
1175 /** @internal */
1176 _split(index: number): boolean | void {
1177 if (this.byStart.get(index) || this.byEnd.get(index))
1178 return
1179
1180 /* v8 ignore next 2 -- DEBUG is always true in tests */
1181 if (DEBUG)
1182 this.stats.time('_split')
1183
1184 let chunk = this.lastSearchedChunk
1185 let previousChunk = chunk
1186 const searchForward = index > chunk.end
1187
1188 while (chunk) {
1189 if (chunk.contains(index))
1190 return this._splitChunk(chunk, index)
1191
1192 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
1193
1194 // Prevent infinite loop (e.g. via empty chunks, where start === end)
1195 if (chunk === previousChunk)
1196 return
1197
1198 previousChunk = chunk
1199 }
1200 }
1201
1202 /** @internal */
1203 _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