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