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

Method prependLeft

src/MagicString.ts:821–847  ·  view source on GitHub ↗

* Same as `s.appendLeft(...)`, 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

819 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
820 */
821 prependLeft(index: number, content: string): this {
822 index = index + this.offset
823
824 if (typeof content !== 'string') {
825 throw new MagicStringError(`content must be a string, got ${typeof content}`)
826 }
827
828 /* v8 ignore next 2 -- DEBUG is always true in tests */
829 if (DEBUG)
830 this.stats.time('insertRight')
831
832 this._split(index)
833
834 const chunk = this.byEnd.get(index)
835
836 if (chunk) {
837 chunk.prependLeft(content)
838 }
839 else {
840 this.intro = content + this.intro
841 }
842
843 /* v8 ignore next 2 -- DEBUG is always true in tests */
844 if (DEBUG)
845 this.stats.timeEnd('insertRight')
846 return this
847 }
848
849 /**
850 * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`

Callers

nothing calls this directly

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected