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

Method _splitChunk

src/MagicString.ts:1205–1228  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

1203
1204 /** @internal */
1205 _splitChunk(chunk: Chunk, index: number): true {
1206 if (chunk.edited && chunk.content.length) {
1207 // zero-length edited chunks are a special case (overlapping replacements)
1208 const loc = getLocator(this.original)(index)
1209 throw new MagicStringError(
1210 `cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1211 )
1212 }
1213
1214 const newChunk = chunk.split(index)
1215
1216 this.byEnd.set(index, chunk)
1217 this.byStart.set(index, newChunk)
1218 this.byEnd.set(newChunk.end, newChunk)
1219
1220 if (chunk === this.lastChunk)
1221 this.lastChunk = newChunk
1222
1223 this.lastSearchedChunk = chunk
1224 /* v8 ignore next 2 -- DEBUG is always true in tests */
1225 if (DEBUG)
1226 this.stats.timeEnd('_split')
1227 return true
1228 }
1229
1230 /**
1231 * Returns the generated string.

Callers 2

indentAtMethod · 0.95
_splitMethod · 0.95

Calls 3

getLocatorFunction · 0.90
timeEndMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected