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

Method prependLeft

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

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