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

Method prependRight

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

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