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

Method prependRight

src/MagicString.ts:701–725  ·  view source on GitHub ↗

* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`

(index: number, content: string)

Source from the content-addressed store, hash-verified

699 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
700 */
701 prependRight(index: number, content: string): this {
702 index = index + this.offset
703
704 if (typeof content !== 'string') {
705 throw new MagicStringError(`content must be a string, got ${typeof content}`)
706 }
707
708 if (DEBUG)
709 this.stats.time('insertRight')
710
711 this._split(index)
712
713 const chunk = this.byStart.get(index)
714
715 if (chunk) {
716 chunk.prependRight(content)
717 }
718 else {
719 this.outro = content + this.outro
720 }
721
722 if (DEBUG)
723 this.stats.timeEnd('insertRight')
724 return this
725 }
726
727 /**
728 * Removes the characters from `start` to `end` (of the original string, **not** the generated string).

Callers 2

insertRightMethod · 0.95
indentAtMethod · 0.45

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected