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

Method reset

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

936 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
937 */
938 reset(start: number, end: number): this {
939 start = this._resolveIndex(start)
940 end = this._resolveIndex(end)
941
942 if (start === end)
943 return this
944
945 if (start < 0 || end > this.original.length) {
946 throw new MagicStringError(`range ${start}–${end} is out of bounds`)
947 }
948 if (start > end) {
949 throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`)
950 }
951
952 this._split(start)
953 this._split(end)
954
955 let chunk = this.byStart.get(start)
956
957 while (chunk) {
958 chunk.reset()
959
960 chunk = end > chunk.end ? this.byStart.get(chunk.end) : undefined
961 }
962
963 return this
964 }
965
966 /**
967 * Returns the last character of the generated string, or `''` if it is empty.

Callers

nothing calls this directly

Calls 2

_resolveIndexMethod · 0.95
_splitMethod · 0.95

Tested by

no test coverage detected