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

Method appendRight

src/MagicString.ts:257–283  ·  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

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