1 | var _typeof = require("./typeof.js")["default"];
|
2 | var _Map = require("@babel/runtime-corejs2/core-js/map");
|
3 | var _Symbol = require("@babel/runtime-corejs2/core-js/symbol");
|
4 | var _Symbol$for = require("@babel/runtime-corejs2/core-js/symbol/for");
|
5 | var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
6 | var _Object$setPrototypeOf = require("@babel/runtime-corejs2/core-js/object/set-prototype-of");
|
7 | var _Array$from = require("@babel/runtime-corejs2/core-js/array/from");
|
8 | var _Object$assign = require("@babel/runtime-corejs2/core-js/object/assign");
|
9 | var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
10 | var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
11 | var _Array$isArray = require("@babel/runtime-corejs2/core-js/array/is-array");
|
12 | function old_createMetadataMethodsForProperty(metadataMap, kind, property, decoratorFinishedRef) {
|
13 | return {
|
14 | getMetadata: function getMetadata(key) {
|
15 | old_assertNotFinished(decoratorFinishedRef, "getMetadata"), old_assertMetadataKey(key);
|
16 | var metadataForKey = metadataMap[key];
|
17 | if (void 0 !== metadataForKey) if (1 === kind) {
|
18 | var pub = metadataForKey["public"];
|
19 | if (void 0 !== pub) return pub[property];
|
20 | } else if (2 === kind) {
|
21 | var priv = metadataForKey["private"];
|
22 | if (void 0 !== priv) return priv.get(property);
|
23 | } else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) return metadataForKey.constructor;
|
24 | },
|
25 | setMetadata: function setMetadata(key, value) {
|
26 | old_assertNotFinished(decoratorFinishedRef, "setMetadata"), old_assertMetadataKey(key);
|
27 | var metadataForKey = metadataMap[key];
|
28 | if (void 0 === metadataForKey && (metadataForKey = metadataMap[key] = {}), 1 === kind) {
|
29 | var pub = metadataForKey["public"];
|
30 | void 0 === pub && (pub = metadataForKey["public"] = {}), pub[property] = value;
|
31 | } else if (2 === kind) {
|
32 | var priv = metadataForKey.priv;
|
33 | void 0 === priv && (priv = metadataForKey["private"] = new _Map()), priv.set(property, value);
|
34 | } else metadataForKey.constructor = value;
|
35 | }
|
36 | };
|
37 | }
|
38 | function old_convertMetadataMapToFinal(obj, metadataMap) {
|
39 | var parentMetadataMap = obj[_Symbol.metadata || _Symbol$for("Symbol.metadata")],
|
40 | metadataKeys = _Object$getOwnPropertySymbols(metadataMap);
|
41 | if (0 !== metadataKeys.length) {
|
42 | for (var i = 0; i < metadataKeys.length; i++) {
|
43 | var key = metadataKeys[i],
|
44 | metaForKey = metadataMap[key],
|
45 | parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null,
|
46 | pub = metaForKey["public"],
|
47 | parentPub = parentMetaForKey ? parentMetaForKey["public"] : null;
|
48 | pub && parentPub && _Object$setPrototypeOf(pub, parentPub);
|
49 | var priv = metaForKey["private"];
|
50 | if (priv) {
|
51 | var privArr = _Array$from(priv.values()),
|
52 | parentPriv = parentMetaForKey ? parentMetaForKey["private"] : null;
|
53 | parentPriv && (privArr = privArr.concat(parentPriv)), metaForKey["private"] = privArr;
|
54 | }
|
55 | parentMetaForKey && _Object$setPrototypeOf(metaForKey, parentMetaForKey);
|
56 | }
|
57 | parentMetadataMap && _Object$setPrototypeOf(metadataMap, parentMetadataMap), obj[_Symbol.metadata || _Symbol$for("Symbol.metadata")] = metadataMap;
|
58 | }
|
59 | }
|
60 | function old_createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
61 | return function (initializer) {
|
62 | old_assertNotFinished(decoratorFinishedRef, "addInitializer"), old_assertCallable(initializer, "An initializer"), initializers.push(initializer);
|
63 | };
|
64 | }
|
65 | function old_memberDec(dec, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value) {
|
66 | var kindStr;
|
67 | switch (kind) {
|
68 | case 1:
|
69 | kindStr = "accessor";
|
70 | break;
|
71 | case 2:
|
72 | kindStr = "method";
|
73 | break;
|
74 | case 3:
|
75 | kindStr = "getter";
|
76 | break;
|
77 | case 4:
|
78 | kindStr = "setter";
|
79 | break;
|
80 | default:
|
81 | kindStr = "field";
|
82 | }
|
83 | var metadataKind,
|
84 | metadataName,
|
85 | ctx = {
|
86 | kind: kindStr,
|
87 | name: isPrivate ? "#" + name : name,
|
88 | isStatic: isStatic,
|
89 | isPrivate: isPrivate
|
90 | },
|
91 | decoratorFinishedRef = {
|
92 | v: !1
|
93 | };
|
94 | if (0 !== kind && (ctx.addInitializer = old_createAddInitializerMethod(initializers, decoratorFinishedRef)), isPrivate) {
|
95 | metadataKind = 2, metadataName = _Symbol(name);
|
96 | var access = {};
|
97 | 0 === kind ? (access.get = desc.get, access.set = desc.set) : 2 === kind ? access.get = function () {
|
98 | return desc.value;
|
99 | } : (1 !== kind && 3 !== kind || (access.get = function () {
|
100 | return desc.get.call(this);
|
101 | }), 1 !== kind && 4 !== kind || (access.set = function (v) {
|
102 | desc.set.call(this, v);
|
103 | })), ctx.access = access;
|
104 | } else metadataKind = 1, metadataName = name;
|
105 | try {
|
106 | return dec(value, _Object$assign(ctx, old_createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName, decoratorFinishedRef)));
|
107 | } finally {
|
108 | decoratorFinishedRef.v = !0;
|
109 | }
|
110 | }
|
111 | function old_assertNotFinished(decoratorFinishedRef, fnName) {
|
112 | if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
113 | }
|
114 | function old_assertMetadataKey(key) {
|
115 | if ("symbol" != _typeof(key)) throw new TypeError("Metadata keys must be symbols, received: " + key);
|
116 | }
|
117 | function old_assertCallable(fn, hint) {
|
118 | if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
|
119 | }
|
120 | function old_assertValidReturnValue(kind, value) {
|
121 | var type = _typeof(value);
|
122 | if (1 === kind) {
|
123 | if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
124 | void 0 !== value.get && old_assertCallable(value.get, "accessor.get"), void 0 !== value.set && old_assertCallable(value.set, "accessor.set"), void 0 !== value.init && old_assertCallable(value.init, "accessor.init"), void 0 !== value.initializer && old_assertCallable(value.initializer, "accessor.initializer");
|
125 | } else if ("function" !== type) {
|
126 | var hint;
|
127 | throw hint = 0 === kind ? "field" : 10 === kind ? "class" : "method", new TypeError(hint + " decorators must return a function or void 0");
|
128 | }
|
129 | }
|
130 | function old_getInit(desc) {
|
131 | var initializer;
|
132 | return null == (initializer = desc.init) && (initializer = desc.initializer) && "undefined" != typeof console && console.warn(".initializer has been renamed to .init as of March 2022"), initializer;
|
133 | }
|
134 | function old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {
|
135 | var desc,
|
136 | initializer,
|
137 | value,
|
138 | newValue,
|
139 | get,
|
140 | set,
|
141 | decs = decInfo[0];
|
142 | if (isPrivate ? desc = 0 === kind || 1 === kind ? {
|
143 | get: decInfo[3],
|
144 | set: decInfo[4]
|
145 | } : 3 === kind ? {
|
146 | get: decInfo[3]
|
147 | } : 4 === kind ? {
|
148 | set: decInfo[3]
|
149 | } : {
|
150 | value: decInfo[3]
|
151 | } : 0 !== kind && (desc = _Object$getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {
|
152 | get: desc.get,
|
153 | set: desc.set
|
154 | } : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set), "function" == typeof decs) void 0 !== (newValue = old_memberDec(decs, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value)) && (old_assertValidReturnValue(kind, newValue), 0 === kind ? initializer = newValue : 1 === kind ? (initializer = old_getInit(newValue), get = newValue.get || value.get, set = newValue.set || value.set, value = {
|
155 | get: get,
|
156 | set: set
|
157 | }) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {
|
158 | var newInit;
|
159 | if (void 0 !== (newValue = old_memberDec(decs[i], name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value))) old_assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = old_getInit(newValue), get = newValue.get || value.get, set = newValue.set || value.set, value = {
|
160 | get: get,
|
161 | set: set
|
162 | }) : value = newValue, void 0 !== newInit && (void 0 === initializer ? initializer = newInit : "function" == typeof initializer ? initializer = [initializer, newInit] : initializer.push(newInit));
|
163 | }
|
164 | if (0 === kind || 1 === kind) {
|
165 | if (void 0 === initializer) initializer = function initializer(instance, init) {
|
166 | return init;
|
167 | };else if ("function" != typeof initializer) {
|
168 | var ownInitializers = initializer;
|
169 | initializer = function initializer(instance, init) {
|
170 | for (var value = init, i = 0; i < ownInitializers.length; i++) value = ownInitializers[i].call(instance, value);
|
171 | return value;
|
172 | };
|
173 | } else {
|
174 | var originalInitializer = initializer;
|
175 | initializer = function initializer(instance, init) {
|
176 | return originalInitializer.call(instance, init);
|
177 | };
|
178 | }
|
179 | ret.push(initializer);
|
180 | }
|
181 | 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) {
|
182 | return value.get.call(instance, args);
|
183 | }), ret.push(function (instance, args) {
|
184 | return value.set.call(instance, args);
|
185 | })) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {
|
186 | return value.call(instance, args);
|
187 | }) : _Object$defineProperty(base, name, desc));
|
188 | }
|
189 | function old_applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInfos) {
|
190 | for (var protoInitializers, staticInitializers, existingProtoNonFields = new _Map(), existingStaticNonFields = new _Map(), i = 0; i < decInfos.length; i++) {
|
191 | var decInfo = decInfos[i];
|
192 | if (_Array$isArray(decInfo)) {
|
193 | var base,
|
194 | metadataMap,
|
195 | initializers,
|
196 | kind = decInfo[1],
|
197 | name = decInfo[2],
|
198 | isPrivate = decInfo.length > 3,
|
199 | isStatic = kind >= 5;
|
200 | if (isStatic ? (base = Class, metadataMap = staticMetadataMap, 0 !== (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, metadataMap = protoMetadataMap, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {
|
201 | var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
|
202 | existingKind = existingNonFields.get(name) || 0;
|
203 | 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);
|
204 | !existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
|
205 | }
|
206 | old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);
|
207 | }
|
208 | }
|
209 | old_pushInitializers(ret, protoInitializers), old_pushInitializers(ret, staticInitializers);
|
210 | }
|
211 | function old_pushInitializers(ret, initializers) {
|
212 | initializers && ret.push(function (instance) {
|
213 | for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
|
214 | return instance;
|
215 | });
|
216 | }
|
217 | function old_applyClassDecs(ret, targetClass, metadataMap, classDecs) {
|
218 | if (classDecs.length > 0) {
|
219 | for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {
|
220 | var decoratorFinishedRef = {
|
221 | v: !1
|
222 | };
|
223 | try {
|
224 | var ctx = _Object$assign({
|
225 | kind: "class",
|
226 | name: name,
|
227 | addInitializer: old_createAddInitializerMethod(initializers, decoratorFinishedRef)
|
228 | }, old_createMetadataMethodsForProperty(metadataMap, 0, name, decoratorFinishedRef)),
|
229 | nextNewClass = classDecs[i](newClass, ctx);
|
230 | } finally {
|
231 | decoratorFinishedRef.v = !0;
|
232 | }
|
233 | void 0 !== nextNewClass && (old_assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);
|
234 | }
|
235 | ret.push(newClass, function () {
|
236 | for (var i = 0; i < initializers.length; i++) initializers[i].call(newClass);
|
237 | });
|
238 | }
|
239 | }
|
240 | function applyDecs(targetClass, memberDecs, classDecs) {
|
241 | var ret = [],
|
242 | staticMetadataMap = {},
|
243 | protoMetadataMap = {};
|
244 | return old_applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs), old_convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap), old_applyClassDecs(ret, targetClass, staticMetadataMap, classDecs), old_convertMetadataMapToFinal(targetClass, staticMetadataMap), ret;
|
245 | }
|
246 | module.exports = applyDecs, module.exports.__esModule = true, module.exports["default"] = module.exports; |
\ | No newline at end of file |