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

Method reset

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

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