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

Method _split

src/MagicString.ts:1101–1125  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

1099
1100 /** @internal */
1101 _split(index: number): boolean | void {
1102 if (this.byStart.get(index) || this.byEnd.get(index))
1103 return
1104
1105 /* v8 ignore next 2 -- DEBUG is always true in tests */
1106 if (DEBUG)
1107 this.stats.time('_split')
1108
1109 let chunk = this.lastSearchedChunk
1110 let previousChunk = chunk
1111 const searchForward = index > chunk.end
1112
1113 while (chunk) {
1114 if (chunk.contains(index))
1115 return this._splitChunk(chunk, index)
1116
1117 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
1118
1119 // Prevent infinite loop (e.g. via empty chunks, where start === end)
1120 if (chunk === previousChunk)
1121 return
1122
1123 previousChunk = chunk
1124 }
1125 }
1126
1127 /** @internal */
1128 _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