source: node_modules/@babel/runtime-corejs3/helpers/esm/wrapRegExp.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1import _typeof from "./typeof.js";
2import _WeakMap from "core-js-pure/features/weak-map/index.js";
3import _reduceInstanceProperty from "core-js-pure/features/instance/reduce.js";
4import _Object$keys from "core-js-pure/features/object/keys.js";
5import _Object$create from "core-js-pure/features/object/create.js";
6import _Symbol$replace from "core-js-pure/features/symbol/replace.js";
7import _Array$isArray from "core-js-pure/features/array/is-array.js";
8import _pushInstanceProperty from "core-js-pure/features/instance/push.js";
9import _sliceInstanceProperty from "core-js-pure/features/instance/slice.js";
10import setPrototypeOf from "./setPrototypeOf.js";
11import inherits from "./inherits.js";
12export default function _wrapRegExp() {
13 _wrapRegExp = function _wrapRegExp(e, r) {
14 return new BabelRegExp(e, void 0, r);
15 };
16 var e = RegExp.prototype,
17 r = new _WeakMap();
18 function BabelRegExp(e, t, p) {
19 var o = new RegExp(e, t);
20 return r.set(o, p || r.get(e)), setPrototypeOf(o, BabelRegExp.prototype);
21 }
22 function buildGroups(e, t) {
23 var _context;
24 var p = r.get(t);
25 return _reduceInstanceProperty(_context = _Object$keys(p)).call(_context, function (r, t) {
26 var o = p[t];
27 if ("number" == typeof o) r[t] = e[o];else {
28 for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++;
29 r[t] = e[o[i]];
30 }
31 return r;
32 }, _Object$create(null));
33 }
34 return inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {
35 var t = e.exec.call(this, r);
36 if (t) {
37 t.groups = buildGroups(t, this);
38 var p = t.indices;
39 p && (p.groups = buildGroups(p, this));
40 }
41 return t;
42 }, BabelRegExp.prototype[_Symbol$replace] = function (t, p) {
43 if ("string" == typeof p) {
44 var o = r.get(this);
45 return e[_Symbol$replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) {
46 var t = o[r];
47 return "$" + (_Array$isArray(t) ? t.join("$") : t);
48 }));
49 }
50 if ("function" == typeof p) {
51 var i = this;
52 return e[_Symbol$replace].call(this, t, function () {
53 var _context2;
54 var e = arguments;
55 return "object" != _typeof(e[e.length - 1]) && _pushInstanceProperty(_context2 = e = _sliceInstanceProperty([]).call(e)).call(_context2, buildGroups(e, i)), p.apply(this, e);
56 });
57 }
58 return e[_Symbol$replace].call(this, t, p);
59 }, _wrapRegExp.apply(this, arguments);
60}
Note: See TracBrowser for help on using the repository browser.