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

Method _resolveIndex

src/MagicString.ts:1118–1127  ·  view source on GitHub ↗

* Applies `offset`, resolves a negative index from the end of `original` as * `update`/`remove` always have, and rejects anything that is not an integer. * Bounds are checked by the caller, because the methods report them differently. * * @internal

(index: number)

Source from the content-addressed store, hash-verified

1116 * @internal
1117 */
1118 _resolveIndex(index: number): number {
1119 const resolved = index + this.offset
1120 if (!Number.isInteger(resolved)) {
1121 throw new MagicStringError(`index must be an integer, got ${index}`)
1122 }
1123 if (resolved < 0 && this.original.length !== 0) {
1124 return Math.max(0, resolved + this.original.length)
1125 }
1126 return resolved
1127 }
1128
1129 /**
1130 * The chunk whose original range holds `index` (`chunk.start <= index < chunk.end`),

Callers 9

appendLeftMethod · 0.95
appendRightMethod · 0.95
moveMethod · 0.95
updateMethod · 0.95
prependLeftMethod · 0.95
prependRightMethod · 0.95
removeMethod · 0.95
resetMethod · 0.95
sliceMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected