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

Method prependRight

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

730 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
731 */
732 prependRight(index: number, content: string): this {
733 index = index + this.offset
734
735 if (typeof content !== 'string') {
736 throw new MagicStringError(`content must be a string, got ${typeof content}`)
737 }
738
739 if (DEBUG)
740 this.stats.time('insertRight')
741
742 this._split(index)
743
744 const chunk = this.byStart.get(index)
745
746 if (chunk) {
747 chunk.prependRight(content)
748 }
749 else {
750 this.outro = content + this.outro
751 }
752
753 if (DEBUG)
754 this.stats.timeEnd('insertRight')
755 return this
756 }
757
758 /**
759 * 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