applyDecs.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. var _typeof = require("./typeof.js")["default"];
  2. var setFunctionName = require("./setFunctionName.js");
  3. var toPropertyKey = require("./toPropertyKey.js");
  4. function old_createMetadataMethodsForProperty(e, t, a, r) {
  5. return {
  6. getMetadata: function getMetadata(o) {
  7. old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o);
  8. var i = e[o];
  9. if (void 0 !== i) if (1 === t) {
  10. var n = i["public"];
  11. if (void 0 !== n) return n[a];
  12. } else if (2 === t) {
  13. var l = i["private"];
  14. if (void 0 !== l) return l.get(a);
  15. } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor;
  16. },
  17. setMetadata: function setMetadata(o, i) {
  18. old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o);
  19. var n = e[o];
  20. if (void 0 === n && (n = e[o] = {}), 1 === t) {
  21. var l = n["public"];
  22. void 0 === l && (l = n["public"] = {}), l[a] = i;
  23. } else if (2 === t) {
  24. var s = n.priv;
  25. void 0 === s && (s = n["private"] = new Map()), s.set(a, i);
  26. } else n.constructor = i;
  27. }
  28. };
  29. }
  30. function old_convertMetadataMapToFinal(e, t) {
  31. var a = e[Symbol.metadata || Symbol["for"]("Symbol.metadata")],
  32. r = Object.getOwnPropertySymbols(t);
  33. if (0 !== r.length) {
  34. for (var o = 0; o < r.length; o++) {
  35. var i = r[o],
  36. n = t[i],
  37. l = a ? a[i] : null,
  38. s = n["public"],
  39. c = l ? l["public"] : null;
  40. s && c && Object.setPrototypeOf(s, c);
  41. var d = n["private"];
  42. if (d) {
  43. var u = Array.from(d.values()),
  44. f = l ? l["private"] : null;
  45. f && (u = u.concat(f)), n["private"] = u;
  46. }
  47. l && Object.setPrototypeOf(n, l);
  48. }
  49. a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol["for"]("Symbol.metadata")] = t;
  50. }
  51. }
  52. function old_createAddInitializerMethod(e, t) {
  53. return function (a) {
  54. old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a);
  55. };
  56. }
  57. function old_memberDec(e, t, a, r, o, i, n, l, s) {
  58. var c;
  59. switch (i) {
  60. case 1:
  61. c = "accessor";
  62. break;
  63. case 2:
  64. c = "method";
  65. break;
  66. case 3:
  67. c = "getter";
  68. break;
  69. case 4:
  70. c = "setter";
  71. break;
  72. default:
  73. c = "field";
  74. }
  75. var d,
  76. u,
  77. f = {
  78. kind: c,
  79. name: l ? "#" + t : toPropertyKey(t),
  80. isStatic: n,
  81. isPrivate: l
  82. },
  83. p = {
  84. v: !1
  85. };
  86. if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {
  87. d = 2, u = Symbol(t);
  88. var v = {};
  89. 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {
  90. return a.value;
  91. } : (1 !== i && 3 !== i || (v.get = function () {
  92. return a.get.call(this);
  93. }), 1 !== i && 4 !== i || (v.set = function (e) {
  94. a.set.call(this, e);
  95. })), f.access = v;
  96. } else d = 1, u = t;
  97. try {
  98. return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));
  99. } finally {
  100. p.v = !0;
  101. }
  102. }
  103. function old_assertNotFinished(e, t) {
  104. if (e.v) throw Error("attempted to call " + t + " after decoration was finished");
  105. }
  106. function old_assertMetadataKey(e) {
  107. if ("symbol" != _typeof(e)) throw new TypeError("Metadata keys must be symbols, received: " + e);
  108. }
  109. function old_assertCallable(e, t) {
  110. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  111. }
  112. function old_assertValidReturnValue(e, t) {
  113. var a = _typeof(t);
  114. if (1 === e) {
  115. if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  116. void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer");
  117. } else if ("function" !== a) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  118. }
  119. function old_getInit(e) {
  120. var t;
  121. return null == (t = e.init) && (t = e.initializer) && void 0 !== console && console.warn(".initializer has been renamed to .init as of March 2022"), t;
  122. }
  123. function old_applyMemberDec(e, t, a, r, o, i, n, l, s) {
  124. var c,
  125. d,
  126. u,
  127. f,
  128. p,
  129. v,
  130. y,
  131. h = a[0];
  132. if (n ? (0 === o || 1 === o ? (c = {
  133. get: a[3],
  134. set: a[4]
  135. }, u = "get") : 3 === o ? (c = {
  136. get: a[3]
  137. }, u = "get") : 4 === o ? (c = {
  138. set: a[3]
  139. }, u = "set") : c = {
  140. value: a[3]
  141. }, 0 !== o && (1 === o && setFunctionName(a[4], "#" + r, "set"), setFunctionName(a[3], "#" + r, u))) : 0 !== o && (c = Object.getOwnPropertyDescriptor(t, r)), 1 === o ? f = {
  142. get: c.get,
  143. set: c.set
  144. } : 2 === o ? f = c.value : 3 === o ? f = c.get : 4 === o && (f = c.set), "function" == typeof h) void 0 !== (p = old_memberDec(h, r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? d = p : 1 === o ? (d = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
  145. get: v,
  146. set: y
  147. }) : f = p);else for (var m = h.length - 1; m >= 0; m--) {
  148. var b;
  149. void 0 !== (p = old_memberDec(h[m], r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? b = p : 1 === o ? (b = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
  150. get: v,
  151. set: y
  152. }) : f = p, void 0 !== b && (void 0 === d ? d = b : "function" == typeof d ? d = [d, b] : d.push(b)));
  153. }
  154. if (0 === o || 1 === o) {
  155. if (void 0 === d) d = function d(e, t) {
  156. return t;
  157. };else if ("function" != typeof d) {
  158. var g = d;
  159. d = function d(e, t) {
  160. for (var a = t, r = 0; r < g.length; r++) a = g[r].call(e, a);
  161. return a;
  162. };
  163. } else {
  164. var _ = d;
  165. d = function d(e, t) {
  166. return _.call(e, t);
  167. };
  168. }
  169. e.push(d);
  170. }
  171. 0 !== o && (1 === o ? (c.get = f.get, c.set = f.set) : 2 === o ? c.value = f : 3 === o ? c.get = f : 4 === o && (c.set = f), n ? 1 === o ? (e.push(function (e, t) {
  172. return f.get.call(e, t);
  173. }), e.push(function (e, t) {
  174. return f.set.call(e, t);
  175. })) : 2 === o ? e.push(f) : e.push(function (e, t) {
  176. return f.call(e, t);
  177. }) : Object.defineProperty(t, r, c));
  178. }
  179. function old_applyMemberDecs(e, t, a, r, o) {
  180. for (var i, n, l = new Map(), s = new Map(), c = 0; c < o.length; c++) {
  181. var d = o[c];
  182. if (Array.isArray(d)) {
  183. var u,
  184. f,
  185. p,
  186. v = d[1],
  187. y = d[2],
  188. h = d.length > 3,
  189. m = v >= 5;
  190. if (m ? (u = t, f = r, 0 != (v -= 5) && (p = n = n || [])) : (u = t.prototype, f = a, 0 !== v && (p = i = i || [])), 0 !== v && !h) {
  191. var b = m ? s : l,
  192. g = b.get(y) || 0;
  193. if (!0 === g || 3 === g && 4 !== v || 4 === g && 3 !== v) throw 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: " + y);
  194. !g && v > 2 ? b.set(y, v) : b.set(y, !0);
  195. }
  196. old_applyMemberDec(e, u, d, y, v, m, h, f, p);
  197. }
  198. }
  199. old_pushInitializers(e, i), old_pushInitializers(e, n);
  200. }
  201. function old_pushInitializers(e, t) {
  202. t && e.push(function (e) {
  203. for (var a = 0; a < t.length; a++) t[a].call(e);
  204. return e;
  205. });
  206. }
  207. function old_applyClassDecs(e, t, a, r) {
  208. if (r.length > 0) {
  209. for (var o = [], i = t, n = t.name, l = r.length - 1; l >= 0; l--) {
  210. var s = {
  211. v: !1
  212. };
  213. try {
  214. var c = Object.assign({
  215. kind: "class",
  216. name: n,
  217. addInitializer: old_createAddInitializerMethod(o, s)
  218. }, old_createMetadataMethodsForProperty(a, 0, n, s)),
  219. d = r[l](i, c);
  220. } finally {
  221. s.v = !0;
  222. }
  223. void 0 !== d && (old_assertValidReturnValue(10, d), i = d);
  224. }
  225. e.push(i, function () {
  226. for (var e = 0; e < o.length; e++) o[e].call(i);
  227. });
  228. }
  229. }
  230. function applyDecs(e, t, a) {
  231. var r = [],
  232. o = {},
  233. i = {};
  234. return old_applyMemberDecs(r, e, i, o, t), old_convertMetadataMapToFinal(e.prototype, i), old_applyClassDecs(r, e, o, a), old_convertMetadataMapToFinal(e, o), r;
  235. }
  236. module.exports = applyDecs, module.exports.__esModule = true, module.exports["default"] = module.exports;