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

Method reset

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

929 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
930 */
931 reset(start: number, end: number): this {
932 start = start + this.offset
933 end = end + this.offset
934
935 if (this.original.length !== 0) {
936 if (start < 0)
937 start = Math.max(0, start + this.original.length)
938 if (end < 0)
939 end = Math.max(0, end + this.original.length)
940 }
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 /* v8 ignore next 2 -- DEBUG is always true in tests */
953 if (DEBUG)
954 this.stats.time('reset')
955
956 this._split(start)
957 this._split(end)
958
959 let chunk = this.byStart.get(start)
960
961 while (chunk) {
962 chunk.reset()
963
964 chunk = end > chunk.end ? this.byStart.get(chunk.end) : null
965 }
966
967 /* v8 ignore next 2 -- DEBUG is always true in tests */
968 if (DEBUG)
969 this.stats.timeEnd('reset')
970 return this
971 }
972
973 lastChar(): string {
974 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