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

Method reset

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

1000 * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
1001 */
1002 reset(start: number, end: number): this {
1003 start = start + this.offset
1004 end = end + this.offset
1005
1006 if (this.original.length !== 0) {
1007 if (start < 0)
1008 start = Math.max(0, start + this.original.length)
1009 if (end < 0)
1010 end = Math.max(0, end + this.original.length)
1011 }
1012
1013 if (start === end)
1014 return this
1015
1016 if (start < 0 || end > this.original.length) {
1017 throw new MagicStringError(`range ${start}–${end} is out of bounds`)
1018 }
1019 if (start > end) {
1020 throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`)
1021 }
1022
1023 /* v8 ignore next 2 -- DEBUG is always true in tests */
1024 if (DEBUG)
1025 this.stats.time('reset')
1026
1027 this._split(start)
1028 this._split(end)
1029
1030 let chunk = this.byStart.get(start)
1031
1032 while (chunk) {
1033 chunk.reset()
1034
1035 chunk = end > chunk.end ? this.byStart.get(chunk.end) : null
1036 }
1037
1038 /* v8 ignore next 2 -- DEBUG is always true in tests */
1039 if (DEBUG)
1040 this.stats.timeEnd('reset')
1041 return this
1042 }
1043
1044 lastChar(): string {
1045 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