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

Method _splitChunk

src/MagicString.ts:948–970  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

946
947 /** @internal */
948 _splitChunk(chunk: Chunk, index: number): true {
949 if (chunk.edited && chunk.content.length) {
950 // zero-length edited chunks are a special case (overlapping replacements)
951 const loc = getLocator(this.original)(index)
952 throw new Error(
953 `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
954 )
955 }
956
957 const newChunk = chunk.split(index)
958
959 this.byEnd.set(index, chunk)
960 this.byStart.set(index, newChunk)
961 this.byEnd.set(newChunk.end, newChunk)
962
963 if (chunk === this.lastChunk)
964 this.lastChunk = newChunk
965
966 this.lastSearchedChunk = chunk
967 if (DEBUG)
968 this.stats.timeEnd('_split')
969 return true
970 }
971
972 /**
973 * Returns the generated string.

Callers 2

indentAtMethod · 0.95
_splitMethod · 0.95

Calls 3

timeEndMethod · 0.80
getLocatorFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected