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

Method replaceMatch

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

Source from the content-addressed store, hash-verified

1356 }
1357 }
1358 const replaceMatch = (match: RegExpMatchArray): void => {
1359 /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
1360 if (match.index == null)
1361 return
1362
1363 const replacement = getReplacement(match, this.original)
1364 if (replacement === match[0])
1365 return
1366
1367 if (match[0].length === 0) {
1368 // a zero-length match spans no characters, so there is no range to
1369 // overwrite - the replacement is an insertion at the matched position,
1370 // which is what `String.prototype.replace` does for an empty match
1371 this.appendRight(match.index, replacement)
1372 }
1373 else {
1374 this.overwrite(match.index, match.index + match[0].length, replacement)
1375 }
1376 }
1377
1378 if (searchValue.global) {
1379 // `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