Skip to content

Commit bae33e0

Browse files
committed
revert test of delegation to .exec().groups in .replace
1 parent 70842e9 commit bae33e0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

packages/core-js/internals/regexp-sticky-helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var fails = require('./fails');
1+
var fails = require('../internals/fails');
22

33
// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
44
var RE = function (s, f) {

packages/core-js/modules/es.string.replace.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
3+
var fails = require('../internals/fails');
34
var anObject = require('../internals/an-object');
45
var toLength = require('../internals/to-length');
56
var toInteger = require('../internals/to-integer');
@@ -8,7 +9,6 @@ var advanceStringIndex = require('../internals/advance-string-index');
89
var getSubstitution = require('../internals/get-substitution');
910
var regExpExec = require('../internals/regexp-exec-abstract');
1011
var wellKnownSymbol = require('../internals/well-known-symbol');
11-
var UNSUPPORTED_NCG = require('../internals/regexp-unsupported-ncg');
1212

1313
var REPLACE = wellKnownSymbol('replace');
1414
var max = Math.max;
@@ -33,6 +33,16 @@ var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () {
3333
return false;
3434
})();
3535

36+
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
37+
var re = /./;
38+
re.exec = function () {
39+
var result = [];
40+
result.groups = { a: '7' };
41+
return result;
42+
};
43+
return ''.replace(re, '$<a>') !== '7';
44+
});
45+
3646
// @@replace logic
3747
fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNative) {
3848
var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';
@@ -112,4 +122,4 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
112122
return accumulatedResult + S.slice(nextSourcePosition);
113123
}
114124
];
115-
}, UNSUPPORTED_NCG || !REPLACE_KEEPS_$0 || REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE);
125+
}, !REPLACE_SUPPORTS_NAMED_GROUPS || !REPLACE_KEEPS_$0 || REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE);

tests/compat/tests.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ GLOBAL.tests = {
899899
'es.string.repeat': function () {
900900
return String.prototype.repeat;
901901
},
902-
'es.string.replace': [NCG_SUPPORT, function () {
902+
'es.string.replace': function () {
903903
var O = {};
904904
O[Symbol.replace] = function () { return 7; };
905905

@@ -908,12 +908,20 @@ GLOBAL.tests = {
908908
re.exec = function () { execCalled = true; return null; };
909909
re[Symbol.replace]('');
910910

911+
var re2 = /./;
912+
re2.exec = function () {
913+
var result = [];
914+
result.groups = { a: '7' };
915+
return result;
916+
};
917+
911918
return ''.replace(O) == 7
912919
&& execCalled
920+
&& ''.replace(re2, '$<a>') === '7'
913921
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
914922
&& 'a'.replace(/./, '$0') === '$0'
915923
&& /./[Symbol.replace]('a', '$0') === '$0';
916-
}],
924+
},
917925
'es.string.replace-all': function () {
918926
return String.prototype.replaceAll;
919927
},

0 commit comments

Comments
 (0)