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

Method _splitChunk

src/MagicString.ts:990–1012  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

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