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

Method _split

src/MagicString.ts:1119–1143  ·  view source on GitHub ↗

@internal

(index: number)

Source from the content-addressed store, hash-verified

1117
1118 /** @internal */
1119 _split(index: number): boolean | void {
1120 if (this.byStart.get(index) || this.byEnd.get(index))
1121 return
1122
1123 /* v8 ignore next 2 -- DEBUG is always true in tests */
1124 if (DEBUG)
1125 this.stats.time('_split')
1126
1127 let chunk = this.lastSearchedChunk
1128 let previousChunk = chunk
1129 const searchForward = index > chunk.end
1130
1131 while (chunk) {
1132 if (chunk.contains(index))
1133 return this._splitChunk(chunk, index)
1134
1135 chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start)
1136
1137 // Prevent infinite loop (e.g. via empty chunks, where start === end)
1138 if (chunk === previousChunk)
1139 return
1140
1141 previousChunk = chunk
1142 }
1143 }
1144
1145 /** @internal */
1146 _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