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

Method _splitChunk

src/MagicString.ts:947–969  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

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