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

Method prependRight

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

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