applyDecs2305.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import _typeof from "./typeof.js";
  2. import checkInRHS from "./checkInRHS.js";
  3. function createAddInitializerMethod(e, t) {
  4. return function (r) {
  5. assertNotFinished(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r);
  6. };
  7. }
  8. function assertInstanceIfPrivate(e, t) {
  9. if (!e(t)) throw new TypeError("Attempted to access private element on non-instance");
  10. }
  11. function memberDec(e, t, r, a, n, i, s, o, c, l, u) {
  12. var f;
  13. switch (i) {
  14. case 1:
  15. f = "accessor";
  16. break;
  17. case 2:
  18. f = "method";
  19. break;
  20. case 3:
  21. f = "getter";
  22. break;
  23. case 4:
  24. f = "setter";
  25. break;
  26. default:
  27. f = "field";
  28. }
  29. var d,
  30. p,
  31. h = {
  32. kind: f,
  33. name: o ? "#" + r : r,
  34. "static": s,
  35. "private": o,
  36. metadata: u
  37. },
  38. v = {
  39. v: !1
  40. };
  41. if (0 !== i && (h.addInitializer = createAddInitializerMethod(n, v)), o || 0 !== i && 2 !== i) {
  42. if (2 === i) d = function d(e) {
  43. return assertInstanceIfPrivate(l, e), a.value;
  44. };else {
  45. var y = 0 === i || 1 === i;
  46. (y || 3 === i) && (d = o ? function (e) {
  47. return assertInstanceIfPrivate(l, e), a.get.call(e);
  48. } : function (e) {
  49. return a.get.call(e);
  50. }), (y || 4 === i) && (p = o ? function (e, t) {
  51. assertInstanceIfPrivate(l, e), a.set.call(e, t);
  52. } : function (e, t) {
  53. a.set.call(e, t);
  54. });
  55. }
  56. } else d = function d(e) {
  57. return e[r];
  58. }, 0 === i && (p = function p(e, t) {
  59. e[r] = t;
  60. });
  61. var m = o ? l.bind() : function (e) {
  62. return r in e;
  63. };
  64. h.access = d && p ? {
  65. get: d,
  66. set: p,
  67. has: m
  68. } : d ? {
  69. get: d,
  70. has: m
  71. } : {
  72. set: p,
  73. has: m
  74. };
  75. try {
  76. return e.call(t, c, h);
  77. } finally {
  78. v.v = !0;
  79. }
  80. }
  81. function assertNotFinished(e, t) {
  82. if (e.v) throw new Error("attempted to call " + t + " after decoration was finished");
  83. }
  84. function assertCallable(e, t) {
  85. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  86. }
  87. function assertValidReturnValue(e, t) {
  88. var r = _typeof(t);
  89. if (1 === e) {
  90. if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  91. void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
  92. } else if ("function" !== r) {
  93. var a;
  94. throw a = 0 === e ? "field" : 5 === e ? "class" : "method", new TypeError(a + " decorators must return a function or void 0");
  95. }
  96. }
  97. function curryThis1(e) {
  98. return function () {
  99. return e(this);
  100. };
  101. }
  102. function curryThis2(e) {
  103. return function (t) {
  104. e(this, t);
  105. };
  106. }
  107. function applyMemberDec(e, t, r, a, n, i, s, o, c, l, u) {
  108. var f,
  109. d,
  110. p,
  111. h,
  112. v,
  113. y,
  114. m = r[0];
  115. a || Array.isArray(m) || (m = [m]), o ? f = 0 === i || 1 === i ? {
  116. get: curryThis1(r[3]),
  117. set: curryThis2(r[4])
  118. } : 3 === i ? {
  119. get: r[3]
  120. } : 4 === i ? {
  121. set: r[3]
  122. } : {
  123. value: r[3]
  124. } : 0 !== i && (f = Object.getOwnPropertyDescriptor(t, n)), 1 === i ? p = {
  125. get: f.get,
  126. set: f.set
  127. } : 2 === i ? p = f.value : 3 === i ? p = f.get : 4 === i && (p = f.set);
  128. for (var g = a ? 2 : 1, b = m.length - 1; b >= 0; b -= g) {
  129. var I;
  130. if (void 0 !== (h = memberDec(m[b], a ? m[b - 1] : void 0, n, f, c, i, s, o, p, l, u))) assertValidReturnValue(i, h), 0 === i ? I = h : 1 === i ? (I = h.init, v = h.get || p.get, y = h.set || p.set, p = {
  131. get: v,
  132. set: y
  133. }) : p = h, void 0 !== I && (void 0 === d ? d = I : "function" == typeof d ? d = [d, I] : d.push(I));
  134. }
  135. if (0 === i || 1 === i) {
  136. if (void 0 === d) d = function d(e, t) {
  137. return t;
  138. };else if ("function" != typeof d) {
  139. var w = d;
  140. d = function d(e, t) {
  141. for (var r = t, a = w.length - 1; a >= 0; a--) r = w[a].call(e, r);
  142. return r;
  143. };
  144. } else {
  145. var M = d;
  146. d = function d(e, t) {
  147. return M.call(e, t);
  148. };
  149. }
  150. e.push(d);
  151. }
  152. 0 !== i && (1 === i ? (f.get = p.get, f.set = p.set) : 2 === i ? f.value = p : 3 === i ? f.get = p : 4 === i && (f.set = p), o ? 1 === i ? (e.push(function (e, t) {
  153. return p.get.call(e, t);
  154. }), e.push(function (e, t) {
  155. return p.set.call(e, t);
  156. })) : 2 === i ? e.push(p) : e.push(function (e, t) {
  157. return p.call(e, t);
  158. }) : Object.defineProperty(t, n, f));
  159. }
  160. function applyMemberDecs(e, t, r, a) {
  161. for (var n, i, s, o = [], c = new Map(), l = new Map(), u = 0; u < t.length; u++) {
  162. var f = t[u];
  163. if (Array.isArray(f)) {
  164. var d,
  165. p,
  166. h = f[1],
  167. v = f[2],
  168. y = f.length > 3,
  169. m = 16 & h,
  170. g = !!(8 & h),
  171. b = r;
  172. if (h &= 7, g ? (d = e, 0 !== h && (p = i = i || []), y && !s && (s = function s(t) {
  173. return checkInRHS(t) === e;
  174. }), b = s) : (d = e.prototype, 0 !== h && (p = n = n || [])), 0 !== h && !y) {
  175. var I = g ? l : c,
  176. w = I.get(v) || 0;
  177. if (!0 === w || 3 === w && 4 !== h || 4 === w && 3 !== h) 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: " + v);
  178. I.set(v, !(!w && h > 2) || h);
  179. }
  180. applyMemberDec(o, d, f, m, v, h, g, y, p, b, a);
  181. }
  182. }
  183. return pushInitializers(o, n), pushInitializers(o, i), o;
  184. }
  185. function pushInitializers(e, t) {
  186. t && e.push(function (e) {
  187. for (var r = 0; r < t.length; r++) t[r].call(e);
  188. return e;
  189. });
  190. }
  191. function applyClassDecs(e, t, r, a) {
  192. if (t.length) {
  193. for (var n = [], i = e, s = e.name, o = r ? 2 : 1, c = t.length - 1; c >= 0; c -= o) {
  194. var l = {
  195. v: !1
  196. };
  197. try {
  198. var u = t[c].call(r ? t[c - 1] : void 0, i, {
  199. kind: "class",
  200. name: s,
  201. addInitializer: createAddInitializerMethod(n, l),
  202. metadata: a
  203. });
  204. } finally {
  205. l.v = !0;
  206. }
  207. void 0 !== u && (assertValidReturnValue(5, u), i = u);
  208. }
  209. return [defineMetadata(i, a), function () {
  210. for (var e = 0; e < n.length; e++) n[e].call(i);
  211. }];
  212. }
  213. }
  214. function defineMetadata(e, t) {
  215. return Object.defineProperty(e, Symbol.metadata || Symbol["for"]("Symbol.metadata"), {
  216. configurable: !0,
  217. enumerable: !0,
  218. value: t
  219. });
  220. }
  221. export default function applyDecs2305(e, t, r, a, n, i) {
  222. if (arguments.length >= 6) var s = i[Symbol.metadata || Symbol["for"]("Symbol.metadata")];
  223. var o = Object.create(void 0 === s ? null : s),
  224. c = applyMemberDecs(e, t, n, o);
  225. return r.length || defineMetadata(e, o), {
  226. e: c,
  227. get c() {
  228. return applyClassDecs(e, r, a, o);
  229. }
  230. };
  231. }