@@ -88,13 +88,16 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
88
88
if ( ! functionalReplace ) replaceValue = toString ( replaceValue ) ;
89
89
90
90
var global = rx . global ;
91
+ var fullUnicode ;
91
92
if ( global ) {
92
- var fullUnicode = rx . unicode ;
93
+ fullUnicode = rx . unicode ;
93
94
rx . lastIndex = 0 ;
94
95
}
96
+
95
97
var results = [ ] ;
98
+ var result ;
96
99
while ( true ) {
97
- var result = regExpExec ( rx , S ) ;
100
+ result = regExpExec ( rx , S ) ;
98
101
if ( result === null ) break ;
99
102
100
103
push ( results , result ) ;
@@ -112,6 +115,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
112
115
var matched = toString ( result [ 0 ] ) ;
113
116
var position = max ( min ( toIntegerOrInfinity ( result . index ) , S . length ) , 0 ) ;
114
117
var captures = [ ] ;
118
+ var replacement ;
115
119
// NOTE: This is equivalent to
116
120
// captures = result.slice(1).map(maybeToString)
117
121
// but for some reason `nativeSlice.call(result, 1, result.length)` (called in
@@ -122,7 +126,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
122
126
if ( functionalReplace ) {
123
127
var replacerArgs = concat ( [ matched ] , captures , position , S ) ;
124
128
if ( namedCaptures !== undefined ) push ( replacerArgs , namedCaptures ) ;
125
- var replacement = toString ( apply ( replaceValue , undefined , replacerArgs ) ) ;
129
+ replacement = toString ( apply ( replaceValue , undefined , replacerArgs ) ) ;
126
130
} else {
127
131
replacement = getSubstitution ( matched , S , position , captures , namedCaptures , replaceValue ) ;
128
132
}
@@ -131,6 +135,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
131
135
nextSourcePosition = position + matched . length ;
132
136
}
133
137
}
138
+
134
139
return accumulatedResult + stringSlice ( S , nextSourcePosition ) ;
135
140
}
136
141
] ;
0 commit comments