* 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)
| 729 | * Removing the same content twice, or making removals that partially overlap, will cause an error. |
| 730 | */ |
| 731 | remove(start: number, end: number): this { |
| 732 | start = start + this.offset |
| 733 | end = end + this.offset |
| 734 | |
| 735 | if (this.original.length !== 0) { |
| 736 | while (start < 0) start += this.original.length |
| 737 | while (end < 0) end += this.original.length |
| 738 | } |
| 739 | |
| 740 | if (start === end) |
| 741 | return this |
| 742 | |
| 743 | if (start < 0 || end > this.original.length) { |
| 744 | throw new MagicStringError(`range ${start}–${end} is out of bounds`) |
| 745 | } |
| 746 | if (start > end) { |
| 747 | throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`) |
| 748 | } |
| 749 | |
| 750 | if (DEBUG) |
| 751 | this.stats.time('remove') |
| 752 | |
| 753 | this._split(start) |
| 754 | this._split(end) |
| 755 | |
| 756 | let chunk = this.byStart.get(start) |
| 757 | |
| 758 | while (chunk) { |
| 759 | chunk.intro = '' |
| 760 | chunk.outro = '' |
| 761 | chunk.edit('') |
| 762 | |
| 763 | chunk = end > chunk.end ? this.byStart.get(chunk.end) : null |
| 764 | } |
| 765 | |
| 766 | if (DEBUG) |
| 767 | this.stats.timeEnd('remove') |
| 768 | return this |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string). |