source: trip-planner-front/node_modules/core-js/modules/es.string.match-all.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.5 KB
Line 
1'use strict';
2/* eslint-disable es/no-string-prototype-matchall -- safe */
3var $ = require('../internals/export');
4var createIteratorConstructor = require('../internals/create-iterator-constructor');
5var requireObjectCoercible = require('../internals/require-object-coercible');
6var toLength = require('../internals/to-length');
7var toString = require('../internals/to-string');
8var aFunction = require('../internals/a-function');
9var anObject = require('../internals/an-object');
10var classof = require('../internals/classof-raw');
11var isRegExp = require('../internals/is-regexp');
12var getRegExpFlags = require('../internals/regexp-flags');
13var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
14var fails = require('../internals/fails');
15var wellKnownSymbol = require('../internals/well-known-symbol');
16var speciesConstructor = require('../internals/species-constructor');
17var advanceStringIndex = require('../internals/advance-string-index');
18var InternalStateModule = require('../internals/internal-state');
19var IS_PURE = require('../internals/is-pure');
20
21var MATCH_ALL = wellKnownSymbol('matchAll');
22var REGEXP_STRING = 'RegExp String';
23var REGEXP_STRING_ITERATOR = REGEXP_STRING + ' Iterator';
24var setInternalState = InternalStateModule.set;
25var getInternalState = InternalStateModule.getterFor(REGEXP_STRING_ITERATOR);
26var RegExpPrototype = RegExp.prototype;
27var regExpBuiltinExec = RegExpPrototype.exec;
28var nativeMatchAll = ''.matchAll;
29
30var WORKS_WITH_NON_GLOBAL_REGEX = !!nativeMatchAll && !fails(function () {
31 'a'.matchAll(/./);
32});
33
34var regExpExec = function (R, S) {
35 var exec = R.exec;
36 var result;
37 if (typeof exec == 'function') {
38 result = exec.call(R, S);
39 if (typeof result != 'object') throw TypeError('Incorrect exec result');
40 return result;
41 } return regExpBuiltinExec.call(R, S);
42};
43
44// eslint-disable-next-line max-len -- ignore
45var $RegExpStringIterator = createIteratorConstructor(function RegExpStringIterator(regexp, string, global, fullUnicode) {
46 setInternalState(this, {
47 type: REGEXP_STRING_ITERATOR,
48 regexp: regexp,
49 string: string,
50 global: global,
51 unicode: fullUnicode,
52 done: false
53 });
54}, REGEXP_STRING, function next() {
55 var state = getInternalState(this);
56 if (state.done) return { value: undefined, done: true };
57 var R = state.regexp;
58 var S = state.string;
59 var match = regExpExec(R, S);
60 if (match === null) return { value: undefined, done: state.done = true };
61 if (state.global) {
62 if (toString(match[0]) === '') R.lastIndex = advanceStringIndex(S, toLength(R.lastIndex), state.unicode);
63 return { value: match, done: false };
64 }
65 state.done = true;
66 return { value: match, done: false };
67});
68
69var $matchAll = function (string) {
70 var R = anObject(this);
71 var S = toString(string);
72 var C, flagsValue, flags, matcher, global, fullUnicode;
73 C = speciesConstructor(R, RegExp);
74 flagsValue = R.flags;
75 if (flagsValue === undefined && R instanceof RegExp && !('flags' in RegExpPrototype)) {
76 flagsValue = getRegExpFlags.call(R);
77 }
78 flags = flagsValue === undefined ? '' : toString(flagsValue);
79 matcher = new C(C === RegExp ? R.source : R, flags);
80 global = !!~flags.indexOf('g');
81 fullUnicode = !!~flags.indexOf('u');
82 matcher.lastIndex = toLength(R.lastIndex);
83 return new $RegExpStringIterator(matcher, S, global, fullUnicode);
84};
85
86// `String.prototype.matchAll` method
87// https://tc39.es/ecma262/#sec-string.prototype.matchall
88$({ target: 'String', proto: true, forced: WORKS_WITH_NON_GLOBAL_REGEX }, {
89 matchAll: function matchAll(regexp) {
90 var O = requireObjectCoercible(this);
91 var flags, S, matcher, rx;
92 if (regexp != null) {
93 if (isRegExp(regexp)) {
94 flags = toString(requireObjectCoercible('flags' in RegExpPrototype
95 ? regexp.flags
96 : getRegExpFlags.call(regexp)
97 ));
98 if (!~flags.indexOf('g')) throw TypeError('`.matchAll` does not allow non-global regexes');
99 }
100 if (WORKS_WITH_NON_GLOBAL_REGEX) return nativeMatchAll.apply(O, arguments);
101 matcher = regexp[MATCH_ALL];
102 if (matcher === undefined && IS_PURE && classof(regexp) == 'RegExp') matcher = $matchAll;
103 if (matcher != null) return aFunction(matcher).call(regexp, O);
104 } else if (WORKS_WITH_NON_GLOBAL_REGEX) return nativeMatchAll.apply(O, arguments);
105 S = toString(O);
106 rx = new RegExp(regexp, 'g');
107 return IS_PURE ? $matchAll.call(rx, S) : rx[MATCH_ALL](S);
108 }
109});
110
111IS_PURE || MATCH_ALL in RegExpPrototype || createNonEnumerableProperty(RegExpPrototype, MATCH_ALL, $matchAll);
Note: See TracBrowser for help on using the repository browser.