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

Method _splitChunk

src/MagicString.ts:1109–1131  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

1107
1108 /** @internal */
1109 _splitChunk(chunk: Chunk, index: number): true {
1110 if (chunk.edited && chunk.content.length) {
1111 // zero-length edited chunks are a special case (overlapping replacements)
1112 const loc = getLocator(this.original)(index)
1113 throw new MagicStringError(
1114 `cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1115 )
1116 }
1117
1118 const newChunk = chunk.split(index)
1119
1120 this.byEnd.set(index, chunk)
1121 this.byStart.set(index, newChunk)
1122 this.byEnd.set(newChunk.end, newChunk)
1123
1124 if (chunk === this.lastChunk)
1125 this.lastChunk = newChunk
1126
1127 this.lastSearchedChunk = chunk
1128 if (DEBUG)
1129 this.stats.timeEnd('_split')
1130 return true
1131 }
1132
1133 /**
1134 * 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