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

Method _splitChunk

src/MagicString.ts:995–1017  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

993
994 /** @internal */
995 _splitChunk(chunk: Chunk, index: number): true {
996 if (chunk.edited && chunk.content.length) {
997 // zero-length edited chunks are a special case (overlapping replacements)
998 const loc = getLocator(this.original)(index)
999 throw new MagicStringError(
1000 `cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1001 )
1002 }
1003
1004 const newChunk = chunk.split(index)
1005
1006 this.byEnd.set(index, chunk)
1007 this.byStart.set(index, newChunk)
1008 this.byEnd.set(newChunk.end, newChunk)
1009
1010 if (chunk === this.lastChunk)
1011 this.lastChunk = newChunk
1012
1013 this.lastSearchedChunk = chunk
1014 if (DEBUG)
1015 this.stats.timeEnd('_split')
1016 return true
1017 }
1018
1019 /**
1020 * 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