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

Method getReplacement

src/MagicString.js:818–831  ·  view source on GitHub ↗
(match, str)

Source from the content-addressed store, hash-verified

816
817 _replaceRegexp(searchValue, replacement) {
818 function getReplacement(match, str) {
819 if (typeof replacement === 'string') {
820 return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
821 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
822 if (i === '$') return '$';
823 if (i === '&') return match[0];
824 const num = +i;
825 if (num < match.length) return match[+i];
826 return `$${i}`;
827 });
828 } else {
829 return replacement(...match, match.index, str, match.groups);
830 }
831 }
832 function matchAll(re, str) {
833 let match;
834 const matches = [];

Callers

nothing calls this directly

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected