applyDecs2203.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. var _typeof = require("./typeof.js")["default"];
  2. function applyDecs2203Factory() {
  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 pushInitializers(ret, initializers) {
  132. initializers && ret.push(function (instance) {
  133. for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
  134. return instance;
  135. });
  136. }
  137. return function (targetClass, memberDecs, classDecs) {
  138. var ret = [];
  139. return function (ret, Class, decInfos) {
  140. for (var protoInitializers, staticInitializers, existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {
  141. var decInfo = decInfos[i];
  142. if (Array.isArray(decInfo)) {
  143. var base,
  144. initializers,
  145. kind = decInfo[1],
  146. name = decInfo[2],
  147. isPrivate = decInfo.length > 3,
  148. isStatic = kind >= 5;
  149. if (isStatic ? (base = Class, 0 != (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {
  150. var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
  151. existingKind = existingNonFields.get(name) || 0;
  152. 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);
  153. !existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
  154. }
  155. applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);
  156. }
  157. }
  158. pushInitializers(ret, protoInitializers), pushInitializers(ret, staticInitializers);
  159. }(ret, targetClass, memberDecs), function (ret, targetClass, classDecs) {
  160. if (classDecs.length > 0) {
  161. for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {
  162. var decoratorFinishedRef = {
  163. v: !1
  164. };
  165. try {
  166. var nextNewClass = classDecs[i](newClass, {
  167. kind: "class",
  168. name: name,
  169. addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)
  170. });
  171. } finally {
  172. decoratorFinishedRef.v = !0;
  173. }
  174. void 0 !== nextNewClass && (assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);
  175. }
  176. ret.push(newClass, function () {
  177. for (var i = 0; i < initializers.length; i++) initializers[i].call(newClass);
  178. });
  179. }
  180. }(ret, targetClass, classDecs), ret;
  181. };
  182. }
  183. var applyDecs2203Impl;
  184. function applyDecs2203(targetClass, memberDecs, classDecs) {
  185. return (applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory())(targetClass, memberDecs, classDecs);
  186. }
  187. module.exports = applyDecs2203, module.exports.__esModule = true, module.exports["default"] = module.exports;