massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / fix-regexp-well-known-symbol-logic.js
1 'use strict';
2 // TODO: Remove from `core-js@4` since it's moved to entry points
3 require('../modules/es.regexp.exec');
4 var uncurryThis = require('../internals/function-uncurry-this');
5 var redefine = require('../internals/redefine');
6 var regexpExec = require('../internals/regexp-exec');
7 var fails = require('../internals/fails');
8 var wellKnownSymbol = require('../internals/well-known-symbol');
9 var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
10
11 var SPECIES = wellKnownSymbol('species');
12 var RegExpPrototype = RegExp.prototype;
13
14 module.exports = function (KEY, exec, FORCED, SHAM) {
15   var SYMBOL = wellKnownSymbol(KEY);
16
17   var DELEGATES_TO_SYMBOL = !fails(function () {
18     // String methods call symbol-named RegEp methods
19     var O = {};
20     O[SYMBOL] = function () { return 7; };
21     return ''[KEY](O) != 7;
22   });
23
24   var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () {
25     // Symbol-named RegExp methods call .exec
26     var execCalled = false;
27     var re = /a/;
28
29     if (KEY === 'split') {
30       // We can't use real regex here since it causes deoptimization
31       // and serious performance degradation in V8
32       // https://github.com/zloirock/core-js/issues/306
33       re = {};
34       // RegExp[@@split] doesn't call the regex's exec method, but first creates
35       // a new one. We need to return the patched regex when creating the new one.
36       re.constructor = {};
37       re.constructor[SPECIES] = function () { return re; };
38       re.flags = '';
39       re[SYMBOL] = /./[SYMBOL];
40     }
41
42     re.exec = function () { execCalled = true; return null; };
43
44     re[SYMBOL]('');
45     return !execCalled;
46   });
47
48   if (
49     !DELEGATES_TO_SYMBOL ||
50     !DELEGATES_TO_EXEC ||
51     FORCED
52   ) {
53     var uncurriedNativeRegExpMethod = uncurryThis(/./[SYMBOL]);
54     var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
55       var uncurriedNativeMethod = uncurryThis(nativeMethod);
56       var $exec = regexp.exec;
57       if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
58         if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
59           // The native String method already delegates to @@method (this
60           // polyfilled function), leasing to infinite recursion.
61           // We avoid it by directly calling the native @@method method.
62           return { done: true, value: uncurriedNativeRegExpMethod(regexp, str, arg2) };
63         }
64         return { done: true, value: uncurriedNativeMethod(str, regexp, arg2) };
65       }
66       return { done: false };
67     });
68
69     redefine(String.prototype, KEY, methods[0]);
70     redefine(RegExpPrototype, SYMBOL, methods[1]);
71   }
72
73   if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
74 };