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

Method _splitChunk

src/MagicString.js:682–702  ·  view source on GitHub ↗
(chunk, index)

Source from the content-addressed store, hash-verified

680 }
681
682 _splitChunk(chunk, index) {
683 if (chunk.edited && chunk.content.length) {
684 // zero-length edited chunks are a special case (overlapping replacements)
685 const loc = getLocator(this.original)(index);
686 throw new Error(
687 `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
688 );
689 }
690
691 const newChunk = chunk.split(index);
692
693 this.byEnd[index] = chunk;
694 this.byStart[index] = newChunk;
695 this.byEnd[newChunk.end] = newChunk;
696
697 if (chunk === this.lastChunk) this.lastChunk = newChunk;
698
699 this.lastSearchedChunk = chunk;
700 if (DEBUG) this.stats.timeEnd('_split');
701 return true;
702 }
703
704 toString() {
705 let str = this.intro;

Callers 2

indentMethod · 0.95
_splitMethod · 0.95

Calls 3

timeEndMethod · 0.80
getLocatorFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected