@@ -718,7 +718,7 @@ export default class MagicString {
718718 }
719719
720720 replace ( searchValue , replacement ) {
721- function getReplacement ( match ) {
721+ function getReplacement ( match , str ) {
722722 if ( typeof replacement === 'string' ) {
723723 return replacement . replace ( / \$ ( \$ | & | \d + ) / g, ( _ , i ) => {
724724 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
@@ -733,7 +733,7 @@ export default class MagicString {
733733 } ) ;
734734 }
735735 else {
736- return replacement ( ...match ) ;
736+ return replacement ( ...match , match . index , str , match . groups ) ;
737737 }
738738 }
739739 function matchAll ( re , str ) {
@@ -748,13 +748,13 @@ export default class MagicString {
748748 const matches = matchAll ( searchValue , this . original ) ;
749749 matches . forEach ( ( match ) => {
750750 if ( match . index != null )
751- this . overwrite ( match . index , match . index + match [ 0 ] . length , getReplacement ( match ) ) ;
751+ this . overwrite ( match . index , match . index + match [ 0 ] . length , getReplacement ( match , this . original ) ) ;
752752 } ) ;
753753 }
754754 else {
755755 const match = this . original . match ( searchValue ) ;
756756 if ( match && match . index != null )
757- this . overwrite ( match . index , match . index + match [ 0 ] . length , getReplacement ( match ) ) ;
757+ this . overwrite ( match . index , match . index + match [ 0 ] . length , getReplacement ( match , this . original ) ) ;
758758 }
759759 return this ;
760760 }
0 commit comments