_wrap_native_super.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _wrapNativeSuper;
  6. var _constructMjs = _interopRequireDefault(require("./_construct.js"));
  7. var _isNativeFunctionMjs = _interopRequireDefault(require("./_is_native_function.js"));
  8. var _getPrototypeOfMjs = _interopRequireDefault(require("./_get_prototype_of.js"));
  9. var _setPrototypeOfMjs = _interopRequireDefault(require("./_set_prototype_of.js"));
  10. function _wrapNativeSuper(Class) {
  11. return wrapNativeSuper(Class);
  12. }
  13. function _interopRequireDefault(obj) {
  14. return obj && obj.__esModule ? obj : {
  15. default: obj
  16. };
  17. }
  18. function wrapNativeSuper(Class1) {
  19. var _cache = typeof Map === "function" ? new Map() : undefined;
  20. wrapNativeSuper = function wrapNativeSuper(Class) {
  21. if (Class === null || !(0, _isNativeFunctionMjs).default(Class)) return Class;
  22. if (typeof Class !== "function") {
  23. throw new TypeError("Super expression must either be null or a function");
  24. }
  25. if (typeof _cache !== "undefined") {
  26. if (_cache.has(Class)) return _cache.get(Class);
  27. _cache.set(Class, Wrapper);
  28. }
  29. function Wrapper() {
  30. return (0, _constructMjs).default(Class, arguments, (0, _getPrototypeOfMjs).default(this).constructor);
  31. }
  32. Wrapper.prototype = Object.create(Class.prototype, {
  33. constructor: {
  34. value: Wrapper,
  35. enumerable: false,
  36. writable: true,
  37. configurable: true
  38. }
  39. });
  40. return (0, _setPrototypeOfMjs).default(Wrapper, Class);
  41. };
  42. return wrapNativeSuper(Class1);
  43. }