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

Method remove

src/MagicString.ts:720–756  ·  view source on GitHub ↗

* Removes the characters from `start` to `end` (of the original string, **not** the generated string). * Removing the same content twice, or making removals that partially overlap, will cause an error.

(start: number, end: number)

Source from the content-addressed store, hash-verified

718 * Removing the same content twice, or making removals that partially overlap, will cause an error.
719 */
720 remove(start: number, end: number): this {
721 start = start + this.offset
722 end = end + this.offset
723
724 if (this.original.length !== 0) {
725 while (start < 0) start += this.original.length
726 while (end < 0) end += this.original.length
727 }
728
729 if (start === end)
730 return this
731
732 if (start < 0 || end > this.original.length)
733 throw new Error('Character is out of bounds')
734 if (start > end)
735 throw new Error('end must be greater than start')
736
737 if (DEBUG)
738 this.stats.time('remove')
739
740 this._split(start)
741 this._split(end)
742
743 let chunk = this.byStart[start]
744
745 while (chunk) {
746 chunk.intro = ''
747 chunk.outro = ''
748 chunk.edit('')
749
750 chunk = end > chunk.end ? this.byStart[chunk.end] : null
751 }
752
753 if (DEBUG)
754 this.stats.timeEnd('remove')
755 return this
756 }
757
758 /**
759 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).

Callers 1

snipMethod · 0.45

Calls 4

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80
editMethod · 0.45

Tested by

no test coverage detected