web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

  1. var _typeof = require("@babel/runtime/helpers/typeof")["default"];
  2. var wrapNativeSuper = require("./wrapNativeSuper.js");
  3. var getPrototypeOf = require("./getPrototypeOf.js");
  4. var possibleConstructorReturn = require("./possibleConstructorReturn.js");
  5. var inherits = require("./inherits.js");
  6. function _wrapRegExp(re, groups) {
  7. module.exports = _wrapRegExp = function _wrapRegExp(re, groups) {
  8. return new BabelRegExp(re, undefined, groups);
  9. };
  10. module.exports["default"] = module.exports, module.exports.__esModule = true;
  11. var _RegExp = wrapNativeSuper(RegExp);
  12. var _super = RegExp.prototype;
  13. var _groups = new WeakMap();
  14. function BabelRegExp(re, flags, groups) {
  15. var _this = _RegExp.call(this, re, flags);
  16. _groups.set(_this, groups || _groups.get(re));
  17. return _this;
  18. }
  19. inherits(BabelRegExp, _RegExp);
  20. BabelRegExp.prototype.exec = function (str) {
  21. var result = _super.exec.call(this, str);
  22. if (result) result.groups = buildGroups(result, this);
  23. return result;
  24. };
  25. BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
  26. if (typeof substitution === "string") {
  27. var groups = _groups.get(this);
  28. return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
  29. return "$" + groups[name];
  30. }));
  31. } else if (typeof substitution === "function") {
  32. var _this = this;
  33. return _super[Symbol.replace].call(this, str, function () {
  34. var args = [];
  35. args.push.apply(args, arguments);
  36. if (_typeof(args[args.length - 1]) !== "object") {
  37. args.push(buildGroups(args, _this));
  38. }
  39. return substitution.apply(this, args);
  40. });
  41. } else {
  42. return _super[Symbol.replace].call(this, str, substitution);
  43. }
  44. };
  45. function buildGroups(result, re) {
  46. var g = _groups.get(re);
  47. return Object.keys(g).reduce(function (groups, name) {
  48. groups[name] = result[g[name]];
  49. return groups;
  50. }, Object.create(null));
  51. }
  52. return _wrapRegExp.apply(this, arguments);
  53. }
  54. module.exports = _wrapRegExp;
  55. module.exports["default"] = module.exports, module.exports.__esModule = true;