core-js 3.12.1 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/es/date/get-year.js +4 -0
  2. package/es/date/index.js +4 -1
  3. package/es/date/set-year.js +4 -0
  4. package/es/date/to-gmt-string.js +4 -0
  5. package/es/escape.js +4 -0
  6. package/es/index.js +7 -0
  7. package/es/regexp/dot-all.js +7 -0
  8. package/es/regexp/index.js +1 -0
  9. package/es/regexp/sticky.js +2 -0
  10. package/es/string/index.js +1 -0
  11. package/es/string/substr.js +4 -0
  12. package/es/string/virtual/index.js +1 -0
  13. package/es/string/virtual/substr.js +4 -0
  14. package/es/unescape.js +4 -0
  15. package/features/date/get-year.js +3 -0
  16. package/features/date/set-year.js +3 -0
  17. package/features/date/to-gmt-string.js +3 -0
  18. package/features/escape.js +3 -0
  19. package/features/index.js +7 -0
  20. package/features/regexp/dot-all.js +3 -0
  21. package/features/string/substr.js +3 -0
  22. package/features/string/virtual/substr.js +3 -0
  23. package/features/unescape.js +3 -0
  24. package/internals/array-sort.js +45 -0
  25. package/internals/call-with-safe-iteration-closing.js +0 -1
  26. package/internals/collection-strong.js +30 -14
  27. package/internals/collection-weak.js +12 -7
  28. package/internals/create-html.js +1 -1
  29. package/internals/date-to-primitive.js +2 -0
  30. package/internals/define-iterator.js +1 -1
  31. package/internals/engine-ff-version.js +5 -0
  32. package/internals/engine-is-ie-or-edge.js +3 -0
  33. package/internals/engine-webkit-version.js +5 -0
  34. package/internals/fix-regexp-well-known-symbol-logic.js +5 -62
  35. package/internals/get-substitution.js +1 -0
  36. package/internals/has.js +1 -1
  37. package/internals/inspect-source.js +1 -1
  38. package/internals/iterators-core.js +2 -1
  39. package/internals/native-symbol.js +4 -2
  40. package/internals/new-promise-capability.js +2 -1
  41. package/internals/object-prototype-accessors-forced.js +4 -0
  42. package/internals/regexp-exec.js +29 -5
  43. package/internals/regexp-sticky-helpers.js +3 -7
  44. package/internals/regexp-unsupported-dot-all.js +7 -0
  45. package/internals/regexp-unsupported-ncg.js +8 -0
  46. package/internals/shared.js +1 -1
  47. package/modules/es.array.sort.js +73 -4
  48. package/modules/es.date.get-year.js +12 -0
  49. package/modules/es.date.set-year.js +18 -0
  50. package/modules/es.date.to-gmt-string.js +7 -0
  51. package/modules/es.escape.js +35 -0
  52. package/modules/es.regexp.constructor.js +121 -15
  53. package/modules/es.regexp.dot-all.js +22 -0
  54. package/modules/es.regexp.flags.js +10 -8
  55. package/modules/es.regexp.sticky.js +1 -1
  56. package/modules/es.string.match.js +5 -5
  57. package/modules/es.string.replace.js +37 -10
  58. package/modules/es.string.search.js +5 -5
  59. package/modules/es.string.split.js +18 -6
  60. package/modules/es.string.substr.js +25 -0
  61. package/modules/es.typed-array.sort.js +77 -3
  62. package/modules/es.unescape.js +39 -0
  63. package/modules/web.url.js +3 -3
  64. package/package.json +2 -2
  65. package/stable/date/get-year.js +3 -0
  66. package/stable/date/set-year.js +3 -0
  67. package/stable/date/to-gmt-string.js +3 -0
  68. package/stable/escape.js +3 -0
  69. package/stable/index.js +7 -0
  70. package/stable/regexp/dot-all.js +3 -0
  71. package/stable/string/substr.js +3 -0
  72. package/stable/string/virtual/substr.js +3 -0
  73. package/stable/unescape.js +3 -0
  74. package/stage/2.js +0 -1
  75. package/stage/3.js +1 -0
@@ -2,9 +2,13 @@
2
2
  var IS_PURE = require('../internals/is-pure');
3
3
  var global = require('../internals/global');
4
4
  var fails = require('../internals/fails');
5
+ var WEBKIT = require('../internals/engine-webkit-version');
5
6
 
6
7
  // Forced replacement object prototype accessors methods
7
8
  module.exports = IS_PURE || !fails(function () {
9
+ // This feature detection crashes old WebKit
10
+ // https://github.com/zloirock/core-js/issues/232
11
+ if (WEBKIT && WEBKIT < 535) return;
8
12
  var key = Math.random();
9
13
  // In FF throws only define methods
10
14
  // eslint-disable-next-line no-undef, no-useless-call -- required for testing
@@ -1,9 +1,13 @@
1
1
  'use strict';
2
2
  /* eslint-disable regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- testing */
3
3
  /* eslint-disable regexp/no-useless-quantifier -- testing */
4
- var regexpFlags = require('./regexp-flags');
5
- var stickyHelpers = require('./regexp-sticky-helpers');
6
- var shared = require('./shared');
4
+ var regexpFlags = require('../internals/regexp-flags');
5
+ var stickyHelpers = require('../internals/regexp-sticky-helpers');
6
+ var shared = require('../internals/shared');
7
+ var create = require('../internals/object-create');
8
+ var getInternalState = require('../internals/internal-state').get;
9
+ var UNSUPPORTED_DOT_ALL = require('../internals/regexp-unsupported-dot-all');
10
+ var UNSUPPORTED_NCG = require('../internals/regexp-unsupported-ncg');
7
11
 
8
12
  var nativeExec = RegExp.prototype.exec;
9
13
  var nativeReplace = shared('native-string-replace', String.prototype.replace);
@@ -23,12 +27,24 @@ var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET;
23
27
  // nonparticipating capturing group, copied from es5-shim's String#split patch.
24
28
  var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
25
29
 
26
- var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y;
30
+ var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y || UNSUPPORTED_DOT_ALL || UNSUPPORTED_NCG;
27
31
 
28
32
  if (PATCH) {
33
+ // eslint-disable-next-line max-statements -- TODO
29
34
  patchedExec = function exec(str) {
30
35
  var re = this;
31
- var lastIndex, reCopy, match, i;
36
+ var state = getInternalState(re);
37
+ var raw = state.raw;
38
+ var result, reCopy, lastIndex, match, i, object, group;
39
+
40
+ if (raw) {
41
+ raw.lastIndex = re.lastIndex;
42
+ result = patchedExec.call(raw, str);
43
+ re.lastIndex = raw.lastIndex;
44
+ return result;
45
+ }
46
+
47
+ var groups = state.groups;
32
48
  var sticky = UNSUPPORTED_Y && re.sticky;
33
49
  var flags = regexpFlags.call(re);
34
50
  var source = re.source;
@@ -80,6 +96,14 @@ if (PATCH) {
80
96
  });
81
97
  }
82
98
 
99
+ if (match && groups) {
100
+ match.groups = object = create(null);
101
+ for (i = 0; i < groups.length; i++) {
102
+ group = groups[i];
103
+ object[group[0]] = match[group[1]];
104
+ }
105
+ }
106
+
83
107
  return match;
84
108
  };
85
109
  }
@@ -1,15 +1,11 @@
1
- 'use strict';
2
-
3
- var fails = require('./fails');
1
+ var fails = require('../internals/fails');
4
2
 
5
3
  // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
6
- // so we use an intermediate function.
7
- function RE(s, f) {
4
+ var RE = function (s, f) {
8
5
  return RegExp(s, f);
9
- }
6
+ };
10
7
 
11
8
  exports.UNSUPPORTED_Y = fails(function () {
12
- // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError
13
9
  var re = RE('a', 'y');
14
10
  re.lastIndex = 2;
15
11
  return re.exec('abcd') != null;
@@ -0,0 +1,7 @@
1
+ var fails = require('./fails');
2
+
3
+ module.exports = fails(function () {
4
+ // babel-minify transpiles RegExp('.', 's') -> /./s and it causes SyntaxError
5
+ var re = RegExp('.', (typeof '').charAt(0));
6
+ return !(re.dotAll && re.exec('\n') && re.flags === 's');
7
+ });
@@ -0,0 +1,8 @@
1
+ var fails = require('./fails');
2
+
3
+ module.exports = fails(function () {
4
+ // babel-minify transpiles RegExp('.', 'g') -> /./g and it causes SyntaxError
5
+ var re = RegExp('(?<a>b)', (typeof '').charAt(5));
6
+ return re.exec('b').groups.a !== 'b' ||
7
+ 'b'.replace(re, '$<a>c') !== 'bc';
8
+ });
@@ -4,7 +4,7 @@ var store = require('../internals/shared-store');
4
4
  (module.exports = function (key, value) {
5
5
  return store[key] || (store[key] = value !== undefined ? value : {});
6
6
  })('versions', []).push({
7
- version: '3.12.1',
7
+ version: '3.15.0',
8
8
  mode: IS_PURE ? 'pure' : 'global',
9
9
  copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
10
10
  });
@@ -2,8 +2,14 @@
2
2
  var $ = require('../internals/export');
3
3
  var aFunction = require('../internals/a-function');
4
4
  var toObject = require('../internals/to-object');
5
+ var toLength = require('../internals/to-length');
5
6
  var fails = require('../internals/fails');
7
+ var internalSort = require('../internals/array-sort');
6
8
  var arrayMethodIsStrict = require('../internals/array-method-is-strict');
9
+ var FF = require('../internals/engine-ff-version');
10
+ var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
11
+ var V8 = require('../internals/engine-v8-version');
12
+ var WEBKIT = require('../internals/engine-webkit-version');
7
13
 
8
14
  var test = [];
9
15
  var nativeSort = test.sort;
@@ -19,14 +25,77 @@ var FAILS_ON_NULL = fails(function () {
19
25
  // Old WebKit
20
26
  var STRICT_METHOD = arrayMethodIsStrict('sort');
21
27
 
22
- var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD;
28
+ var STABLE_SORT = !fails(function () {
29
+ // feature detection can be too slow, so check engines versions
30
+ if (V8) return V8 < 70;
31
+ if (FF && FF > 3) return;
32
+ if (IE_OR_EDGE) return true;
33
+ if (WEBKIT) return WEBKIT < 603;
34
+
35
+ var result = '';
36
+ var code, chr, value, index;
37
+
38
+ // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
39
+ for (code = 65; code < 76; code++) {
40
+ chr = String.fromCharCode(code);
41
+
42
+ switch (code) {
43
+ case 66: case 69: case 70: case 72: value = 3; break;
44
+ case 68: case 71: value = 4; break;
45
+ default: value = 2;
46
+ }
47
+
48
+ for (index = 0; index < 47; index++) {
49
+ test.push({ k: chr + index, v: value });
50
+ }
51
+ }
52
+
53
+ test.sort(function (a, b) { return b.v - a.v; });
54
+
55
+ for (index = 0; index < test.length; index++) {
56
+ chr = test[index].k.charAt(0);
57
+ if (result.charAt(result.length - 1) !== chr) result += chr;
58
+ }
59
+
60
+ return result !== 'DGBEFHACIJK';
61
+ });
62
+
63
+ var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
64
+
65
+ var getSortCompare = function (comparefn) {
66
+ return function (x, y) {
67
+ if (y === undefined) return -1;
68
+ if (x === undefined) return 1;
69
+ if (comparefn !== undefined) return +comparefn(x, y) || 0;
70
+ return String(x) > String(y) ? 1 : -1;
71
+ };
72
+ };
23
73
 
24
74
  // `Array.prototype.sort` method
25
75
  // https://tc39.es/ecma262/#sec-array.prototype.sort
26
76
  $({ target: 'Array', proto: true, forced: FORCED }, {
27
77
  sort: function sort(comparefn) {
28
- return comparefn === undefined
29
- ? nativeSort.call(toObject(this))
30
- : nativeSort.call(toObject(this), aFunction(comparefn));
78
+ if (comparefn !== undefined) aFunction(comparefn);
79
+
80
+ var array = toObject(this);
81
+
82
+ if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
83
+
84
+ var items = [];
85
+ var arrayLength = toLength(array.length);
86
+ var itemsLength, index;
87
+
88
+ for (index = 0; index < arrayLength; index++) {
89
+ if (index in array) items.push(array[index]);
90
+ }
91
+
92
+ items = internalSort(items, getSortCompare(comparefn));
93
+ itemsLength = items.length;
94
+ index = 0;
95
+
96
+ while (index < itemsLength) array[index] = items[index++];
97
+ while (index < arrayLength) delete array[index++];
98
+
99
+ return array;
31
100
  }
32
101
  });
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+ var $ = require('../internals/export');
3
+
4
+ var getFullYear = Date.prototype.getFullYear;
5
+
6
+ // `Date.prototype.getYear` method
7
+ // https://tc39.es/ecma262/#sec-date.prototype.getyear
8
+ $({ target: 'Date', proto: true }, {
9
+ getYear: function getYear() {
10
+ return getFullYear.call(this) - 1900;
11
+ }
12
+ });
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+ var $ = require('../internals/export');
3
+ var toInteger = require('../internals/to-integer');
4
+
5
+ var getTime = Date.prototype.getTime;
6
+ var setFullYear = Date.prototype.setFullYear;
7
+
8
+ // `Date.prototype.setYear` method
9
+ // https://tc39.es/ecma262/#sec-date.prototype.setyear
10
+ $({ target: 'Date', proto: true }, {
11
+ setYear: function setYear(year) {
12
+ // validate
13
+ getTime.call(this);
14
+ var yi = toInteger(year);
15
+ var yyyy = 0 <= yi && yi <= 99 ? yi + 1900 : yi;
16
+ return setFullYear.call(this, yyyy);
17
+ }
18
+ });
@@ -0,0 +1,7 @@
1
+ var $ = require('../internals/export');
2
+
3
+ // `Date.prototype.toGMTString` method
4
+ // https://tc39.es/ecma262/#sec-date.prototype.togmtstring
5
+ $({ target: 'Date', proto: true }, {
6
+ toGMTString: Date.prototype.toUTCString
7
+ });
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+ var $ = require('../internals/export');
3
+
4
+ var raw = /[\w*+\-./@]/;
5
+
6
+ var hex = function (code, length) {
7
+ var result = code.toString(16);
8
+ while (result.length < length) result = '0' + result;
9
+ return result;
10
+ };
11
+
12
+ // `escape` method
13
+ // https://tc39.es/ecma262/#sec-escape-string
14
+ $({ global: true }, {
15
+ escape: function escape(string) {
16
+ var str = String(string);
17
+ var result = '';
18
+ var length = str.length;
19
+ var index = 0;
20
+ var chr, code;
21
+ while (index < length) {
22
+ chr = str.charAt(index++);
23
+ if (raw.test(chr)) {
24
+ result += chr;
25
+ } else {
26
+ code = chr.charCodeAt(0);
27
+ if (code < 256) {
28
+ result += '%' + hex(code, 2);
29
+ } else {
30
+ result += '%u' + hex(code, 4).toUpperCase();
31
+ }
32
+ }
33
+ } return result;
34
+ }
35
+ });
@@ -2,6 +2,7 @@ var DESCRIPTORS = require('../internals/descriptors');
2
2
  var global = require('../internals/global');
3
3
  var isForced = require('../internals/is-forced');
4
4
  var inheritIfRequired = require('../internals/inherit-if-required');
5
+ var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
5
6
  var defineProperty = require('../internals/object-define-property').f;
6
7
  var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
7
8
  var isRegExp = require('../internals/is-regexp');
@@ -9,13 +10,18 @@ var getFlags = require('../internals/regexp-flags');
9
10
  var stickyHelpers = require('../internals/regexp-sticky-helpers');
10
11
  var redefine = require('../internals/redefine');
11
12
  var fails = require('../internals/fails');
13
+ var has = require('../internals/has');
12
14
  var enforceInternalState = require('../internals/internal-state').enforce;
13
15
  var setSpecies = require('../internals/set-species');
14
16
  var wellKnownSymbol = require('../internals/well-known-symbol');
17
+ var UNSUPPORTED_DOT_ALL = require('../internals/regexp-unsupported-dot-all');
18
+ var UNSUPPORTED_NCG = require('../internals/regexp-unsupported-ncg');
15
19
 
16
20
  var MATCH = wellKnownSymbol('match');
17
21
  var NativeRegExp = global.RegExp;
18
22
  var RegExpPrototype = NativeRegExp.prototype;
23
+ // TODO: Use only propper RegExpIdentifierName
24
+ var IS_NCG = /^\?<[^\s\d!#%&*+<=>@^][^\s!#%&*+<=>@^]*>/;
19
25
  var re1 = /a/g;
20
26
  var re2 = /a/g;
21
27
 
@@ -24,20 +30,90 @@ var CORRECT_NEW = new NativeRegExp(re1) !== re1;
24
30
 
25
31
  var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y;
26
32
 
27
- var FORCED = DESCRIPTORS && isForced('RegExp', (!CORRECT_NEW || UNSUPPORTED_Y || fails(function () {
28
- re2[MATCH] = false;
29
- // RegExp constructor can alter flags and IsRegExp works correct with @@match
30
- return NativeRegExp(re1) != re1 || NativeRegExp(re2) == re2 || NativeRegExp(re1, 'i') != '/a/i';
31
- })));
33
+ var BASE_FORCED = DESCRIPTORS &&
34
+ (!CORRECT_NEW || UNSUPPORTED_Y || UNSUPPORTED_DOT_ALL || UNSUPPORTED_NCG || fails(function () {
35
+ re2[MATCH] = false;
36
+ // RegExp constructor can alter flags and IsRegExp works correct with @@match
37
+ return NativeRegExp(re1) != re1 || NativeRegExp(re2) == re2 || NativeRegExp(re1, 'i') != '/a/i';
38
+ }));
39
+
40
+ var handleDotAll = function (string) {
41
+ var length = string.length;
42
+ var index = 0;
43
+ var result = '';
44
+ var brackets = false;
45
+ var chr;
46
+ for (; index <= length; index++) {
47
+ chr = string.charAt(index);
48
+ if (chr === '\\') {
49
+ result += chr + string.charAt(++index);
50
+ continue;
51
+ }
52
+ if (!brackets && chr === '.') {
53
+ result += '[\\s\\S]';
54
+ } else {
55
+ if (chr === '[') {
56
+ brackets = true;
57
+ } else if (chr === ']') {
58
+ brackets = false;
59
+ } result += chr;
60
+ }
61
+ } return result;
62
+ };
63
+
64
+ var handleNCG = function (string) {
65
+ var length = string.length;
66
+ var index = 0;
67
+ var result = '';
68
+ var named = [];
69
+ var names = {};
70
+ var brackets = false;
71
+ var ncg = false;
72
+ var groupid = 0;
73
+ var groupname = '';
74
+ var chr;
75
+ for (; index <= length; index++) {
76
+ chr = string.charAt(index);
77
+ if (chr === '\\') {
78
+ chr = chr + string.charAt(++index);
79
+ } else if (chr === ']') {
80
+ brackets = false;
81
+ } else if (!brackets) switch (true) {
82
+ case chr === '[':
83
+ brackets = true;
84
+ break;
85
+ case chr === '(':
86
+ if (IS_NCG.test(string.slice(index + 1))) {
87
+ index += 2;
88
+ ncg = true;
89
+ }
90
+ result += chr;
91
+ groupid++;
92
+ continue;
93
+ case chr === '>' && ncg:
94
+ if (groupname === '' || has(names, groupname)) {
95
+ throw new SyntaxError('Invalid capture group name');
96
+ }
97
+ names[groupname] = true;
98
+ named.push([groupname, groupid]);
99
+ ncg = false;
100
+ groupname = '';
101
+ continue;
102
+ }
103
+ if (ncg) groupname += chr;
104
+ else result += chr;
105
+ } return [result, named];
106
+ };
32
107
 
33
108
  // `RegExp` constructor
34
109
  // https://tc39.es/ecma262/#sec-regexp-constructor
35
- if (FORCED) {
110
+ if (isForced('RegExp', BASE_FORCED)) {
36
111
  var RegExpWrapper = function RegExp(pattern, flags) {
37
112
  var thisIsRegExp = this instanceof RegExpWrapper;
38
113
  var patternIsRegExp = isRegExp(pattern);
39
114
  var flagsAreUndefined = flags === undefined;
40
- var sticky;
115
+ var groups = [];
116
+ var rawPattern, rawFlags, dotAll, sticky, handled, result, state;
41
117
 
42
118
  if (!thisIsRegExp && patternIsRegExp && pattern.constructor === RegExpWrapper && flagsAreUndefined) {
43
119
  return pattern;
@@ -50,24 +126,52 @@ if (FORCED) {
50
126
  pattern = pattern.source;
51
127
  }
52
128
 
53
- if (UNSUPPORTED_Y) {
129
+ pattern = pattern === undefined ? '' : String(pattern);
130
+ flags = flags === undefined ? '' : String(flags);
131
+ rawPattern = pattern;
132
+
133
+ if (UNSUPPORTED_DOT_ALL && 'dotAll' in re1) {
134
+ dotAll = !!flags && flags.indexOf('s') > -1;
135
+ if (dotAll) flags = flags.replace(/s/g, '');
136
+ }
137
+
138
+ rawFlags = flags;
139
+
140
+ if (UNSUPPORTED_Y && 'sticky' in re1) {
54
141
  sticky = !!flags && flags.indexOf('y') > -1;
55
142
  if (sticky) flags = flags.replace(/y/g, '');
56
143
  }
57
144
 
58
- var result = inheritIfRequired(
145
+ if (UNSUPPORTED_NCG) {
146
+ handled = handleNCG(pattern);
147
+ pattern = handled[0];
148
+ groups = handled[1];
149
+ }
150
+
151
+ result = inheritIfRequired(
59
152
  CORRECT_NEW ? new NativeRegExp(pattern, flags) : NativeRegExp(pattern, flags),
60
153
  thisIsRegExp ? this : RegExpPrototype,
61
154
  RegExpWrapper
62
155
  );
63
156
 
64
- if (UNSUPPORTED_Y && sticky) {
65
- var state = enforceInternalState(result);
66
- state.sticky = true;
157
+ if (dotAll || sticky || groups.length) {
158
+ state = enforceInternalState(result);
159
+ if (dotAll) {
160
+ state.dotAll = true;
161
+ state.raw = RegExpWrapper(handleDotAll(pattern), rawFlags);
162
+ }
163
+ if (sticky) state.sticky = true;
164
+ if (groups.length) state.groups = groups;
67
165
  }
68
166
 
167
+ if (pattern !== rawPattern) try {
168
+ // fails in old engines, but we have no alternatives for unsupported regex syntax
169
+ createNonEnumerableProperty(result, 'source', rawPattern === '' ? '(?:)' : rawPattern);
170
+ } catch (error) { /* empty */ }
171
+
69
172
  return result;
70
173
  };
174
+
71
175
  var proxy = function (key) {
72
176
  key in RegExpWrapper || defineProperty(RegExpWrapper, key, {
73
177
  configurable: true,
@@ -75,9 +179,11 @@ if (FORCED) {
75
179
  set: function (it) { NativeRegExp[key] = it; }
76
180
  });
77
181
  };
78
- var keys = getOwnPropertyNames(NativeRegExp);
79
- var index = 0;
80
- while (keys.length > index) proxy(keys[index++]);
182
+
183
+ for (var keys = getOwnPropertyNames(NativeRegExp), index = 0; keys.length > index;) {
184
+ proxy(keys[index++]);
185
+ }
186
+
81
187
  RegExpPrototype.constructor = RegExpWrapper;
82
188
  RegExpWrapper.prototype = RegExpPrototype;
83
189
  redefine(global, 'RegExp', RegExpWrapper);
@@ -0,0 +1,22 @@
1
+ var DESCRIPTORS = require('../internals/descriptors');
2
+ var UNSUPPORTED_DOT_ALL = require('../internals/regexp-unsupported-dot-all');
3
+ var defineProperty = require('../internals/object-define-property').f;
4
+ var getInternalState = require('../internals/internal-state').get;
5
+ var RegExpPrototype = RegExp.prototype;
6
+
7
+ // `RegExp.prototype.dotAll` getter
8
+ // https://tc39.es/ecma262/#sec-get-regexp.prototype.dotall
9
+ if (DESCRIPTORS && UNSUPPORTED_DOT_ALL) {
10
+ defineProperty(RegExpPrototype, 'dotAll', {
11
+ configurable: true,
12
+ get: function () {
13
+ if (this === RegExpPrototype) return undefined;
14
+ // We can't use InternalStateModule.getterFor because
15
+ // we don't add metadata for regexps created by a literal.
16
+ if (this instanceof RegExp) {
17
+ return !!getInternalState(this).dotAll;
18
+ }
19
+ throw TypeError('Incompatible receiver, RegExp required');
20
+ }
21
+ });
22
+ }
@@ -1,14 +1,16 @@
1
1
  var DESCRIPTORS = require('../internals/descriptors');
2
2
  var objectDefinePropertyModule = require('../internals/object-define-property');
3
3
  var regExpFlags = require('../internals/regexp-flags');
4
- var UNSUPPORTED_Y = require('../internals/regexp-sticky-helpers').UNSUPPORTED_Y;
4
+ var fails = require('../internals/fails');
5
+
6
+ var FORCED = DESCRIPTORS && fails(function () {
7
+ // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
8
+ return Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get.call({ dotAll: true, sticky: true }) !== 'sy';
9
+ });
5
10
 
6
11
  // `RegExp.prototype.flags` getter
7
12
  // https://tc39.es/ecma262/#sec-get-regexp.prototype.flags
8
- // eslint-disable-next-line es/no-regexp-prototype-flags -- required for testing
9
- if (DESCRIPTORS && (/./g.flags != 'g' || UNSUPPORTED_Y)) {
10
- objectDefinePropertyModule.f(RegExp.prototype, 'flags', {
11
- configurable: true,
12
- get: regExpFlags
13
- });
14
- }
13
+ if (FORCED) objectDefinePropertyModule.f(RegExp.prototype, 'flags', {
14
+ configurable: true,
15
+ get: regExpFlags
16
+ });
@@ -7,7 +7,7 @@ var RegExpPrototype = RegExp.prototype;
7
7
  // `RegExp.prototype.sticky` getter
8
8
  // https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
9
9
  if (DESCRIPTORS && UNSUPPORTED_Y) {
10
- defineProperty(RegExp.prototype, 'sticky', {
10
+ defineProperty(RegExpPrototype, 'sticky', {
11
11
  configurable: true,
12
12
  get: function () {
13
13
  if (this === RegExpPrototype) return undefined;
@@ -7,7 +7,7 @@ var advanceStringIndex = require('../internals/advance-string-index');
7
7
  var regExpExec = require('../internals/regexp-exec-abstract');
8
8
 
9
9
  // @@match logic
10
- fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCallNative) {
10
+ fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
11
11
  return [
12
12
  // `String.prototype.match` method
13
13
  // https://tc39.es/ecma262/#sec-string.prototype.match
@@ -18,12 +18,12 @@ fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCal
18
18
  },
19
19
  // `RegExp.prototype[@@match]` method
20
20
  // 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);
23
23
  if (res.done) return res.value;
24
24
 
25
- var rx = anObject(regexp);
26
- var S = String(this);
25
+ var rx = anObject(this);
26
+ var S = String(string);
27
27
 
28
28
  if (!rx.global) return regExpExec(rx, S);
29
29
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
3
+ var fails = require('../internals/fails');
3
4
  var anObject = require('../internals/an-object');
4
5
  var toLength = require('../internals/to-length');
5
6
  var toInteger = require('../internals/to-integer');
@@ -7,7 +8,9 @@ var requireObjectCoercible = require('../internals/require-object-coercible');
7
8
  var advanceStringIndex = require('../internals/advance-string-index');
8
9
  var getSubstitution = require('../internals/get-substitution');
9
10
  var regExpExec = require('../internals/regexp-exec-abstract');
11
+ var wellKnownSymbol = require('../internals/well-known-symbol');
10
12
 
13
+ var REPLACE = wellKnownSymbol('replace');
11
14
  var max = Math.max;
12
15
  var min = Math.min;
13
16
 
@@ -15,10 +18,33 @@ var maybeToString = function (it) {
15
18
  return it === undefined ? it : String(it);
16
19
  };
17
20
 
21
+ // IE <= 11 replaces $0 with the whole match, as if it was $&
22
+ // https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0
23
+ var REPLACE_KEEPS_$0 = (function () {
24
+ // eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
25
+ return 'a'.replace(/./, '$0') === '$0';
26
+ })();
27
+
28
+ // Safari <= 13.0.3(?) substitutes nth capture where n>m with an empty string
29
+ var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () {
30
+ if (/./[REPLACE]) {
31
+ return /./[REPLACE]('a', '$0') === '';
32
+ }
33
+ return false;
34
+ })();
35
+
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
+
18
46
  // @@replace logic
19
- fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) {
20
- var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE;
21
- var REPLACE_KEEPS_$0 = reason.REPLACE_KEEPS_$0;
47
+ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNative) {
22
48
  var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';
23
49
 
24
50
  return [
@@ -33,17 +59,18 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, ma
33
59
  },
34
60
  // `RegExp.prototype[@@replace]` method
35
61
  // https://tc39.es/ecma262/#sec-regexp.prototype-@@replace
36
- function (regexp, replaceValue) {
62
+ function (string, replaceValue) {
37
63
  if (
38
- (!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0) ||
39
- (typeof replaceValue === 'string' && replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1)
64
+ typeof replaceValue === 'string' &&
65
+ replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1 &&
66
+ replaceValue.indexOf('$<') === -1
40
67
  ) {
41
- var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
68
+ var res = maybeCallNative(nativeReplace, this, string, replaceValue);
42
69
  if (res.done) return res.value;
43
70
  }
44
71
 
45
- var rx = anObject(regexp);
46
- var S = String(this);
72
+ var rx = anObject(this);
73
+ var S = String(string);
47
74
 
48
75
  var functionalReplace = typeof replaceValue === 'function';
49
76
  if (!functionalReplace) replaceValue = String(replaceValue);
@@ -95,4 +122,4 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, ma
95
122
  return accumulatedResult + S.slice(nextSourcePosition);
96
123
  }
97
124
  ];
98
- });
125
+ }, !REPLACE_SUPPORTS_NAMED_GROUPS || !REPLACE_KEEPS_$0 || REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE);