Skip to content

Commit 913625f

Browse files
authored
Merge pull request #944 from zloirock/re
close #792, close #521
2 parents fad1d44 + 12e0678 commit 913625f

27 files changed

+414
-146
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
## Changelog
22
##### Unreleased
3+
- Added `RegExp` named capture groups polyfill, [#521](https://github.com/zloirock/core-js/issues/521)
4+
- Added `RegExp` `dotAll` flag polyfill, [#792](https://github.com/zloirock/core-js/issues/792)
35
- Added missed polyfills of [Annex B](https://tc39.es/ecma262/#sec-additional-built-in-properties) features (required mainly for some non-browser engines), [#336](https://github.com/zloirock/core-js/issues/336):
46
- `escape`
57
- `unescape`
68
- `String.prototype.substr`
79
- `Date.prototype.getYear`
810
- `Date.prototype.setYear`
911
- `Date.prototype.toGMTString`
10-
- Fixed detection of forbidden host code points in URL polyfill
12+
- Fixed detection of forbidden host code points in `URL` polyfill
1113
- Allowed `rhino` target in `core-js-compat` / `core-js-builder`, added compat data for `rhino` 1.7.13, [#942](https://github.com/zloirock/core-js/issues/942), thanks [@gausie](https://github.com/gausie)
1214
- `.at` marked as supported from FF90
1315

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ Adding support of well-known [symbols](#ecmascript-symbol) `@@match`, `@@replace
669669

670670
Annex B methods. Modules [`es.string.anchor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.anchor.js), [`es.string.big`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.big.js), [`es.string.blink`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.blink.js), [`es.string.bold`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.bold.js), [`es.string.fixed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.fixed.js), [`es.string.fontcolor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.fontcolor.js), [`es.string.fontsize`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.fontsize.js), [`es.string.italics`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.italics.js), [`es.string.link`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.link.js), [`es.string.small`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.small.js), [`es.string.strike`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.strike.js), [`es.string.sub`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.sub.js), [`es.string.sup`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.sup.js), [`es.string.substr`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.string.substr.js), [`es.escape`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.escape.js) and [`es.unescape`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.unescape.js).
671671

672-
`RegExp` features: modules [`es.regexp.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.constructor.js), [`es.regexp.flags`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.flags.js), [`es.regexp.sticky`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.sticky.js) and [`es.regexp.test`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.test.js).
672+
`RegExp` features: modules [`es.regexp.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.constructor.js), [`es.regexp.dot-all`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.dot-all.js), [`es.regexp.flags`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.flags.js), [`es.regexp.sticky`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.sticky.js) and [`es.regexp.test`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.regexp.test.js).
673673
```js
674674
class String {
675675
static fromCodePoint(...codePoints: Array<number>): string;
@@ -710,7 +710,8 @@ class String {
710710
}
711711

712712
class RegExp {
713-
constructor(pattern: RegExp | string, flags?: string): RegExp; // support of sticky (`y`) flag; can alter flags
713+
// support of sticky (`y`) flag, dotAll (`s`) flag, named capture groups, can alter flags
714+
constructor(pattern: RegExp | string, flags?: string): RegExp;
714715
exec(): Array<string | undefined> | null; // IE8 fixes
715716
test(string: string): boolean; // delegation to `.exec`
716717
toString(): string; // ES2015+ fix - generic
@@ -719,8 +720,9 @@ class RegExp {
719720
@@replace(string: string, replaceValue: Function | string): string;
720721
@@search(string: string): number;
721722
@@split(string: string, limit: number): Array<string>;
722-
readonly attribute flags: string; // IE9+
723-
readonly attribute sticky: boolean;
723+
readonly attribute dotAll: boolean; // IE9+
724+
readonly attribute flags: string; // IE9+
725+
readonly attribute sticky: boolean; // IE9+
724726
}
725727

726728
function escape(string: string): string;
@@ -766,14 +768,15 @@ core-js(-pure)/es|stable|features/string(/virtual)/sup
766768
core-js(-pure)/es|stable|features/string(/virtual)/iterator
767769
core-js/es|stable|features/regexp
768770
core-js/es|stable|features/regexp/constructor
771+
core-js/es|stable|features/regexp/dot-all
769772
core-js(-pure)/es|stable|features/regexp/flags
770773
core-js/es|stable|features/regexp/sticky
771774
core-js/es|stable|features/regexp/test
772775
core-js/es|stable|features/regexp/to-string
773776
core-js/es|stable|features/escape
774777
core-js/es|stable|features/unescape
775778
```
776-
[*Examples*](http://es6.zloirock.ru/#for(var%20val%20of%20'a%F0%A0%AE%B7b')%7B%0A%20%20log(val)%3B%20%2F%2F%20%3D%3E%20'a'%2C%20'%F0%A0%AE%B7'%2C%20'b'%0A%7D%0A%0Alog('foobarbaz'.includes('bar'))%3B%20%20%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.includes('bar'%2C%204))%3B%20%20%20%2F%2F%20%3D%3E%20false%0Alog('foobarbaz'.startsWith('foo'))%3B%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.startsWith('bar'%2C%203))%3B%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.endsWith('baz'))%3B%20%20%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.endsWith('bar'%2C%206))%3B%20%20%20%2F%2F%20%3D%3E%20true%0A%0Alog('string'.repeat(3))%3B%20%2F%2F%20%3D%3E%20'stringstringstring'%0A%0Alog('hello'.padStart(10))%3B%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%20%20%20%20%20hello'%0Alog('hello'.padStart(10%2C%20'1234'))%3B%20%2F%2F%20%3D%3E%20'12341hello'%0Alog('hello'.padEnd(10))%3B%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'hello%20%20%20%20%20'%0Alog('hello'.padEnd(10%2C%20'1234'))%3B%20%20%20%2F%2F%20%3D%3E%20'hello12341'%0A%0Alog('%F0%A0%AE%B7'.codePointAt(0))%3B%20%2F%2F%20%3D%3E%20134071%0A%0Avar%20name%20%3D%20'Bob'%3B%0Alog(String.raw%60Hi%5Cn%24%7Bname%7D!%60)%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'Hi%5C%5CnBob!'%20(ES6%20template%20string%20syntax)%0Alog(String.raw(%7B%20raw%3A%20'test'%20%7D%2C%200%2C%201%2C%202))%3B%20%2F%2F%20%3D%3E%20%2F%2F%20't0e1s2t'%0A%0Alog('foo'.bold())%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%3Cb%3Efoo%3C%2Fb%3E'%0Alog('bar'.anchor('a%22b'))%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%3Ca%20name%3D%22a%26quot%3Bb%22%3Ebar%3C%2Fa%3E'%0Alog('baz'.link('http%3A%2F%2Fexample.com'))%3B%20%2F%2F%20%3D%3E%20'%3Ca%20href%3D%22http%3A%2F%2Fexample.com%22%3Ebaz%3C%2Fa%3E'%0A%0Alog(RegExp(%2F.%2Fg%2C%20'm'))%3B%20%2F%2F%20%3D%3E%20%2F.%2Fm%0A%0Alog(%2Ffoo%2F.flags)%3B%20%20%20%20%2F%2F%20%3D%3E%20''%0Alog(%2Ffoo%2Fgim.flags)%3B%20%2F%2F%20%3D%3E%20'gim'%0A%0Alog(RegExp('foo'%2C%20'y').sticky)%3B%20%2F%2F%20%3D%3E%20true%0A%0Aconst%20text%20%3D%20'First%20line%5CnSecond%20line'%3B%0Aconst%20regex%20%3D%20RegExp('(%5C%5CS%2B)%20line%5C%5Cn%3F'%2C%20'y')%3B%0A%0Alog(regex.exec(text)%5B1%5D)%3B%20%2F%2F%20%3D%3E%20'First'%0Alog(regex.exec(text)%5B1%5D)%3B%20%2F%2F%20%3D%3E%20'Second'%0Alog(regex.exec(text))%3B%20%20%20%20%2F%2F%20%3D%3E%20null%0A%0Alog('foo'.match(%7B%5BSymbol.match%5D%3A%20_%20%3D%3E%201%7D))%3B%20%20%20%20%20%2F%2F%20%3D%3E%201%0Alog('foo'.replace(%7B%5BSymbol.replace%5D%3A%20_%20%3D%3E%202%7D))%3B%20%2F%2F%20%3D%3E%202%0Alog('foo'.search(%7B%5BSymbol.search%5D%3A%20_%20%3D%3E%203%7D))%3B%20%20%20%2F%2F%20%3D%3E%203%0Alog('foo'.split(%7B%5BSymbol.split%5D%3A%20_%20%3D%3E%204%7D))%3B%20%20%20%20%20%2F%2F%20%3D%3E%204%0A%0Alog(RegExp.prototype.toString.call(%7Bsource%3A%20'foo'%2C%20flags%3A%20'bar'%7D))%3B%0A%0Alog('%20%20%20hello%20%20%20'.trimLeft())%3B%20%20%2F%2F%20%3D%3E%20'hello%20%20%20'%0Alog('%20%20%20hello%20%20%20'.trimRight())%3B%20%2F%2F%20%3D%3E%20'%20%20%20hello'%0Alog('%20%20%20hello%20%20%20'.trimStart())%3B%20%2F%2F%20%3D%3E%20'hello%20%20%20'%0Alog('%20%20%20hello%20%20%20'.trimEnd())%3B%20%20%20%2F%2F%20%3D%3E%20'%20%20%20hello'%0A%0Afor%20(let%20%5B_%2C%20d%2C%20D%5D%20of%20'1111a2b3cccc'.matchAll(%2F(%5Cd)(%5CD)%2Fg))%20%7B%0A%20%20log(d%2C%20D)%3B%20%2F%2F%20%3D%3E%201%20a%2C%202%20b%2C%203%20c%0A%7D%0A%0Alog('Test%20abc%20test%20test%20abc%20test.'.replaceAll('abc'%2C%20'foo'))%3B%20%2F%2F%20-%3E%20'Test%20foo%20test%20test%20foo%20test.'):
779+
[*Examples*](http://es6.zloirock.ru/#for(var%20val%20of%20'a%F0%A0%AE%B7b')%7B%0A%20%20log(val)%3B%20%2F%2F%20%3D%3E%20'a'%2C%20'%F0%A0%AE%B7'%2C%20'b'%0A%7D%0A%0Alog('foobarbaz'.includes('bar'))%3B%20%20%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.includes('bar'%2C%204))%3B%20%20%20%2F%2F%20%3D%3E%20false%0Alog('foobarbaz'.startsWith('foo'))%3B%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.startsWith('bar'%2C%203))%3B%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.endsWith('baz'))%3B%20%20%20%20%20%20%2F%2F%20%3D%3E%20true%0Alog('foobarbaz'.endsWith('bar'%2C%206))%3B%20%20%20%2F%2F%20%3D%3E%20true%0A%0Alog('string'.repeat(3))%3B%20%2F%2F%20%3D%3E%20'stringstringstring'%0A%0Alog('hello'.padStart(10))%3B%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%20%20%20%20%20hello'%0Alog('hello'.padStart(10%2C%20'1234'))%3B%20%2F%2F%20%3D%3E%20'12341hello'%0Alog('hello'.padEnd(10))%3B%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'hello%20%20%20%20%20'%0Alog('hello'.padEnd(10%2C%20'1234'))%3B%20%20%20%2F%2F%20%3D%3E%20'hello12341'%0A%0Alog('%F0%A0%AE%B7'.codePointAt(0))%3B%20%2F%2F%20%3D%3E%20134071%0A%0Avar%20name%20%3D%20'Bob'%3B%0Alog(String.raw%60Hi%5Cn%24%7Bname%7D!%60)%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'Hi%5C%5CnBob!'%20(ES6%20template%20string%20syntax)%0Alog(String.raw(%7B%20raw%3A%20'test'%20%7D%2C%200%2C%201%2C%202))%3B%20%2F%2F%20%3D%3E%20%2F%2F%20't0e1s2t'%0A%0Alog('foo'.bold())%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%3Cb%3Efoo%3C%2Fb%3E'%0Alog('bar'.anchor('a%22b'))%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%3D%3E%20'%3Ca%20name%3D%22a%26quot%3Bb%22%3Ebar%3C%2Fa%3E'%0Alog('baz'.link('http%3A%2F%2Fexample.com'))%3B%20%2F%2F%20%3D%3E%20'%3Ca%20href%3D%22http%3A%2F%2Fexample.com%22%3Ebaz%3C%2Fa%3E'%0A%0Alog(RegExp('.'%2C%20's').test('%5Cn'))%3B%20%2F%2F%20%3D%3E%20true%0Alog(RegExp('.'%2C%20's').dotAll)%3B%20%20%20%20%20%2F%2F%20%3D%3E%20true%0A%0Alog(RegExp('foo%3A(%3F%3Cfoo%3E%5C%5Cw%2B)%2Cbar%3A(%3F%3Cbar%3E%5C%5Cw%2B)').exec('foo%3Aabc%2Cbar%3Adef').groups.bar)%3B%20%2F%2F%20%3D%3E%20'def'%0A%0Alog('foo%3Aabc%2Cbar%3Adef'.replace(RegExp('foo%3A(%3F%3Cfoo%3E%5C%5Cw%2B)%2Cbar%3A(%3F%3Cbar%3E%5C%5Cw%2B)')%2C%20'%24%3Cbar%3E%2C%24%3Cfoo%3E'))%3B%20%2F%2F%20%3D%3E%20'def%2Cabc'%0A%0Alog(RegExp(%2F.%2Fg%2C%20'm'))%3B%20%2F%2F%20%3D%3E%20%2F.%2Fm%0A%0Alog(%2Ffoo%2F.flags)%3B%20%20%20%20%2F%2F%20%3D%3E%20''%0Alog(%2Ffoo%2Fgim.flags)%3B%20%2F%2F%20%3D%3E%20'gim'%0A%0Alog(RegExp('foo'%2C%20'y').sticky)%3B%20%2F%2F%20%3D%3E%20true%0A%0Aconst%20text%20%3D%20'First%20line%5CnSecond%20line'%3B%0Aconst%20regex%20%3D%20RegExp('(%5C%5CS%2B)%20line%5C%5Cn%3F'%2C%20'y')%3B%0A%0Alog(regex.exec(text)%5B1%5D)%3B%20%2F%2F%20%3D%3E%20'First'%0Alog(regex.exec(text)%5B1%5D)%3B%20%2F%2F%20%3D%3E%20'Second'%0Alog(regex.exec(text))%3B%20%20%20%20%2F%2F%20%3D%3E%20null%0A%0Alog('foo'.match(%7B%5BSymbol.match%5D%3A%20_%20%3D%3E%201%7D))%3B%20%20%20%20%20%2F%2F%20%3D%3E%201%0Alog('foo'.replace(%7B%5BSymbol.replace%5D%3A%20_%20%3D%3E%202%7D))%3B%20%2F%2F%20%3D%3E%202%0Alog('foo'.search(%7B%5BSymbol.search%5D%3A%20_%20%3D%3E%203%7D))%3B%20%20%20%2F%2F%20%3D%3E%203%0Alog('foo'.split(%7B%5BSymbol.split%5D%3A%20_%20%3D%3E%204%7D))%3B%20%20%20%20%20%2F%2F%20%3D%3E%204%0A%0Alog(RegExp.prototype.toString.call(%7Bsource%3A%20'foo'%2C%20flags%3A%20'bar'%7D))%3B%0A%0Alog('%20%20%20hello%20%20%20'.trimLeft())%3B%20%20%2F%2F%20%3D%3E%20'hello%20%20%20'%0Alog('%20%20%20hello%20%20%20'.trimRight())%3B%20%2F%2F%20%3D%3E%20'%20%20%20hello'%0Alog('%20%20%20hello%20%20%20'.trimStart())%3B%20%2F%2F%20%3D%3E%20'hello%20%20%20'%0Alog('%20%20%20hello%20%20%20'.trimEnd())%3B%20%20%20%2F%2F%20%3D%3E%20'%20%20%20hello'%0A%0Afor%20(let%20%5B_%2C%20d%2C%20D%5D%20of%20'1111a2b3cccc'.matchAll(%2F(%5Cd)(%5CD)%2Fg))%20%7B%0A%20%20log(d%2C%20D)%3B%20%2F%2F%20%3D%3E%201%20a%2C%202%20b%2C%203%20c%0A%7D%0A%0Alog('Test%20abc%20test%20test%20abc%20test.'.replaceAll('abc'%2C%20'foo'))%3B%20%2F%2F%20-%3E%20'Test%20foo%20test%20test%20foo%20test.'):
777780
```js
778781
for (let value of 'a𠮷b') {
779782
console.log(value); // => 'a', '𠮷', 'b'
@@ -804,6 +807,13 @@ String.raw({ raw: 'test' }, 0, 1, 2); // => 't0e1s2t'
804807
'bar'.anchor('a"b'); // => '<a name="a&quot;b">bar</a>'
805808
'baz'.link('http://example.com'); // => '<a href="http://example.com">baz</a>'
806809

810+
RegExp('.', 's').test('\n'); // => true
811+
RegExp('.', 's').dotAll; // => true
812+
813+
RegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)').exec('foo:abc,bar:def').groups.bar; // => 'def'
814+
815+
'foo:abc,bar:def'.replace(RegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)'), '$<bar>,$<foo>'); // => 'def,abc'
816+
807817
RegExp(/./g, 'm'); // => /./m
808818

809819
/foo/.flags; // => ''

packages/core-js-compat/src/data.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -929,20 +929,24 @@ const data = {
929929
safari: '14.0',
930930
},
931931
'es.regexp.constructor': {
932-
chrome: '51',
933-
firefox: '49',
934-
safari: '10.0',
932+
chrome: '64',
933+
firefox: '78',
934+
safari: '11.1',
935+
},
936+
'es.regexp.dot-all': {
937+
chrome: '62',
938+
firefox: '78',
939+
safari: '11.1',
935940
},
936941
'es.regexp.exec': {
937-
chrome: '26',
938-
edge: '13',
939-
firefox: '44',
940-
safari: '10.0',
942+
chrome: '64',
943+
firefox: '78',
944+
safari: '11.1',
941945
},
942946
'es.regexp.flags': {
943-
chrome: '49',
944-
firefox: '37',
945-
safari: '9.0',
947+
chrome: '62',
948+
firefox: '78',
949+
safari: '11.1',
946950
},
947951
'es.regexp.sticky': {
948952
chrome: '49',

packages/core-js-compat/src/modules-by-versions.js

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module.exports = {
9292
'es.date.set-year',
9393
'es.date.to-gmt-string',
9494
'es.escape',
95+
'es.regexp.dot-all',
9596
'es.string.substr',
9697
'es.unescape',
9798
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty

packages/core-js/es/regexp/dot-all.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require('../../modules/es.regexp.constructor');
2+
require('../../modules/es.regexp.dot-all');
3+
require('../../modules/es.regexp.exec');
4+
5+
module.exports = function (it) {
6+
return it.sticky;
7+
};

packages/core-js/es/regexp/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require('../../modules/es.regexp.constructor');
22
require('../../modules/es.regexp.to-string');
3+
require('../../modules/es.regexp.dot-all');
34
require('../../modules/es.regexp.exec');
45
require('../../modules/es.regexp.flags');
56
require('../../modules/es.regexp.sticky');

packages/core-js/es/regexp/sticky.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('../../modules/es.regexp.constructor');
2+
require('../../modules/es.regexp.exec');
13
require('../../modules/es.regexp.sticky');
24

35
module.exports = function (it) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var parent = require('../../stable/regexp/dot-all');
2+
3+
module.exports = parent;

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

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

13-
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
14-
// #replace needs built-in support for named groups.
15-
// #match works fine because it just return the exec results, even if it has
16-
// a "grops" property.
17-
var re = /./;
18-
re.exec = function () {
19-
var result = [];
20-
result.groups = { a: '7' };
21-
return result;
22-
};
23-
return ''.replace(re, '$<a>') !== '7';
24-
});
25-
26-
// IE <= 11 replaces $0 with the whole match, as if it was $&
27-
// https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0
28-
var REPLACE_KEEPS_$0 = (function () {
29-
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
30-
return 'a'.replace(/./, '$0') === '$0';
31-
})();
32-
33-
var REPLACE = wellKnownSymbol('replace');
34-
// Safari <= 13.0.3(?) substitutes nth capture where n>m with an empty string
35-
var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () {
36-
if (/./[REPLACE]) {
37-
return /./[REPLACE]('a', '$0') === '';
38-
}
39-
return false;
40-
})();
41-
42-
// Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
43-
// Weex JS has frozen built-in prototypes, so use try / catch wrapper
44-
var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () {
45-
// eslint-disable-next-line regexp/no-empty-group -- required for testing
46-
var re = /(?:)/;
47-
var originalExec = re.exec;
48-
re.exec = function () { return originalExec.apply(this, arguments); };
49-
var result = 'ab'.split(re);
50-
return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b';
51-
});
52-
53-
module.exports = function (KEY, length, exec, sham) {
13+
module.exports = function (KEY, exec, FORCED, SHAM) {
5414
var SYMBOL = wellKnownSymbol(KEY);
5515

5616
var DELEGATES_TO_SYMBOL = !fails(function () {
@@ -87,12 +47,7 @@ module.exports = function (KEY, length, exec, sham) {
8747
if (
8848
!DELEGATES_TO_SYMBOL ||
8949
!DELEGATES_TO_EXEC ||
90-
(KEY === 'replace' && !(
91-
REPLACE_SUPPORTS_NAMED_GROUPS &&
92-
REPLACE_KEEPS_$0 &&
93-
!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
94-
)) ||
95-
(KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
50+
FORCED
9651
) {
9752
var nativeRegExpMethod = /./[SYMBOL];
9853
var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
@@ -107,23 +62,11 @@ module.exports = function (KEY, length, exec, sham) {
10762
return { done: true, value: nativeMethod.call(str, regexp, arg2) };
10863
}
10964
return { done: false };
110-
}, {
111-
REPLACE_KEEPS_$0: REPLACE_KEEPS_$0,
112-
REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE: REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
11365
});
114-
var stringMethod = methods[0];
115-
var regexMethod = methods[1];
11666

117-
redefine(String.prototype, KEY, stringMethod);
118-
redefine(RegExpPrototype, SYMBOL, length == 2
119-
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
120-
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
121-
? function (string, arg) { return regexMethod.call(string, this, arg); }
122-
// 21.2.5.6 RegExp.prototype[@@match](string)
123-
// 21.2.5.9 RegExp.prototype[@@search](string)
124-
: function (string) { return regexMethod.call(string, this); }
125-
);
67+
redefine(String.prototype, KEY, methods[0]);
68+
redefine(RegExpPrototype, SYMBOL, methods[1]);
12669
}
12770

128-
if (sham) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
71+
if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
12972
};

0 commit comments

Comments
 (0)