Skip to content

Commit

Permalink
some missed actions for #745
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jan 10, 2020
1 parent 254a227 commit 6f80aac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Fixed replacement of substitutes of undefined capture groups in `.replace` in Safari 13.0-, [#471](https://github.com/zloirock/core-js/issues/471), [#745](https://github.com/zloirock/core-js/issues/745), thanks [@mattclough1](https://github.com/mattclough1)
- Improved compat data for old engines

##### 3.6.2 - 2020.01.07
Expand Down
Expand Up @@ -87,7 +87,7 @@ module.exports = function (KEY, length, exec, sham) {
(KEY === 'replace' && !(
REPLACE_SUPPORTS_NAMED_GROUPS &&
REPLACE_KEEPS_$0 &&
REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
)) ||
(KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
) {
Expand Down
8 changes: 6 additions & 2 deletions packages/core-js/modules/es.string.replace.js
Expand Up @@ -20,6 +20,10 @@ var maybeToString = function (it) {

// @@replace logic
fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) {
var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE;
var REPLACE_KEEPS_$0 = reason.REPLACE_KEEPS_$0;
var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';

return [
// `String.prototype.replace` method
// https://tc39.github.io/ecma262/#sec-string.prototype.replace
Expand All @@ -34,8 +38,8 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, ma
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
function (regexp, replaceValue) {
if (
!reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE &&
(reason.REPLACE_KEEPS_$0 || (typeof replaceValue === 'string' && replaceValue.indexOf('$0') === -1))
(!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0) ||
(typeof replaceValue === 'string' && replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1)
) {
var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
if (res.done) return res.value;
Expand Down
6 changes: 5 additions & 1 deletion tests/compat/tests.js
Expand Up @@ -875,7 +875,11 @@ GLOBAL.tests = {
return result;
};

return ''.replace(O) == 7 && execCalled && ''.replace(re2, '$<a>') === '7';
return ''.replace(O) == 7
&& execCalled
&& ''.replace(re2, '$<a>') === '7'
&& 'a'.replace(/./, '$0') === '$0'
&& /./[Symbol.replace]('a', '$0') === '$0';
},
'es.string.search': function () {
var O = {};
Expand Down

0 comments on commit 6f80aac

Please sign in to comment.