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

Method reset

src/MagicString.ts:774–810  ·  view source on GitHub ↗

* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).

(start: number, end: number)

Source from the content-addressed store, hash-verified

772 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
773 */
774 reset(start: number, end: number): this {
775 start = start + this.offset
776 end = end + this.offset
777
778 if (this.original.length !== 0) {
779 while (start < 0) start += this.original.length
780 while (end < 0) end += this.original.length
781 }
782
783 if (start === end)
784 return this
785
786 if (start < 0 || end > this.original.length) {
787 throw new MagicStringError(`range ${start}–${end} is out of bounds`)
788 }
789 if (start > end) {
790 throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`)
791 }
792
793 if (DEBUG)
794 this.stats.time('reset')
795
796 this._split(start)
797 this._split(end)
798
799 let chunk = this.byStart.get(start)
800
801 while (chunk) {
802 chunk.reset()
803
804 chunk = end > chunk.end ? this.byStart.get(chunk.end) : null
805 }
806
807 if (DEBUG)
808 this.stats.timeEnd('reset')
809 return this
810 }
811
812 lastChar(): string {
813 if (this.outro.length)

Callers

nothing calls this directly

Calls 3

_splitMethod · 0.95
timeMethod · 0.80
timeEndMethod · 0.80

Tested by

no test coverage detected