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

Method prependRight

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

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