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

Method reset

src/MagicString.ts:805–841  ·  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

803 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
804 */
805 reset(start: number, end: number): this {
806 start = start + this.offset
807 end = end + this.offset
808
809 if (this.original.length !== 0) {
810 while (start < 0) start += this.original.length
811 while (end < 0) end += this.original.length
812 }
813
814 if (start === end)
815 return this
816
817 if (start < 0 || end > this.original.length) {
818 throw new MagicStringError(`range ${start}–${end} is out of bounds`)
819 }
820 if (start > end) {
821 throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`)
822 }
823
824 if (DEBUG)
825 this.stats.time('reset')
826
827 this._split(start)
828 this._split(end)
829
830 let chunk = this.byStart.get(start)
831
832 while (chunk) {
833 chunk.reset()
834
835 chunk = end > chunk.end ? this.byStart.get(chunk.end) : null
836 }
837
838 if (DEBUG)
839 this.stats.timeEnd('reset')
840 return this
841 }
842
843 lastChar(): string {
844 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