Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@babel/runtime/helpers/esm/applyDecs2203.js
1126 views
1
import _typeof from "./typeof.js";
2
3
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
4
return function (initializer) {
5
assertNotFinished(decoratorFinishedRef, "addInitializer"), assertCallable(initializer, "An initializer"), initializers.push(initializer);
6
};
7
}
8
9
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value) {
10
var kindStr;
11
12
switch (kind) {
13
case 1:
14
kindStr = "accessor";
15
break;
16
17
case 2:
18
kindStr = "method";
19
break;
20
21
case 3:
22
kindStr = "getter";
23
break;
24
25
case 4:
26
kindStr = "setter";
27
break;
28
29
default:
30
kindStr = "field";
31
}
32
33
var get,
34
set,
35
ctx = {
36
kind: kindStr,
37
name: isPrivate ? "#" + name : name,
38
"static": isStatic,
39
"private": isPrivate
40
},
41
decoratorFinishedRef = {
42
v: !1
43
};
44
0 !== kind && (ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef)), 0 === kind ? isPrivate ? (get = desc.get, set = desc.set) : (get = function get() {
45
return this[name];
46
}, set = function set(v) {
47
this[name] = v;
48
}) : 2 === kind ? get = function get() {
49
return desc.value;
50
} : (1 !== kind && 3 !== kind || (get = function get() {
51
return desc.get.call(this);
52
}), 1 !== kind && 4 !== kind || (set = function set(v) {
53
desc.set.call(this, v);
54
})), ctx.access = get && set ? {
55
get: get,
56
set: set
57
} : get ? {
58
get: get
59
} : {
60
set: set
61
};
62
63
try {
64
return dec(value, ctx);
65
} finally {
66
decoratorFinishedRef.v = !0;
67
}
68
}
69
70
function assertNotFinished(decoratorFinishedRef, fnName) {
71
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
72
}
73
74
function assertCallable(fn, hint) {
75
if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
76
}
77
78
function assertValidReturnValue(kind, value) {
79
var type = _typeof(value);
80
81
if (1 === kind) {
82
if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
83
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");
84
} else if ("function" !== type) {
85
var hint;
86
throw hint = 0 === kind ? "field" : 10 === kind ? "class" : "method", new TypeError(hint + " decorators must return a function or void 0");
87
}
88
}
89
90
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers) {
91
var desc,
92
init,
93
value,
94
newValue,
95
get,
96
set,
97
decs = decInfo[0];
98
if (isPrivate ? desc = 0 === kind || 1 === kind ? {
99
get: decInfo[3],
100
set: decInfo[4]
101
} : 3 === kind ? {
102
get: decInfo[3]
103
} : 4 === kind ? {
104
set: decInfo[3]
105
} : {
106
value: decInfo[3]
107
} : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {
108
get: desc.get,
109
set: desc.set
110
} : 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 = {
111
get: get,
112
set: set
113
}) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {
114
var newInit;
115
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 = {
116
get: get,
117
set: set
118
}) : value = newValue, void 0 !== newInit && (void 0 === init ? init = newInit : "function" == typeof init ? init = [init, newInit] : init.push(newInit));
119
}
120
121
if (0 === kind || 1 === kind) {
122
if (void 0 === init) init = function init(instance, _init) {
123
return _init;
124
};else if ("function" != typeof init) {
125
var ownInitializers = init;
126
127
init = function init(instance, _init2) {
128
for (var value = _init2, i = 0; i < ownInitializers.length; i++) {
129
value = ownInitializers[i].call(instance, value);
130
}
131
132
return value;
133
};
134
} else {
135
var originalInitializer = init;
136
137
init = function init(instance, _init3) {
138
return originalInitializer.call(instance, _init3);
139
};
140
}
141
ret.push(init);
142
}
143
144
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) {
145
return value.get.call(instance, args);
146
}), ret.push(function (instance, args) {
147
return value.set.call(instance, args);
148
})) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {
149
return value.call(instance, args);
150
}) : Object.defineProperty(base, name, desc));
151
}
152
153
function applyMemberDecs(ret, Class, decInfos) {
154
for (var protoInitializers, staticInitializers, existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {
155
var decInfo = decInfos[i];
156
157
if (Array.isArray(decInfo)) {
158
var base,
159
initializers,
160
kind = decInfo[1],
161
name = decInfo[2],
162
isPrivate = decInfo.length > 3,
163
isStatic = kind >= 5;
164
165
if (isStatic ? (base = Class, 0 !== (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {
166
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
167
existingKind = existingNonFields.get(name) || 0;
168
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);
169
!existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
170
}
171
172
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);
173
}
174
}
175
176
pushInitializers(ret, protoInitializers), pushInitializers(ret, staticInitializers);
177
}
178
179
function pushInitializers(ret, initializers) {
180
initializers && ret.push(function (instance) {
181
for (var i = 0; i < initializers.length; i++) {
182
initializers[i].call(instance);
183
}
184
185
return instance;
186
});
187
}
188
189
function applyClassDecs(ret, targetClass, classDecs) {
190
if (classDecs.length > 0) {
191
for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {
192
var decoratorFinishedRef = {
193
v: !1
194
};
195
196
try {
197
var nextNewClass = classDecs[i](newClass, {
198
kind: "class",
199
name: name,
200
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)
201
});
202
} finally {
203
decoratorFinishedRef.v = !0;
204
}
205
206
void 0 !== nextNewClass && (assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);
207
}
208
209
ret.push(newClass, function () {
210
for (var i = 0; i < initializers.length; i++) {
211
initializers[i].call(newClass);
212
}
213
});
214
}
215
}
216
217
export default function applyDecs2203(targetClass, memberDecs, classDecs) {
218
var ret = [];
219
return applyMemberDecs(ret, targetClass, memberDecs), applyClassDecs(ret, targetClass, classDecs), ret;
220
}
221