Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/node_modules/@babel/runtime/helpers/applyDecs.js
2593 views
1
var _typeof = require("./typeof.js")["default"];
2
3
function createMetadataMethodsForProperty(metadataMap, kind, property) {
4
return {
5
getMetadata: function getMetadata(key) {
6
if ("symbol" != _typeof(key)) throw new TypeError("Metadata keys must be symbols, received: " + key);
7
var metadataForKey = metadataMap[key];
8
if (void 0 !== metadataForKey) if (1 === kind) {
9
var pub = metadataForKey["public"];
10
if (void 0 !== pub) return pub[property];
11
} else if (2 === kind) {
12
var priv = metadataForKey["private"];
13
if (void 0 !== priv) return priv.get(property);
14
} else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) return metadataForKey.constructor;
15
},
16
setMetadata: function setMetadata(key, value) {
17
if ("symbol" != _typeof(key)) throw new TypeError("Metadata keys must be symbols, received: " + key);
18
var metadataForKey = metadataMap[key];
19
20
if (void 0 === metadataForKey && (metadataForKey = metadataMap[key] = {}), 1 === kind) {
21
var pub = metadataForKey["public"];
22
void 0 === pub && (pub = metadataForKey["public"] = {}), pub[property] = value;
23
} else if (2 === kind) {
24
var priv = metadataForKey.priv;
25
void 0 === priv && (priv = metadataForKey["private"] = new Map()), priv.set(property, value);
26
} else metadataForKey.constructor = value;
27
}
28
};
29
}
30
31
function convertMetadataMapToFinal(obj, metadataMap) {
32
var parentMetadataMap = obj[Symbol.metadata || Symbol["for"]("Symbol.metadata")],
33
metadataKeys = Object.getOwnPropertySymbols(metadataMap);
34
35
if (0 !== metadataKeys.length) {
36
for (var i = 0; i < metadataKeys.length; i++) {
37
var key = metadataKeys[i],
38
metaForKey = metadataMap[key],
39
parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null,
40
pub = metaForKey["public"],
41
parentPub = parentMetaForKey ? parentMetaForKey["public"] : null;
42
pub && parentPub && Object.setPrototypeOf(pub, parentPub);
43
var priv = metaForKey["private"];
44
45
if (priv) {
46
var privArr = Array.from(priv.values()),
47
parentPriv = parentMetaForKey ? parentMetaForKey["private"] : null;
48
parentPriv && (privArr = privArr.concat(parentPriv)), metaForKey["private"] = privArr;
49
}
50
51
parentMetaForKey && Object.setPrototypeOf(metaForKey, parentMetaForKey);
52
}
53
54
parentMetadataMap && Object.setPrototypeOf(metadataMap, parentMetadataMap), obj[Symbol.metadata || Symbol["for"]("Symbol.metadata")] = metadataMap;
55
}
56
}
57
58
function createAddInitializerMethod(initializers) {
59
return function (initializer) {
60
assertValidInitializer(initializer), initializers.push(initializer);
61
};
62
}
63
64
function memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate) {
65
var kindStr;
66
67
switch (kind) {
68
case 1:
69
kindStr = "accessor";
70
break;
71
72
case 2:
73
kindStr = "method";
74
break;
75
76
case 3:
77
kindStr = "getter";
78
break;
79
80
case 4:
81
kindStr = "setter";
82
break;
83
84
default:
85
kindStr = "field";
86
}
87
88
var metadataKind,
89
metadataName,
90
ctx = {
91
kind: kindStr,
92
name: isPrivate ? "#" + name : name,
93
isStatic: isStatic,
94
isPrivate: isPrivate
95
};
96
97
if (0 !== kind && (ctx.addInitializer = createAddInitializerMethod(initializers)), isPrivate) {
98
metadataKind = 2, metadataName = Symbol(name);
99
var access = {};
100
0 === kind ? (access.get = desc.get, access.set = desc.set) : 2 === kind ? access.get = function () {
101
return desc.value;
102
} : (1 !== kind && 3 !== kind || (access.get = function () {
103
return desc.get.call(this);
104
}), 1 !== kind && 4 !== kind || (access.set = function (v) {
105
desc.set.call(this, v);
106
})), ctx.access = access;
107
} else metadataKind = 1, metadataName = name;
108
109
return Object.assign(ctx, createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName));
110
}
111
112
function assertValidInitializer(initializer) {
113
if ("function" != typeof initializer) throw new Error("initializers must be functions");
114
}
115
116
function assertValidReturnValue(kind, value) {
117
var type = _typeof(value);
118
119
if (1 === kind) {
120
if ("object" !== type || null === value) throw new Error("accessor decorators must return an object with get, set, or initializer properties or void 0");
121
} else if ("function" !== type) throw 0 === kind ? new Error("field decorators must return a initializer function or void 0") : new Error("method decorators must return a function or void 0");
122
}
123
124
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {
125
var desc,
126
initializer,
127
value,
128
decs = decInfo[0];
129
isPrivate ? desc = 0 === kind || 1 === kind ? {
130
get: decInfo[3],
131
set: decInfo[4]
132
} : 3 === kind ? {
133
get: decInfo[3]
134
} : 4 === kind ? {
135
set: decInfo[3]
136
} : {
137
value: decInfo[3]
138
} : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {
139
get: desc.get,
140
set: desc.set
141
} : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set);
142
var newValue,
143
get,
144
set,
145
ctx = memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate);
146
if ("function" == typeof decs) void 0 !== (newValue = decs(value, ctx)) && (assertValidReturnValue(kind, newValue), 0 === kind ? initializer = newValue : 1 === kind ? (initializer = newValue.initializer, get = newValue.get || value.get, set = newValue.set || value.set, value = {
147
get: get,
148
set: set
149
}) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {
150
var newInit;
151
if (void 0 !== (newValue = (0, decs[i])(value, ctx))) assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = newValue.initializer, get = newValue.get || value.get, set = newValue.set || value.set, value = {
152
get: get,
153
set: set
154
}) : value = newValue, void 0 !== newInit && (void 0 === initializer ? initializer = newInit : "function" == typeof initializer ? initializer = [initializer, newInit] : initializer.push(newInit));
155
}
156
157
if (0 === kind || 1 === kind) {
158
if (void 0 === initializer) initializer = function initializer(instance, init) {
159
return init;
160
};else if ("function" != typeof initializer) {
161
var ownInitializers = initializer;
162
163
initializer = function initializer(instance, init) {
164
for (var value = init, i = 0; i < ownInitializers.length; i++) {
165
value = ownInitializers[i].call(instance, value);
166
}
167
168
return value;
169
};
170
} else {
171
var originalInitializer = initializer;
172
173
initializer = function initializer(instance, init) {
174
return originalInitializer.call(instance, init);
175
};
176
}
177
ret.push(initializer);
178
}
179
180
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) {
181
return value.get.call(instance, args);
182
}), ret.push(function (instance, args) {
183
return value.set.call(instance, args);
184
})) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {
185
return value.call(instance, args);
186
}) : Object.defineProperty(base, name, desc));
187
}
188
189
function 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
193
if (Array.isArray(decInfo)) {
194
var base,
195
metadataMap,
196
initializers,
197
kind = decInfo[1],
198
name = decInfo[2],
199
isPrivate = decInfo.length > 3,
200
isStatic = kind >= 5;
201
202
if (isStatic ? (base = Class, metadataMap = staticMetadataMap, kind -= 5, initializers = staticInitializers) : (base = Class.prototype, metadataMap = protoMetadataMap, initializers = protoInitializers), 0 !== kind && !isPrivate) {
203
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
204
existingKind = existingNonFields.get(name) || 0;
205
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);
206
!existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
207
}
208
209
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);
210
}
211
}
212
213
protoInitializers.length > 0 && pushInitializers(ret, protoInitializers), staticInitializers.length > 0 && pushInitializers(ret, staticInitializers);
214
}
215
216
function pushInitializers(ret, initializers) {
217
initializers.length > 0 ? (initializers = initializers.slice(), ret.push(function (instance) {
218
for (var i = 0; i < initializers.length; i++) {
219
initializers[i].call(instance, instance);
220
}
221
222
return instance;
223
})) : ret.push(function (instance) {
224
return instance;
225
});
226
}
227
228
function applyClassDecs(ret, targetClass, metadataMap, classDecs) {
229
for (var initializers = [], newClass = targetClass, name = targetClass.name, ctx = Object.assign({
230
kind: "class",
231
name: name,
232
addInitializer: createAddInitializerMethod(initializers)
233
}, createMetadataMethodsForProperty(metadataMap, 0, name)), i = classDecs.length - 1; i >= 0; i--) {
234
newClass = classDecs[i](newClass, ctx) || newClass;
235
}
236
237
ret.push(newClass), initializers.length > 0 ? ret.push(function () {
238
for (var i = 0; i < initializers.length; i++) {
239
initializers[i].call(newClass, newClass);
240
}
241
}) : ret.push(function () {});
242
}
243
244
function applyDecs(targetClass, memberDecs, classDecs) {
245
var ret = [],
246
staticMetadataMap = {};
247
248
if (memberDecs) {
249
var protoMetadataMap = {};
250
applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs), convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
251
}
252
253
return classDecs && applyClassDecs(ret, targetClass, staticMetadataMap, classDecs), convertMetadataMapToFinal(targetClass, staticMetadataMap), ret;
254
}
255
256
module.exports = applyDecs, module.exports.__esModule = true, module.exports["default"] = module.exports;
257