core-js 3.5.0 → 3.6.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.
package/es/index.js CHANGED
@@ -105,6 +105,8 @@ require('../modules/es.string.sup');
105
105
  require('../modules/es.regexp.constructor');
106
106
  require('../modules/es.regexp.exec');
107
107
  require('../modules/es.regexp.flags');
108
+ require('../modules/es.regexp.sticky');
109
+ require('../modules/es.regexp.test');
108
110
  require('../modules/es.regexp.to-string');
109
111
  require('../modules/es.parse-int');
110
112
  require('../modules/es.parse-float');
@@ -2,6 +2,8 @@ require('../../modules/es.regexp.constructor');
2
2
  require('../../modules/es.regexp.to-string');
3
3
  require('../../modules/es.regexp.exec');
4
4
  require('../../modules/es.regexp.flags');
5
+ require('../../modules/es.regexp.sticky');
6
+ require('../../modules/es.regexp.test');
5
7
  require('../../modules/es.string.match');
6
8
  require('../../modules/es.string.replace');
7
9
  require('../../modules/es.string.search');
@@ -0,0 +1,5 @@
1
+ require('../../modules/es.regexp.sticky');
2
+
3
+ module.exports = function (it) {
4
+ return it.sticky;
5
+ };
@@ -0,0 +1,5 @@
1
+ require('../../modules/es.regexp.test');
2
+
3
+ module.exports = function (re, string) {
4
+ return RegExp.prototype.test.call(re, string);
5
+ };
@@ -1,3 +1,6 @@
1
+ // TODO: remove from `core-js@4`
2
+ require('../../modules/esnext.string.match-all');
3
+
1
4
  var parent = require('../../es/instance/match-all');
2
5
 
3
6
  module.exports = parent;
@@ -0,0 +1,3 @@
1
+ var parent = require('../../es/regexp/sticky');
2
+
3
+ module.exports = parent;
@@ -0,0 +1,3 @@
1
+ var parent = require('../../es/regexp/test');
2
+
3
+ module.exports = parent;
@@ -1,6 +1,6 @@
1
1
  var wellKnownSymbol = require('../internals/well-known-symbol');
2
2
  var create = require('../internals/object-create');
3
- var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
3
+ var definePropertyModule = require('../internals/object-define-property');
4
4
 
5
5
  var UNSCOPABLES = wellKnownSymbol('unscopables');
6
6
  var ArrayPrototype = Array.prototype;
@@ -8,7 +8,10 @@ var ArrayPrototype = Array.prototype;
8
8
  // Array.prototype[@@unscopables]
9
9
  // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
10
10
  if (ArrayPrototype[UNSCOPABLES] == undefined) {
11
- createNonEnumerableProperty(ArrayPrototype, UNSCOPABLES, create(null));
11
+ definePropertyModule.f(ArrayPrototype, UNSCOPABLES, {
12
+ configurable: true,
13
+ value: create(null)
14
+ });
12
15
  }
13
16
 
14
17
  // add a key to Array.prototype[@@unscopables]
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
- var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
3
2
  var redefine = require('../internals/redefine');
4
3
  var fails = require('../internals/fails');
5
4
  var wellKnownSymbol = require('../internals/well-known-symbol');
6
5
  var regexpExec = require('../internals/regexp-exec');
6
+ var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
7
7
 
8
8
  var SPECIES = wellKnownSymbol('species');
9
9
 
@@ -20,6 +20,12 @@ var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
20
20
  return ''.replace(re, '$<a>') !== '7';
21
21
  });
22
22
 
23
+ // IE <= 11 replaces $0 with the whole match, as if it was $&
24
+ // https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0
25
+ var REPLACE_KEEPS_$0 = (function () {
26
+ return 'a'.replace(/./, '$0') === '$0';
27
+ })();
28
+
23
29
  // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
24
30
  // Weex JS has frozen built-in prototypes, so use try / catch wrapper
25
31
  var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () {
@@ -67,7 +73,7 @@ module.exports = function (KEY, length, exec, sham) {
67
73
  if (
68
74
  !DELEGATES_TO_SYMBOL ||
69
75
  !DELEGATES_TO_EXEC ||
70
- (KEY === 'replace' && !REPLACE_SUPPORTS_NAMED_GROUPS) ||
76
+ (KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && REPLACE_KEEPS_$0)) ||
71
77
  (KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
72
78
  ) {
73
79
  var nativeRegExpMethod = /./[SYMBOL];
@@ -82,7 +88,7 @@ module.exports = function (KEY, length, exec, sham) {
82
88
  return { done: true, value: nativeMethod.call(str, regexp, arg2) };
83
89
  }
84
90
  return { done: false };
85
- });
91
+ }, { REPLACE_KEEPS_$0: REPLACE_KEEPS_$0 });
86
92
  var stringMethod = methods[0];
87
93
  var regexMethod = methods[1];
88
94
 
@@ -95,6 +101,7 @@ module.exports = function (KEY, length, exec, sham) {
95
101
  // 21.2.5.9 RegExp.prototype[@@search](string)
96
102
  : function (string) { return regexMethod.call(string, this); }
97
103
  );
98
- if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true);
99
104
  }
105
+
106
+ if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true);
100
107
  };
@@ -5,45 +5,74 @@ var hiddenKeys = require('../internals/hidden-keys');
5
5
  var html = require('../internals/html');
6
6
  var documentCreateElement = require('../internals/document-create-element');
7
7
  var sharedKey = require('../internals/shared-key');
8
- var IE_PROTO = sharedKey('IE_PROTO');
9
8
 
9
+ var GT = '>';
10
+ var LT = '<';
10
11
  var PROTOTYPE = 'prototype';
11
- var Empty = function () { /* empty */ };
12
+ var SCRIPT = 'script';
13
+ var IE_PROTO = sharedKey('IE_PROTO');
14
+
15
+ var EmptyConstructor = function () { /* empty */ };
16
+
17
+ var scriptTag = function (content) {
18
+ return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
19
+ };
20
+
21
+ // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
22
+ var NullProtoObjectViaActiveX = function (activeXDocument) {
23
+ activeXDocument.write(scriptTag(''));
24
+ activeXDocument.close();
25
+ var temp = activeXDocument.parentWindow.Object;
26
+ activeXDocument = null; // avoid memory leak
27
+ return temp;
28
+ };
12
29
 
13
30
  // Create object with fake `null` prototype: use iframe Object with cleared prototype
14
- var createDict = function () {
31
+ var NullProtoObjectViaIFrame = function () {
15
32
  // Thrash, waste and sodomy: IE GC bug
16
33
  var iframe = documentCreateElement('iframe');
17
- var length = enumBugKeys.length;
18
- var lt = '<';
19
- var script = 'script';
20
- var gt = '>';
21
- var js = 'java' + script + ':';
34
+ var JS = 'java' + SCRIPT + ':';
22
35
  var iframeDocument;
23
36
  iframe.style.display = 'none';
24
37
  html.appendChild(iframe);
25
- iframe.src = String(js);
38
+ // https://github.com/zloirock/core-js/issues/475
39
+ iframe.src = String(JS);
26
40
  iframeDocument = iframe.contentWindow.document;
27
41
  iframeDocument.open();
28
- iframeDocument.write(lt + script + gt + 'document.F=Object' + lt + '/' + script + gt);
42
+ iframeDocument.write(scriptTag('document.F=Object'));
29
43
  iframeDocument.close();
30
- createDict = iframeDocument.F;
31
- while (length--) delete createDict[PROTOTYPE][enumBugKeys[length]];
32
- return createDict();
44
+ return iframeDocument.F;
33
45
  };
34
46
 
47
+ // Check for document.domain and active x support
48
+ // No need to use active x approach when document.domain is not set
49
+ // see https://github.com/es-shims/es5-shim/issues/150
50
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
51
+ // avoid IE GC bug
52
+ var activeXDocument;
53
+ var NullProtoObject = function () {
54
+ try {
55
+ /* global ActiveXObject */
56
+ activeXDocument = document.domain && new ActiveXObject('htmlfile');
57
+ } catch (error) { /* ignore */ }
58
+ NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
59
+ var length = enumBugKeys.length;
60
+ while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
61
+ return NullProtoObject();
62
+ };
63
+
64
+ hiddenKeys[IE_PROTO] = true;
65
+
35
66
  // `Object.create` method
36
67
  // https://tc39.github.io/ecma262/#sec-object.create
37
68
  module.exports = Object.create || function create(O, Properties) {
38
69
  var result;
39
70
  if (O !== null) {
40
- Empty[PROTOTYPE] = anObject(O);
41
- result = new Empty();
42
- Empty[PROTOTYPE] = null;
71
+ EmptyConstructor[PROTOTYPE] = anObject(O);
72
+ result = new EmptyConstructor();
73
+ EmptyConstructor[PROTOTYPE] = null;
43
74
  // add "__proto__" for Object.getPrototypeOf polyfill
44
75
  result[IE_PROTO] = O;
45
- } else result = createDict();
76
+ } else result = NullProtoObject();
46
77
  return Properties === undefined ? result : defineProperties(result, Properties);
47
78
  };
48
-
49
- hiddenKeys[IE_PROTO] = true;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  var regexpFlags = require('./regexp-flags');
3
+ var stickyHelpers = require('./regexp-sticky-helpers');
3
4
 
4
5
  var nativeExec = RegExp.prototype.exec;
5
6
  // This always refers to the native implementation, because the
@@ -17,24 +18,56 @@ var UPDATES_LAST_INDEX_WRONG = (function () {
17
18
  return re1.lastIndex !== 0 || re2.lastIndex !== 0;
18
19
  })();
19
20
 
21
+ var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET;
22
+
20
23
  // nonparticipating capturing group, copied from es5-shim's String#split patch.
21
24
  var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
22
25
 
23
- var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED;
26
+ var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y;
24
27
 
25
28
  if (PATCH) {
26
29
  patchedExec = function exec(str) {
27
30
  var re = this;
28
31
  var lastIndex, reCopy, match, i;
32
+ var sticky = UNSUPPORTED_Y && re.sticky;
33
+ var flags = regexpFlags.call(re);
34
+ var source = re.source;
35
+ var charsAdded = 0;
36
+ var strCopy = str;
37
+
38
+ if (sticky) {
39
+ flags = flags.replace('y', '');
40
+ if (flags.indexOf('g') === -1) {
41
+ flags += 'g';
42
+ }
43
+
44
+ strCopy = String(str).slice(re.lastIndex);
45
+ // Support anchored sticky behavior.
46
+ if (re.lastIndex > 0 && (!re.multiline || re.multiline && str[re.lastIndex - 1] !== '\n')) {
47
+ source = '(?: ' + source + ')';
48
+ strCopy = ' ' + strCopy;
49
+ charsAdded++;
50
+ }
51
+ // ^(? + rx + ) is needed, in combination with some str slicing, to
52
+ // simulate the 'y' flag.
53
+ reCopy = new RegExp('^(?:' + source + ')', flags);
54
+ }
29
55
 
30
56
  if (NPCG_INCLUDED) {
31
- reCopy = new RegExp('^' + re.source + '$(?!\\s)', regexpFlags.call(re));
57
+ reCopy = new RegExp('^' + source + '$(?!\\s)', flags);
32
58
  }
33
59
  if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex;
34
60
 
35
- match = nativeExec.call(re, str);
61
+ match = nativeExec.call(sticky ? reCopy : re, strCopy);
36
62
 
37
- if (UPDATES_LAST_INDEX_WRONG && match) {
63
+ if (sticky) {
64
+ if (match) {
65
+ match.input = match.input.slice(charsAdded);
66
+ match[0] = match[0].slice(charsAdded);
67
+ match.index = re.lastIndex;
68
+ re.lastIndex += match[0].length;
69
+ } else re.lastIndex = 0;
70
+ } else if (UPDATES_LAST_INDEX_WRONG && match) {
38
71
  re.lastIndex = re.global ? match.index + match[0].length : lastIndex;
39
72
  }
40
73
  if (NPCG_INCLUDED && match && match.length > 1) {
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var fails = require('./fails');
4
+
5
+ // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
6
+ // so we use an intermediate function.
7
+ function RE(s, f) {
8
+ return RegExp(s, f);
9
+ }
10
+
11
+ exports.UNSUPPORTED_Y = fails(function () {
12
+ // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError
13
+ var re = RE('a', 'y');
14
+ re.lastIndex = 2;
15
+ return re.exec('abcd') != null;
16
+ });
17
+
18
+ exports.BROKEN_CARET = fails(function () {
19
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=773687
20
+ var re = RE('^r', 'gy');
21
+ re.lastIndex = 2;
22
+ return re.exec('str') != null;
23
+ });
@@ -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.5.0',
7
+ version: '3.6.0',
8
8
  mode: IS_PURE ? 'pure' : 'global',
9
9
  copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
10
10
  });
@@ -6,8 +6,10 @@ var defineProperty = require('../internals/object-define-property').f;
6
6
  var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
7
7
  var isRegExp = require('../internals/is-regexp');
8
8
  var getFlags = require('../internals/regexp-flags');
9
+ var stickyHelpers = require('../internals/regexp-sticky-helpers');
9
10
  var redefine = require('../internals/redefine');
10
11
  var fails = require('../internals/fails');
12
+ var setInternalState = require('../internals/internal-state').set;
11
13
  var setSpecies = require('../internals/set-species');
12
14
  var wellKnownSymbol = require('../internals/well-known-symbol');
13
15
 
@@ -20,7 +22,9 @@ var re2 = /a/g;
20
22
  // "new" should create a new object, old webkit bug
21
23
  var CORRECT_NEW = new NativeRegExp(re1) !== re1;
22
24
 
23
- var FORCED = DESCRIPTORS && isForced('RegExp', (!CORRECT_NEW || fails(function () {
25
+ var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y;
26
+
27
+ var FORCED = DESCRIPTORS && isForced('RegExp', (!CORRECT_NEW || UNSUPPORTED_Y || fails(function () {
24
28
  re2[MATCH] = false;
25
29
  // RegExp constructor can alter flags and IsRegExp works correct with @@match
26
30
  return NativeRegExp(re1) != re1 || NativeRegExp(re2) == re2 || NativeRegExp(re1, 'i') != '/a/i';
@@ -33,13 +37,33 @@ if (FORCED) {
33
37
  var thisIsRegExp = this instanceof RegExpWrapper;
34
38
  var patternIsRegExp = isRegExp(pattern);
35
39
  var flagsAreUndefined = flags === undefined;
36
- return !thisIsRegExp && patternIsRegExp && pattern.constructor === RegExpWrapper && flagsAreUndefined ? pattern
37
- : inheritIfRequired(CORRECT_NEW
38
- ? new NativeRegExp(patternIsRegExp && !flagsAreUndefined ? pattern.source : pattern, flags)
39
- : NativeRegExp((patternIsRegExp = pattern instanceof RegExpWrapper)
40
- ? pattern.source
41
- : pattern, patternIsRegExp && flagsAreUndefined ? getFlags.call(pattern) : flags)
42
- , thisIsRegExp ? this : RegExpPrototype, RegExpWrapper);
40
+ var sticky;
41
+
42
+ if (!thisIsRegExp && patternIsRegExp && pattern.constructor === RegExpWrapper && flagsAreUndefined) {
43
+ return pattern;
44
+ }
45
+
46
+ if (CORRECT_NEW) {
47
+ if (patternIsRegExp && !flagsAreUndefined) pattern = pattern.source;
48
+ } else if (pattern instanceof RegExpWrapper) {
49
+ if (flagsAreUndefined) flags = getFlags.call(pattern);
50
+ pattern = pattern.source;
51
+ }
52
+
53
+ if (UNSUPPORTED_Y) {
54
+ sticky = !!flags && flags.indexOf('y') > -1;
55
+ if (sticky) flags = flags.replace(/y/g, '');
56
+ }
57
+
58
+ var result = inheritIfRequired(
59
+ CORRECT_NEW ? new NativeRegExp(pattern, flags) : NativeRegExp(pattern, flags),
60
+ thisIsRegExp ? this : RegExpPrototype,
61
+ RegExpWrapper
62
+ );
63
+
64
+ if (UNSUPPORTED_Y && sticky) setInternalState(result, { sticky: sticky });
65
+
66
+ return result;
43
67
  };
44
68
  var proxy = function (key) {
45
69
  key in RegExpWrapper || defineProperty(RegExpWrapper, key, {
@@ -1,10 +1,11 @@
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
5
 
5
6
  // `RegExp.prototype.flags` getter
6
7
  // https://tc39.github.io/ecma262/#sec-get-regexp.prototype.flags
7
- if (DESCRIPTORS && /./g.flags != 'g') {
8
+ if (DESCRIPTORS && (/./g.flags != 'g' || UNSUPPORTED_Y)) {
8
9
  objectDefinePropertyModule.f(RegExp.prototype, 'flags', {
9
10
  configurable: true,
10
11
  get: regExpFlags
@@ -0,0 +1,21 @@
1
+ var DESCRIPTORS = require('../internals/descriptors');
2
+ var UNSUPPORTED_Y = require('../internals/regexp-sticky-helpers').UNSUPPORTED_Y;
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.sticky` getter
8
+ if (DESCRIPTORS && UNSUPPORTED_Y) {
9
+ defineProperty(RegExp.prototype, 'sticky', {
10
+ configurable: true,
11
+ get: function () {
12
+ if (this === RegExpPrototype) return undefined;
13
+ // We can't use InternalStateModule.getterFor because
14
+ // we don't add metadata for regexps created by a literal.
15
+ if (this instanceof RegExp) {
16
+ return !!getInternalState(this).sticky;
17
+ }
18
+ throw TypeError('Incompatible receiver, RegExp required');
19
+ }
20
+ });
21
+ }
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+ var $ = require('../internals/export');
3
+ var isObject = require('../internals/is-object');
4
+
5
+ var DELEGATES_TO_EXEC = function () {
6
+ var execCalled = false;
7
+ var re = /[ac]/;
8
+ re.exec = function () {
9
+ execCalled = true;
10
+ return /./.exec.apply(this, arguments);
11
+ };
12
+ return re.test('abc') === true && execCalled;
13
+ }();
14
+
15
+ var nativeTest = /./.test;
16
+
17
+ $({ target: 'RegExp', proto: true, forced: !DELEGATES_TO_EXEC }, {
18
+ test: function (str) {
19
+ if (typeof this.exec !== 'function') {
20
+ return nativeTest.call(this, str);
21
+ }
22
+ var result = this.exec(str);
23
+ if (result !== null && !isObject(result)) {
24
+ throw new Error('RegExp exec method returned something other than an Object or null');
25
+ }
26
+ return !!result;
27
+ }
28
+ });
@@ -19,7 +19,7 @@ var maybeToString = function (it) {
19
19
  };
20
20
 
21
21
  // @@replace logic
22
- fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative) {
22
+ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) {
23
23
  return [
24
24
  // `String.prototype.replace` method
25
25
  // https://tc39.github.io/ecma262/#sec-string.prototype.replace
@@ -33,8 +33,10 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, ma
33
33
  // `RegExp.prototype[@@replace]` method
34
34
  // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
35
35
  function (regexp, replaceValue) {
36
- var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
37
- if (res.done) return res.value;
36
+ if (reason.REPLACE_KEEPS_$0 || (typeof replaceValue === 'string' && replaceValue.indexOf('$0') === -1)) {
37
+ var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
38
+ if (res.done) return res.value;
39
+ }
38
40
 
39
41
  var rx = anObject(regexp);
40
42
  var S = String(this);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "core-js",
3
3
  "description": "Standard library",
4
- "version": "3.5.0",
4
+ "version": "3.6.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/zloirock/core-js.git"
@@ -0,0 +1,3 @@
1
+ var parent = require('../../es/regexp/sticky');
2
+
3
+ module.exports = parent;
@@ -0,0 +1,3 @@
1
+ var parent = require('../../es/regexp/test');
2
+
3
+ module.exports = parent;