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

Method replaceMatch

src/MagicString.ts:1382–1400  ·  view source on GitHub ↗
(match: RegExpMatchArray)

Source from the content-addressed store, hash-verified

1380 }
1381 }
1382 const replaceMatch = (match: RegExpMatchArray): void => {
1383 /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
1384 if (match.index == null)
1385 return
1386
1387 const replacement = getReplacement(match, this.original)
1388 if (replacement === match[0])
1389 return
1390
1391 if (match[0].length === 0) {
1392 // a zero-length match spans no characters, so there is no range to
1393 // overwrite - the replacement is an insertion at the matched position,
1394 // which is what `String.prototype.replace` does for an empty match
1395 this.appendRight(match.index, replacement)
1396 }
1397 else {
1398 this.overwrite(match.index, match.index + match[0].length, replacement)
1399 }
1400 }
1401
1402 if (searchValue.global) {
1403 // `String.prototype.replace` starts a global regexp from the beginning of

Callers

nothing calls this directly

Calls 2

appendRightMethod · 0.95
overwriteMethod · 0.95

Tested by

no test coverage detected