source: trip-planner-front/node_modules/@babel/runtime/helpers/wrapRegExp.js@ 59329aa

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

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1var _typeof = require("@babel/runtime/helpers/typeof")["default"];
2
3var setPrototypeOf = require("./setPrototypeOf.js");
4
5var inherits = require("./inherits.js");
6
7function _wrapRegExp() {
8 module.exports = _wrapRegExp = function _wrapRegExp(re, groups) {
9 return new BabelRegExp(re, undefined, groups);
10 };
11
12 module.exports["default"] = module.exports, module.exports.__esModule = true;
13 var _super = RegExp.prototype;
14
15 var _groups = new WeakMap();
16
17 function BabelRegExp(re, flags, groups) {
18 var _this = new RegExp(re, flags);
19
20 _groups.set(_this, groups || _groups.get(re));
21
22 return setPrototypeOf(_this, BabelRegExp.prototype);
23 }
24
25 inherits(BabelRegExp, RegExp);
26
27 BabelRegExp.prototype.exec = function (str) {
28 var result = _super.exec.call(this, str);
29
30 if (result) result.groups = buildGroups(result, this);
31 return result;
32 };
33
34 BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
35 if (typeof substitution === "string") {
36 var groups = _groups.get(this);
37
38 return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
39 return "$" + groups[name];
40 }));
41 } else if (typeof substitution === "function") {
42 var _this = this;
43
44 return _super[Symbol.replace].call(this, str, function () {
45 var args = arguments;
46
47 if (_typeof(args[args.length - 1]) !== "object") {
48 args = [].slice.call(args);
49 args.push(buildGroups(args, _this));
50 }
51
52 return substitution.apply(this, args);
53 });
54 } else {
55 return _super[Symbol.replace].call(this, str, substitution);
56 }
57 };
58
59 function buildGroups(result, re) {
60 var g = _groups.get(re);
61
62 return Object.keys(g).reduce(function (groups, name) {
63 groups[name] = result[g[name]];
64 return groups;
65 }, Object.create(null));
66 }
67
68 return _wrapRegExp.apply(this, arguments);
69}
70
71module.exports = _wrapRegExp;
72module.exports["default"] = module.exports, module.exports.__esModule = true;
Note: See TracBrowser for help on using the repository browser.