Skip to content

Commit f7b619d

Browse files
committed
simplify fix-regexp-well-known-symbol-logic
1 parent 3646a74 commit f7b619d

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

packages/core-js/internals/fix-regexp-well-known-symbol-logic.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var createNonEnumerableProperty = require('../internals/create-non-enumerable-pr
1010
var SPECIES = wellKnownSymbol('species');
1111
var RegExpPrototype = RegExp.prototype;
1212

13-
module.exports = function (KEY, length, exec, FORCED, sham) {
13+
module.exports = function (KEY, exec, FORCED, sham) {
1414
var SYMBOL = wellKnownSymbol(KEY);
1515

1616
var DELEGATES_TO_SYMBOL = !fails(function () {
@@ -63,18 +63,9 @@ module.exports = function (KEY, length, exec, FORCED, sham) {
6363
}
6464
return { done: false };
6565
});
66-
var stringMethod = methods[0];
67-
var regexMethod = methods[1];
6866

69-
redefine(String.prototype, KEY, stringMethod);
70-
redefine(RegExpPrototype, SYMBOL, length == 2
71-
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
72-
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
73-
? function (string, arg) { return regexMethod.call(string, this, arg); }
74-
// 21.2.5.6 RegExp.prototype[@@match](string)
75-
// 21.2.5.9 RegExp.prototype[@@search](string)
76-
: function (string) { return regexMethod.call(string, this); }
77-
);
67+
redefine(String.prototype, KEY, methods[0]);
68+
redefine(RegExpPrototype, SYMBOL, methods[1]);
7869
}
7970

8071
if (sham) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var advanceStringIndex = require('../internals/advance-string-index');
77
var regExpExec = require('../internals/regexp-exec-abstract');
88

99
// @@match logic
10-
fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCallNative) {
10+
fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
1111
return [
1212
// `String.prototype.match` method
1313
// https://tc39.es/ecma262/#sec-string.prototype.match
@@ -18,12 +18,12 @@ fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCal
1818
},
1919
// `RegExp.prototype[@@match]` method
2020
// https://tc39.es/ecma262/#sec-regexp.prototype-@@match
21-
function (regexp) {
22-
var res = maybeCallNative(nativeMatch, regexp, this);
21+
function (string) {
22+
var res = maybeCallNative(nativeMatch, this, string);
2323
if (res.done) return res.value;
2424

25-
var rx = anObject(regexp);
26-
var S = String(this);
25+
var rx = anObject(this);
26+
var S = String(string);
2727

2828
if (!rx.global) return regExpExec(rx, S);
2929

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () {
3434
})();
3535

3636
// @@replace logic
37-
fixRegExpWellKnownSymbolLogic('replace', 2, function (_, nativeReplace, maybeCallNative) {
37+
fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNative) {
3838
var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';
3939

4040
return [
@@ -49,17 +49,17 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (_, nativeReplace, maybeCal
4949
},
5050
// `RegExp.prototype[@@replace]` method
5151
// https://tc39.es/ecma262/#sec-regexp.prototype-@@replace
52-
function (regexp, replaceValue) {
52+
function (string, replaceValue) {
5353
if (
5454
(!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0) ||
5555
(typeof replaceValue === 'string' && replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1)
5656
) {
57-
var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
57+
var res = maybeCallNative(nativeReplace, this, string, replaceValue);
5858
if (res.done) return res.value;
5959
}
6060

61-
var rx = anObject(regexp);
62-
var S = String(this);
61+
var rx = anObject(this);
62+
var S = String(string);
6363

6464
var functionalReplace = typeof replaceValue === 'function';
6565
if (!functionalReplace) replaceValue = String(replaceValue);

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var sameValue = require('../internals/same-value');
66
var regExpExec = require('../internals/regexp-exec-abstract');
77

88
// @@search logic
9-
fixRegExpWellKnownSymbolLogic('search', 1, function (SEARCH, nativeSearch, maybeCallNative) {
9+
fixRegExpWellKnownSymbolLogic('search', function (SEARCH, nativeSearch, maybeCallNative) {
1010
return [
1111
// `String.prototype.search` method
1212
// https://tc39.es/ecma262/#sec-string.prototype.search
@@ -17,12 +17,12 @@ fixRegExpWellKnownSymbolLogic('search', 1, function (SEARCH, nativeSearch, maybe
1717
},
1818
// `RegExp.prototype[@@search]` method
1919
// https://tc39.es/ecma262/#sec-regexp.prototype-@@search
20-
function (regexp) {
21-
var res = maybeCallNative(nativeSearch, regexp, this);
20+
function (string) {
21+
var res = maybeCallNative(nativeSearch, this, string);
2222
if (res.done) return res.value;
2323

24-
var rx = anObject(regexp);
25-
var S = String(this);
24+
var rx = anObject(this);
25+
var S = String(string);
2626

2727
var previousLastIndex = rx.lastIndex;
2828
if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () {
2828
});
2929

3030
// @@split logic
31-
fixRegExpWellKnownSymbolLogic('split', 2, function (SPLIT, nativeSplit, maybeCallNative) {
31+
fixRegExpWellKnownSymbolLogic('split', function (SPLIT, nativeSplit, maybeCallNative) {
3232
var internalSplit;
3333
if (
3434
'abbc'.split(/(b)*/)[1] == 'c' ||
@@ -97,12 +97,12 @@ fixRegExpWellKnownSymbolLogic('split', 2, function (SPLIT, nativeSplit, maybeCal
9797
//
9898
// NOTE: This cannot be properly polyfilled in engines that don't support
9999
// the 'y' flag.
100-
function (regexp, limit) {
101-
var res = maybeCallNative(internalSplit, regexp, this, limit, internalSplit !== nativeSplit);
100+
function (string, limit) {
101+
var res = maybeCallNative(internalSplit, this, string, limit, internalSplit !== nativeSplit);
102102
if (res.done) return res.value;
103103

104-
var rx = anObject(regexp);
105-
var S = String(this);
104+
var rx = anObject(this);
105+
var S = String(string);
106106
var C = speciesConstructor(rx, RegExp);
107107

108108
var unicodeMatching = rx.unicode;

0 commit comments

Comments
 (0)