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

Method _splitChunk

src/MagicString.ts:1173–1193  ·  view source on GitHub ↗

@internal

(chunk: Chunk, index: number)

Source from the content-addressed store, hash-verified

1171
1172 /** @internal */
1173 _splitChunk(chunk: Chunk, index: number): true {
1174 if (chunk.edited && chunk.content.length) {
1175 // zero-length edited chunks are a special case (overlapping replacements)
1176 const loc = getLocator(this.original)(index)
1177 throw new MagicStringError(
1178 `cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1179 )
1180 }
1181
1182 const newChunk = chunk.split(index)
1183
1184 this.byEnd.set(index, chunk)
1185 this.byStart.set(index, newChunk)
1186 this.byEnd.set(newChunk.end, newChunk)
1187
1188 if (chunk === this.lastChunk)
1189 this.lastChunk = newChunk
1190
1191 this.lastSearchedChunk = chunk
1192 return true
1193 }
1194
1195 /**
1196 * Returns the generated string.

Callers 2

indentAtMethod · 0.95
_splitMethod · 0.95

Calls 2

getLocatorFunction · 0.90
splitMethod · 0.45

Tested by

no test coverage detected