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

Method _splitChunk

src/MagicString.ts:1003–1025  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

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