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

Method prependRight

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

850 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
851 */
852 prependRight(index: number, content: string): this {
853 index = index + this.offset
854
855 if (typeof content !== 'string') {
856 throw new MagicStringError(`content must be a string, got ${typeof content}`)
857 }
858
859 /* v8 ignore next 2 -- DEBUG is always true in tests */
860 if (DEBUG)
861 this.stats.time('insertRight')
862
863 this._split(index)
864
865 const chunk = this.byStart.get(index)
866
867 if (chunk) {
868 chunk.prependRight(content)
869 }
870 else {
871 this.outro = content + this.outro
872 }
873
874 /* v8 ignore next 2 -- DEBUG is always true in tests */
875 if (DEBUG)
876 this.stats.timeEnd('insertRight')
877 return this
878 }
879
880 /**
881 * 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