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