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

Method prependRight

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

912 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
913 */
914 prependRight(index: number, content: string): this {
915 index = index + this.offset
916
917 if (typeof content !== 'string') {
918 throw new MagicStringError(`content must be a string, got ${typeof content}`)
919 }
920
921 /* v8 ignore next 2 -- DEBUG is always true in tests */
922 if (DEBUG)
923 this.stats.time('insertRight')
924
925 this._split(index)
926
927 const chunk = this.byStart.get(index)
928
929 if (chunk) {
930 chunk.prependRight(content)
931 }
932 else {
933 this.outro = content + this.outro
934 }
935
936 /* v8 ignore next 2 -- DEBUG is always true in tests */
937 if (DEBUG)
938 this.stats.timeEnd('insertRight')
939 return this
940 }
941
942 /**
943 * 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