* 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)
| 755 | * Removing the same content twice, or making removals that partially overlap, will cause an error. |
| 756 | */ |
| 757 | remove(start: number, end: number): this { |
| 758 | start = start + this.offset |
| 759 | end = end + this.offset |
| 760 | |
| 761 | if (this.original.length !== 0) { |
| 762 | while (start < 0) start += this.original.length |
| 763 | while (end < 0) end += this.original.length |
| 764 | } |
| 765 | |
| 766 | if (start === end) |
| 767 | return this |
| 768 | |
| 769 | if (start < 0 || end > this.original.length) { |
| 770 | throw new MagicStringError(`range ${start}–${end} is out of bounds`) |
| 771 | } |
| 772 | if (start > end) { |
| 773 | throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`) |
| 774 | } |
| 775 | |
| 776 | if (DEBUG) |
| 777 | this.stats.time('remove') |
| 778 | |
| 779 | this._split(start) |
| 780 | this._split(end) |
| 781 | |
| 782 | let chunk = this.byStart.get(start) |
| 783 | |
| 784 | while (chunk) { |
| 785 | chunk.intro = '' |
| 786 | chunk.outro = '' |
| 787 | chunk.edit('') |
| 788 | |
| 789 | chunk = end > chunk.end ? this.byStart.get(chunk.end) : null |
| 790 | } |
| 791 | |
| 792 | if (DEBUG) |
| 793 | this.stats.timeEnd('remove') |
| 794 | return this |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string). |