applyDecs2203R.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var _typeof = require("./typeof.js")["default"];
  2. function applyDecs2203RFactory() {
  3. function createAddInitializerMethod(initializers, decoratorFinishedRef) {
  4. return function (initializer) {
  5. !function (decoratorFinishedRef, fnName) {
  6. if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
  7. }(decoratorFinishedRef, "addInitializer"), assertCallable(initializer, "An initializer"), initializers.push(initializer);
  8. };
  9. }
  10. function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value) {
  11. var kindStr;
  12. switch (kind) {
  13. case 1:
  14. kindStr = "accessor";
  15. break;
  16. case 2:
  17. kindStr = "method";
  18. break;
  19. case 3:
  20. kindStr = "getter";
  21. break;
  22. case 4:
  23. kindStr = "setter";
  24. break;
  25. default:
  26. kindStr = "field";
  27. }
  28. var get,
  29. set,
  30. ctx = {
  31. kind: kindStr,
  32. name: isPrivate ? "#" + name : name,
  33. "static": isStatic,
  34. "private": isPrivate
  35. },
  36. decoratorFinishedRef = {
  37. v: !1
  38. };
  39. 0 !== kind && (ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef)), 0 === kind ? isPrivate ? (get = desc.get, set = desc.set) : (get = function get() {
  40. return this[name];
  41. }, set = function set(v) {
  42. this[name] = v;
  43. }) : 2 === kind ? get = function get() {
  44. return desc.value;
  45. } : (1 !== kind && 3 !== kind || (get = function get() {
  46. return desc.get.call(this);
  47. }), 1 !== kind && 4 !== kind || (set = function set(v) {
  48. desc.set.call(this, v);
  49. })), ctx.access = get && set ? {
  50. get: get,
  51. set: set
  52. } : get ? {
  53. get: get
  54. } : {
  55. set: set
  56. };
  57. try {
  58. return dec(value, ctx);
  59. } finally {
  60. decoratorFinishedRef.v = !0;
  61. }
  62. }
  63. function assertCallable(fn, hint) {
  64. if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
  65. }
  66. function assertValidReturnValue(kind, value) {
  67. var type = _typeof(value);
  68. if (1 === kind) {
  69. if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  70. void 0 !== value.get && assertCallable(value.get, "accessor.get"), void 0 !== value.set && assertCallable(value.set, "accessor.set"), void 0 !== value.init && assertCallable(value.init, "accessor.init");
  71. } else if ("function" !== type) {
  72. var hint;
  73. throw hint = 0 === kind ? "field" : 10 === kind ? "class" : "method", new TypeError(hint + " decorators must return a function or void 0");
  74. }
  75. }
  76. function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers) {
  77. var desc,
  78. init,
  79. value,
  80. newValue,
  81. get,
  82. set,
  83. decs = decInfo[0];
  84. if (isPrivate ? desc = 0 === kind || 1 === kind ? {
  85. get: decInfo[3],
  86. set: decInfo[4]
  87. } : 3 === kind ? {
  88. get: decInfo[3]
  89. } : 4 === kind ? {
  90. set: decInfo[3]
  91. } : {
  92. value: decInfo[3]
  93. } : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {
  94. get: desc.get,
  95. set: desc.set
  96. } : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set), "function" == typeof decs) void 0 !== (newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, value)) && (assertValidReturnValue(kind, newValue), 0 === kind ? init = newValue : 1 === kind ? (init = newValue.init, get = newValue.get || value.get, set = newValue.set || value.set, value = {
  97. get: get,
  98. set: set
  99. }) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {
  100. var newInit;
  101. if (void 0 !== (newValue = memberDec(decs[i], name, desc, initializers, kind, isStatic, isPrivate, value))) assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = newValue.init, get = newValue.get || value.get, set = newValue.set || value.set, value = {
  102. get: get,
  103. set: set
  104. }) : value = newValue, void 0 !== newInit && (void 0 === init ? init = newInit : "function" == typeof init ? init = [init, newInit] : init.push(newInit));
  105. }
  106. if (0 === kind || 1 === kind) {
  107. if (void 0 === init) init = function init(instance, _init) {
  108. return _init;
  109. };else if ("function" != typeof init) {
  110. var ownInitializers = init;
  111. init = function init(instance, _init2) {
  112. for (var value = _init2, i = 0; i < ownInitializers.length; i++) value = ownInitializers[i].call(instance, value);
  113. return value;
  114. };
  115. } else {
  116. var originalInitializer = init;
  117. init = function init(instance, _init3) {
  118. return originalInitializer.call(instance, _init3);
  119. };
  120. }
  121. ret.push(init);
  122. }
  123. 0 !== kind && (1 === kind ? (desc.get = value.get, desc.set = value.set) : 2 === kind ? desc.value = value : 3 === kind ? desc.get = value : 4 === kind && (desc.set = value), isPrivate ? 1 === kind ? (ret.push(function (instance, args) {
  124. return value.get.call(instance, args);
  125. }), ret.push(function (instance, args) {
  126. return value.set.call(instance, args);
  127. })) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {
  128. return value.call(instance, args);
  129. }) : Object.defineProperty(base, name, desc));
  130. }
  131. function applyMemberDecs(Class, decInfos) {
  132. for (var protoInitializers, staticInitializers, ret = [], existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {
  133. var decInfo = decInfos[i];
  134. if (Array.isArray(decInfo)) {
  135. var base,
  136. initializers,
  137. kind = decInfo[1],
  138. name = decInfo[2],
  139. isPrivate = decInfo.length > 3,
  140. isStatic = kind >= 5;
  141. if (isStatic ? (base = Class, 0 !== (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {
  142. var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
  143. existingKind = existingNonFields.get(name) || 0;
  144. if (!0 === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
  145. !existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
  146. }
  147. applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);
  148. }
  149. }
  150. return pushInitializers(ret, protoInitializers), pushInitializers(ret, staticInitializers), ret;
  151. }
  152. function pushInitializers(ret, initializers) {
  153. initializers && ret.push(function (instance) {
  154. for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
  155. return instance;
  156. });
  157. }
  158. return function (targetClass, memberDecs, classDecs) {
  159. return {
  160. e: applyMemberDecs(targetClass, memberDecs),
  161. get c() {
  162. return function (targetClass, classDecs) {
  163. if (classDecs.length > 0) {
  164. for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {
  165. var decoratorFinishedRef = {
  166. v: !1
  167. };
  168. try {
  169. var nextNewClass = classDecs[i](newClass, {
  170. kind: "class",
  171. name: name,
  172. addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)
  173. });
  174. } finally {
  175. decoratorFinishedRef.v = !0;
  176. }
  177. void 0 !== nextNewClass && (assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);
  178. }
  179. return [newClass, function () {
  180. for (var i = 0; i < initializers.length; i++) initializers[i].call(newClass);
  181. }];
  182. }
  183. }(targetClass, classDecs);
  184. }
  185. };
  186. };
  187. }
  188. function applyDecs2203R(targetClass, memberDecs, classDecs) {
  189. return (module.exports = applyDecs2203R = applyDecs2203RFactory(), module.exports.__esModule = true, module.exports["default"] = module.exports)(targetClass, memberDecs, classDecs);
  190. }
  191. module.exports = applyDecs2203R, module.exports.__esModule = true, module.exports["default"] = module.exports;