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

Method appendRight

src/MagicString.ts:258–284  ·  view source on GitHub ↗

* Appends the specified content at the index in the original string. * If a range *starting* with index is subsequently moved, the insert will be moved with it. * See also `s.prependRight(...)`.

(index: number, content: string)

Source from the content-addressed store, hash-verified

256 * See also `s.prependRight(...)`.
257 */
258 appendRight(index: number, content: string): this {
259 index = index + this.offset
260
261 if (typeof content !== 'string') {
262 throw new MagicStringError(`content must be a string, got ${typeof content}`)
263 }
264
265 /* v8 ignore next 2 -- DEBUG is always true in tests */
266 if (DEBUG)
267 this.stats.time('appendRight')
268
269 this._split(index)
270
271 const chunk = this.byStart.get(index)
272
273 if (chunk) {
274 chunk.appendRight(content)
275 }
276 else {
277 this.outro += content
278 }
279
280 /* v8 ignore next 2 -- DEBUG is always true in tests */
281 if (DEBUG)
282 this.stats.timeEnd('appendRight')
283 return this
284 }
285
286 /**
287 * Does what you'd expect.

Callers 4

replaceMatchMethod · 0.95
_replaceStringMethod · 0.95
_replaceAllStringMethod · 0.95
indentAtMethod · 0.45

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected