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

Method _splitChunk

src/MagicString.ts:964–986  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

962
963 /** @internal */
964 _splitChunk(chunk: Chunk, index: number): true {
965 if (chunk.edited && chunk.content.length) {
966 // zero-length edited chunks are a special case (overlapping replacements)
967 const loc = getLocator(this.original)(index)
968 throw new MagicStringError(
969 `cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
970 )
971 }
972
973 const newChunk = chunk.split(index)
974
975 this.byEnd.set(index, chunk)
976 this.byStart.set(index, newChunk)
977 this.byEnd.set(newChunk.end, newChunk)
978
979 if (chunk === this.lastChunk)
980 this.lastChunk = newChunk
981
982 this.lastSearchedChunk = chunk
983 if (DEBUG)
984 this.stats.timeEnd('_split')
985 return true
986 }
987
988 /**
989 * 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