.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / modules / es.string.match.js
1 'use strict';
2 var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
3 var anObject = require('../internals/an-object');
4 var toLength = require('../internals/to-length');
5 var requireObjectCoercible = require('../internals/require-object-coercible');
6 var advanceStringIndex = require('../internals/advance-string-index');
7 var regExpExec = require('../internals/regexp-exec-abstract');
8
9 // @@match logic
10 fixRegExpWellKnownSymbolLogic('match', 1, function (MATCH, nativeMatch, maybeCallNative) {
11   return [
12     // `String.prototype.match` method
13     // https://tc39.es/ecma262/#sec-string.prototype.match
14     function match(regexp) {
15       var O = requireObjectCoercible(this);
16       var matcher = regexp == undefined ? undefined : regexp[MATCH];
17       return matcher !== undefined ? matcher.call(regexp, O) : new RegExp(regexp)[MATCH](String(O));
18     },
19     // `RegExp.prototype[@@match]` method
20     // https://tc39.es/ecma262/#sec-regexp.prototype-@@match
21     function (regexp) {
22       var res = maybeCallNative(nativeMatch, regexp, this);
23       if (res.done) return res.value;
24
25       var rx = anObject(regexp);
26       var S = String(this);
27
28       if (!rx.global) return regExpExec(rx, S);
29
30       var fullUnicode = rx.unicode;
31       rx.lastIndex = 0;
32       var A = [];
33       var n = 0;
34       var result;
35       while ((result = regExpExec(rx, S)) !== null) {
36         var matchStr = String(result[0]);
37         A[n] = matchStr;
38         if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
39         n++;
40       }
41       return n === 0 ? null : A;
42     }
43   ];
44 });