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

Method remove

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

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