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

Method prependLeft

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

703 * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
704 */
705 prependLeft(index: number, content: string): this {
706 index = index + this.offset
707
708 if (typeof content !== 'string') {
709 throw new MagicStringError(`content must be a string, got ${typeof content}`)
710 }
711
712 if (DEBUG)
713 this.stats.time('insertRight')
714
715 this._split(index)
716
717 const chunk = this.byEnd.get(index)
718
719 if (chunk) {
720 chunk.prependLeft(content)
721 }
722 else {
723 this.intro = content + this.intro
724 }
725
726 if (DEBUG)
727 this.stats.timeEnd('insertRight')
728 return this
729 }
730
731 /**
732 * 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