@jsenv/core 40.3.1 → 40.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +42 -33
  2. package/dist/browserslist_index/browserslist_index.js +4951 -0
  3. package/dist/build/build.js +189 -62
  4. package/dist/jsenv_core_node_modules.js +25 -1
  5. package/dist/jsenv_core_packages.js +6384 -11580
  6. package/dist/start_build_server/start_build_server.js +0 -5
  7. package/dist/start_dev_server/start_dev_server.js +108 -60
  8. package/package.json +20 -21
  9. package/src/build/build.js +80 -1
  10. package/src/kitchen/errors.js +6 -1
  11. package/src/kitchen/kitchen.js +95 -7
  12. package/src/plugins/package_side_effects/jsenv_plugin_package_side_effects.js +5 -51
  13. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +0 -112
  14. package/dist/babel_helpers/AwaitValue/AwaitValue.js +0 -3
  15. package/dist/babel_helpers/OverloadYield/OverloadYield.js +0 -11
  16. package/dist/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +0 -32
  17. package/dist/babel_helpers/applyDecs/applyDecs.js +0 -813
  18. package/dist/babel_helpers/applyDecs2203/applyDecs2203.js +0 -635
  19. package/dist/babel_helpers/applyDecs2203R/applyDecs2203R.js +0 -654
  20. package/dist/babel_helpers/applyDecs2301/applyDecs2301.js +0 -721
  21. package/dist/babel_helpers/applyDecs2305/applyDecs2305.js +0 -531
  22. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +0 -7
  23. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +0 -4
  24. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +0 -6
  25. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +0 -9
  26. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -55
  27. package/dist/babel_helpers/asyncIterator/asyncIterator.js +0 -68
  28. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +0 -34
  29. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -5
  30. package/dist/babel_helpers/callSuper/callSuper.js +0 -25
  31. package/dist/babel_helpers/checkInRHS/checkInRHS.js +0 -11
  32. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -23
  33. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -6
  34. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -13
  35. package/dist/babel_helpers/classCallCheck/classCallCheck.js +0 -5
  36. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -8
  37. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -11
  38. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -13
  39. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +0 -6
  40. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -7
  41. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +0 -7
  42. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -6
  43. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -5
  44. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +0 -8
  45. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +0 -6
  46. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +0 -3
  47. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -13
  48. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -15
  49. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -10
  50. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -3
  51. package/dist/babel_helpers/construct/construct.js +0 -20
  52. package/dist/babel_helpers/createClass/createClass.js +0 -17
  53. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -61
  54. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -24
  55. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +0 -50
  56. package/dist/babel_helpers/createSuper/createSuper.js +0 -22
  57. package/dist/babel_helpers/decorate/decorate.js +0 -488
  58. package/dist/babel_helpers/defaults/defaults.js +0 -11
  59. package/dist/babel_helpers/defineAccessor/defineAccessor.js +0 -6
  60. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +0 -23
  61. package/dist/babel_helpers/defineProperty/defineProperty.js +0 -21
  62. package/dist/babel_helpers/dispose/dispose.js +0 -45
  63. package/dist/babel_helpers/extends/extends.js +0 -14
  64. package/dist/babel_helpers/get/get.js +0 -19
  65. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +0 -4
  66. package/dist/babel_helpers/identity/identity.js +0 -3
  67. package/dist/babel_helpers/importDeferProxy/importDeferProxy.js +0 -31
  68. package/dist/babel_helpers/inherits/inherits.js +0 -19
  69. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +0 -7
  70. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +0 -12
  71. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +0 -6
  72. package/dist/babel_helpers/instanceof/instanceof.js +0 -10
  73. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +0 -3
  74. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +0 -47
  75. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +0 -9
  76. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -19
  77. package/dist/babel_helpers/iterableToArray/iterableToArray.js +0 -7
  78. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +0 -54
  79. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -16
  80. package/dist/babel_helpers/jsx/jsx.js +0 -50
  81. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +0 -10
  82. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +0 -5
  83. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +0 -5
  84. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +0 -5
  85. package/dist/babel_helpers/nullishReceiverError/nullishReceiverError.js +0 -3
  86. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -3
  87. package/dist/babel_helpers/objectSpread/objectSpread.js +0 -23
  88. package/dist/babel_helpers/objectSpread2/objectSpread2.js +0 -43
  89. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +0 -19
  90. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -13
  91. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +0 -12
  92. package/dist/babel_helpers/readOnlyError/readOnlyError.js +0 -4
  93. package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +0 -698
  94. package/dist/babel_helpers/set/set.js +0 -47
  95. package/dist/babel_helpers/setFunctionName/setFunctionName.js +0 -19
  96. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +0 -7
  97. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -8
  98. package/dist/babel_helpers/slicedToArray/slicedToArray.js +0 -10
  99. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +0 -13
  100. package/dist/babel_helpers/superPropBase/superPropBase.js +0 -10
  101. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -10
  102. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -7
  103. package/dist/babel_helpers/tdz/tdz.js +0 -4
  104. package/dist/babel_helpers/temporalRef/temporalRef.js +0 -6
  105. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +0 -3
  106. package/dist/babel_helpers/toArray/toArray.js +0 -10
  107. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +0 -10
  108. package/dist/babel_helpers/toPrimitive/toPrimitive.js +0 -14
  109. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +0 -10
  110. package/dist/babel_helpers/typeof/typeof.js +0 -15
  111. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -12
  112. package/dist/babel_helpers/using/using.js +0 -23
  113. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -8
  114. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +0 -30
  115. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +0 -79
  116. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +0 -3
@@ -1,813 +0,0 @@
1
- /* @minVersion 7.17.8 */
2
-
3
- import setFunctionName from "../setFunctionName/setFunctionName.js";
4
- import toPropertyKey from "../toPropertyKey/toPropertyKey.js";
5
- /**
6
- * NOTE: This is an old version of the helper, used for 2021-12 decorators.
7
- * Updates should be done in applyDecs2203R.js.
8
- */
9
-
10
- /**
11
- Enums are used in this file, but not assigned to vars to avoid non-hoistable values
12
-
13
- CONSTRUCTOR = 0;
14
- PUBLIC = 1;
15
- PRIVATE = 2;
16
-
17
- FIELD = 0;
18
- ACCESSOR = 1;
19
- METHOD = 2;
20
- GETTER = 3;
21
- SETTER = 4;
22
-
23
- STATIC = 5;
24
-
25
- CLASS = 10; // only used in assertValidReturnValue
26
- */
27
-
28
- function old_createMetadataMethodsForProperty(
29
- metadataMap,
30
- kind,
31
- property,
32
- decoratorFinishedRef,
33
- ) {
34
- return {
35
- getMetadata: function (key) {
36
- old_assertNotFinished(decoratorFinishedRef, "getMetadata");
37
- old_assertMetadataKey(key);
38
-
39
- var metadataForKey = metadataMap[key];
40
-
41
- if (metadataForKey === void 0) return void 0;
42
-
43
- if (kind === 1 /* PUBLIC */) {
44
- var pub = metadataForKey.public;
45
- if (pub !== void 0) {
46
- return pub[property];
47
- }
48
- } else if (kind === 2 /* PRIVATE */) {
49
- var priv = metadataForKey.private;
50
- if (priv !== void 0) {
51
- return priv.get(property);
52
- }
53
- } else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) {
54
- return metadataForKey.constructor;
55
- }
56
- },
57
- setMetadata: function (key, value) {
58
- old_assertNotFinished(decoratorFinishedRef, "setMetadata");
59
- old_assertMetadataKey(key);
60
-
61
- var metadataForKey = metadataMap[key];
62
-
63
- if (metadataForKey === void 0) {
64
- metadataForKey = metadataMap[key] = {};
65
- }
66
-
67
- if (kind === 1 /* PUBLIC */) {
68
- var pub = metadataForKey.public;
69
-
70
- if (pub === void 0) {
71
- pub = metadataForKey.public = {};
72
- }
73
-
74
- pub[property] = value;
75
- } else if (kind === 2 /* PRIVATE */) {
76
- var priv = metadataForKey.priv;
77
-
78
- if (priv === void 0) {
79
- priv = metadataForKey.private = new Map();
80
- }
81
-
82
- priv.set(property, value);
83
- } else {
84
- metadataForKey.constructor = value;
85
- }
86
- },
87
- };
88
- }
89
-
90
- function old_convertMetadataMapToFinal(obj, metadataMap) {
91
- var parentMetadataMap = obj[Symbol.metadata || Symbol.for("Symbol.metadata")];
92
- var metadataKeys = Object.getOwnPropertySymbols(metadataMap);
93
-
94
- if (metadataKeys.length === 0) return;
95
-
96
- for (var i = 0; i < metadataKeys.length; i++) {
97
- var key = metadataKeys[i];
98
- var metaForKey = metadataMap[key];
99
- var parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null;
100
-
101
- var pub = metaForKey.public;
102
- var parentPub = parentMetaForKey ? parentMetaForKey.public : null;
103
-
104
- if (pub && parentPub) {
105
- Object.setPrototypeOf(pub, parentPub);
106
- }
107
-
108
- var priv = metaForKey.private;
109
-
110
- if (priv) {
111
- var privArr = Array.from(priv.values());
112
- var parentPriv = parentMetaForKey ? parentMetaForKey.private : null;
113
-
114
- if (parentPriv) {
115
- privArr = privArr.concat(parentPriv);
116
- }
117
-
118
- metaForKey.private = privArr;
119
- }
120
-
121
- if (parentMetaForKey) {
122
- Object.setPrototypeOf(metaForKey, parentMetaForKey);
123
- }
124
- }
125
-
126
- if (parentMetadataMap) {
127
- Object.setPrototypeOf(metadataMap, parentMetadataMap);
128
- }
129
-
130
- obj[Symbol.metadata || Symbol.for("Symbol.metadata")] = metadataMap;
131
- }
132
-
133
- function old_createAddInitializerMethod(initializers, decoratorFinishedRef) {
134
- return function addInitializer(initializer) {
135
- old_assertNotFinished(decoratorFinishedRef, "addInitializer");
136
- old_assertCallable(initializer, "An initializer");
137
- initializers.push(initializer);
138
- };
139
- }
140
-
141
- function old_memberDec(
142
- dec,
143
- name,
144
- desc,
145
- metadataMap,
146
- initializers,
147
- kind,
148
- isStatic,
149
- isPrivate,
150
- value,
151
- ) {
152
- var kindStr;
153
-
154
- switch (kind) {
155
- case 1 /* ACCESSOR */:
156
- kindStr = "accessor";
157
- break;
158
- case 2 /* METHOD */:
159
- kindStr = "method";
160
- break;
161
- case 3 /* GETTER */:
162
- kindStr = "getter";
163
- break;
164
- case 4 /* SETTER */:
165
- kindStr = "setter";
166
- break;
167
- default:
168
- kindStr = "field";
169
- }
170
-
171
- var ctx = {
172
- kind: kindStr,
173
- name: isPrivate ? "#" + name : toPropertyKey(name),
174
- isStatic: isStatic,
175
- isPrivate: isPrivate,
176
- };
177
-
178
- var decoratorFinishedRef = { v: false };
179
-
180
- if (kind !== 0 /* FIELD */) {
181
- ctx.addInitializer = old_createAddInitializerMethod(
182
- initializers,
183
- decoratorFinishedRef,
184
- );
185
- }
186
-
187
- var metadataKind, metadataName;
188
-
189
- if (isPrivate) {
190
- metadataKind = 2 /* PRIVATE */;
191
- metadataName = Symbol(name);
192
-
193
- var access = {};
194
-
195
- if (kind === 0 /* FIELD */) {
196
- access.get = desc.get;
197
- access.set = desc.set;
198
- } else if (kind === 2 /* METHOD */) {
199
- access.get = function () {
200
- return desc.value;
201
- };
202
- } else {
203
- // replace with values that will go through the final getter and setter
204
- if (kind === 1 /* ACCESSOR */ || kind === 3 /* GETTER */) {
205
- access.get = function () {
206
- return desc.get.call(this);
207
- };
208
- }
209
-
210
- if (kind === 1 /* ACCESSOR */ || kind === 4 /* SETTER */) {
211
- access.set = function (v) {
212
- desc.set.call(this, v);
213
- };
214
- }
215
- }
216
-
217
- ctx.access = access;
218
- } else {
219
- metadataKind = 1 /* PUBLIC */;
220
- metadataName = name;
221
- }
222
-
223
- try {
224
- return dec(
225
- value,
226
- Object.assign(
227
- ctx,
228
- old_createMetadataMethodsForProperty(
229
- metadataMap,
230
- metadataKind,
231
- metadataName,
232
- decoratorFinishedRef,
233
- ),
234
- ),
235
- );
236
- } finally {
237
- decoratorFinishedRef.v = true;
238
- }
239
- }
240
-
241
- function old_assertNotFinished(decoratorFinishedRef, fnName) {
242
- if (decoratorFinishedRef.v) {
243
- throw new Error(
244
- "attempted to call " + fnName + " after decoration was finished",
245
- );
246
- }
247
- }
248
-
249
- function old_assertMetadataKey(key) {
250
- if (typeof key !== "symbol") {
251
- throw new TypeError("Metadata keys must be symbols, received: " + key);
252
- }
253
- }
254
-
255
- function old_assertCallable(fn, hint) {
256
- if (typeof fn !== "function") {
257
- throw new TypeError(hint + " must be a function");
258
- }
259
- }
260
-
261
- function old_assertValidReturnValue(kind, value) {
262
- var type = typeof value;
263
-
264
- if (kind === 1 /* ACCESSOR */) {
265
- if (type !== "object" || value === null) {
266
- throw new TypeError(
267
- "accessor decorators must return an object with get, set, or init properties or void 0",
268
- );
269
- }
270
- if (value.get !== undefined) {
271
- old_assertCallable(value.get, "accessor.get");
272
- }
273
- if (value.set !== undefined) {
274
- old_assertCallable(value.set, "accessor.set");
275
- }
276
- if (value.init !== undefined) {
277
- old_assertCallable(value.init, "accessor.init");
278
- }
279
- if (value.initializer !== undefined) {
280
- old_assertCallable(value.initializer, "accessor.initializer");
281
- }
282
- } else if (type !== "function") {
283
- var hint;
284
- if (kind === 0 /* FIELD */) {
285
- hint = "field";
286
- } else if (kind === 10 /* CLASS */) {
287
- hint = "class";
288
- } else {
289
- hint = "method";
290
- }
291
- throw new TypeError(hint + " decorators must return a function or void 0");
292
- }
293
- }
294
-
295
- function old_getInit(desc) {
296
- var initializer;
297
- if (
298
- (initializer = desc.init) == null &&
299
- (initializer = desc.initializer) &&
300
- typeof console !== "undefined"
301
- ) {
302
- console.warn(".initializer has been renamed to .init as of March 2022");
303
- }
304
- return initializer;
305
- }
306
-
307
- function old_applyMemberDec(
308
- ret,
309
- base,
310
- decInfo,
311
- name,
312
- kind,
313
- isStatic,
314
- isPrivate,
315
- metadataMap,
316
- initializers,
317
- ) {
318
- var decs = decInfo[0];
319
-
320
- var desc, initializer, prefix, value;
321
-
322
- if (isPrivate) {
323
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
324
- desc = {
325
- get: decInfo[3],
326
- set: decInfo[4],
327
- };
328
- prefix = "get";
329
- } else if (kind === 3 /* GETTER */) {
330
- desc = {
331
- get: decInfo[3],
332
- };
333
- prefix = "get";
334
- } else if (kind === 4 /* SETTER */) {
335
- desc = {
336
- set: decInfo[3],
337
- };
338
- prefix = "set";
339
- } else {
340
- desc = {
341
- value: decInfo[3],
342
- };
343
- }
344
- if (kind !== 0 /* FIELD */) {
345
- if (kind === 1 /* ACCESSOR */) {
346
- setFunctionName(decInfo[4], "#" + name, "set");
347
- }
348
- setFunctionName(decInfo[3], "#" + name, prefix);
349
- }
350
- } else if (kind !== 0 /* FIELD */) {
351
- desc = Object.getOwnPropertyDescriptor(base, name);
352
- }
353
-
354
- if (kind === 1 /* ACCESSOR */) {
355
- value = {
356
- get: desc.get,
357
- set: desc.set,
358
- };
359
- } else if (kind === 2 /* METHOD */) {
360
- value = desc.value;
361
- } else if (kind === 3 /* GETTER */) {
362
- value = desc.get;
363
- } else if (kind === 4 /* SETTER */) {
364
- value = desc.set;
365
- }
366
-
367
- var newValue, get, set;
368
-
369
- if (typeof decs === "function") {
370
- newValue = old_memberDec(
371
- decs,
372
- name,
373
- desc,
374
- metadataMap,
375
- initializers,
376
- kind,
377
- isStatic,
378
- isPrivate,
379
- value,
380
- );
381
-
382
- if (newValue !== void 0) {
383
- old_assertValidReturnValue(kind, newValue);
384
-
385
- if (kind === 0 /* FIELD */) {
386
- initializer = newValue;
387
- } else if (kind === 1 /* ACCESSOR */) {
388
- initializer = old_getInit(newValue);
389
- get = newValue.get || value.get;
390
- set = newValue.set || value.set;
391
-
392
- value = { get: get, set: set };
393
- } else {
394
- value = newValue;
395
- }
396
- }
397
- } else {
398
- for (var i = decs.length - 1; i >= 0; i--) {
399
- var dec = decs[i];
400
-
401
- newValue = old_memberDec(
402
- dec,
403
- name,
404
- desc,
405
- metadataMap,
406
- initializers,
407
- kind,
408
- isStatic,
409
- isPrivate,
410
- value,
411
- );
412
-
413
- if (newValue !== void 0) {
414
- old_assertValidReturnValue(kind, newValue);
415
- var newInit;
416
-
417
- if (kind === 0 /* FIELD */) {
418
- newInit = newValue;
419
- } else if (kind === 1 /* ACCESSOR */) {
420
- newInit = old_getInit(newValue);
421
- get = newValue.get || value.get;
422
- set = newValue.set || value.set;
423
-
424
- value = { get: get, set: set };
425
- } else {
426
- value = newValue;
427
- }
428
-
429
- if (newInit !== void 0) {
430
- if (initializer === void 0) {
431
- initializer = newInit;
432
- } else if (typeof initializer === "function") {
433
- initializer = [initializer, newInit];
434
- } else {
435
- initializer.push(newInit);
436
- }
437
- }
438
- }
439
- }
440
- }
441
-
442
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
443
- if (initializer === void 0) {
444
- // If the initializer was void 0, sub in a dummy initializer
445
- initializer = function (instance, init) {
446
- return init;
447
- };
448
- } else if (typeof initializer !== "function") {
449
- var ownInitializers = initializer;
450
-
451
- initializer = function (instance, init) {
452
- var value = init;
453
-
454
- for (var i = 0; i < ownInitializers.length; i++) {
455
- value = ownInitializers[i].call(instance, value);
456
- }
457
-
458
- return value;
459
- };
460
- } else {
461
- var originalInitializer = initializer;
462
-
463
- initializer = function (instance, init) {
464
- return originalInitializer.call(instance, init);
465
- };
466
- }
467
-
468
- ret.push(initializer);
469
- }
470
-
471
- if (kind !== 0 /* FIELD */) {
472
- if (kind === 1 /* ACCESSOR */) {
473
- desc.get = value.get;
474
- desc.set = value.set;
475
- } else if (kind === 2 /* METHOD */) {
476
- desc.value = value;
477
- } else if (kind === 3 /* GETTER */) {
478
- desc.get = value;
479
- } else if (kind === 4 /* SETTER */) {
480
- desc.set = value;
481
- }
482
-
483
- if (isPrivate) {
484
- if (kind === 1 /* ACCESSOR */) {
485
- ret.push(function (instance, args) {
486
- return value.get.call(instance, args);
487
- });
488
- ret.push(function (instance, args) {
489
- return value.set.call(instance, args);
490
- });
491
- } else if (kind === 2 /* METHOD */) {
492
- ret.push(value);
493
- } else {
494
- ret.push(function (instance, args) {
495
- return value.call(instance, args);
496
- });
497
- }
498
- } else {
499
- Object.defineProperty(base, name, desc);
500
- }
501
- }
502
- }
503
-
504
- function old_applyMemberDecs(
505
- ret,
506
- Class,
507
- protoMetadataMap,
508
- staticMetadataMap,
509
- decInfos,
510
- ) {
511
- var protoInitializers;
512
- var staticInitializers;
513
-
514
- var existingProtoNonFields = new Map();
515
- var existingStaticNonFields = new Map();
516
-
517
- for (var i = 0; i < decInfos.length; i++) {
518
- var decInfo = decInfos[i];
519
-
520
- // skip computed property names
521
- if (!Array.isArray(decInfo)) continue;
522
-
523
- var kind = decInfo[1];
524
- var name = decInfo[2];
525
- var isPrivate = decInfo.length > 3;
526
-
527
- var isStatic = kind >= 5; /* STATIC */
528
- var base;
529
- var metadataMap;
530
- var initializers;
531
-
532
- if (isStatic) {
533
- base = Class;
534
- metadataMap = staticMetadataMap;
535
- kind = kind - 5 /* STATIC */;
536
- // initialize staticInitializers when we see a non-field static member
537
- if (kind !== 0 /* FIELD */) {
538
- staticInitializers = staticInitializers || [];
539
- initializers = staticInitializers;
540
- }
541
- } else {
542
- base = Class.prototype;
543
- metadataMap = protoMetadataMap;
544
- // initialize protoInitializers when we see a non-field member
545
- if (kind !== 0 /* FIELD */) {
546
- protoInitializers = protoInitializers || [];
547
- initializers = protoInitializers;
548
- }
549
- }
550
-
551
- if (kind !== 0 /* FIELD */ && !isPrivate) {
552
- var existingNonFields = isStatic
553
- ? existingStaticNonFields
554
- : existingProtoNonFields;
555
-
556
- var existingKind = existingNonFields.get(name) || 0;
557
-
558
- if (
559
- existingKind === true ||
560
- (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ ||
561
- (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */
562
- ) {
563
- throw new Error(
564
- "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: " +
565
- name,
566
- );
567
- } else if (!existingKind && kind > 2 /* METHOD */) {
568
- existingNonFields.set(name, kind);
569
- } else {
570
- existingNonFields.set(name, true);
571
- }
572
- }
573
-
574
- old_applyMemberDec(
575
- ret,
576
- base,
577
- decInfo,
578
- name,
579
- kind,
580
- isStatic,
581
- isPrivate,
582
- metadataMap,
583
- initializers,
584
- );
585
- }
586
-
587
- old_pushInitializers(ret, protoInitializers);
588
- old_pushInitializers(ret, staticInitializers);
589
- }
590
-
591
- function old_pushInitializers(ret, initializers) {
592
- if (initializers) {
593
- ret.push(function (instance) {
594
- for (var i = 0; i < initializers.length; i++) {
595
- initializers[i].call(instance);
596
- }
597
- return instance;
598
- });
599
- }
600
- }
601
-
602
- function old_applyClassDecs(ret, targetClass, metadataMap, classDecs) {
603
- if (classDecs.length > 0) {
604
- var initializers = [];
605
- var newClass = targetClass;
606
- var name = targetClass.name;
607
-
608
- for (var i = classDecs.length - 1; i >= 0; i--) {
609
- var decoratorFinishedRef = { v: false };
610
-
611
- try {
612
- var ctx = Object.assign(
613
- {
614
- kind: "class",
615
- name: name,
616
- addInitializer: old_createAddInitializerMethod(
617
- initializers,
618
- decoratorFinishedRef,
619
- ),
620
- },
621
- old_createMetadataMethodsForProperty(
622
- metadataMap,
623
- 0 /* CONSTRUCTOR */,
624
- name,
625
- decoratorFinishedRef,
626
- ),
627
- );
628
- var nextNewClass = classDecs[i](newClass, ctx);
629
- } finally {
630
- decoratorFinishedRef.v = true;
631
- }
632
-
633
- if (nextNewClass !== undefined) {
634
- old_assertValidReturnValue(10 /* CLASS */, nextNewClass);
635
- newClass = nextNewClass;
636
- }
637
- }
638
-
639
- ret.push(newClass, function () {
640
- for (var i = 0; i < initializers.length; i++) {
641
- initializers[i].call(newClass);
642
- }
643
- });
644
- }
645
- }
646
-
647
- /**
648
- Basic usage:
649
-
650
- applyDecs(
651
- Class,
652
- [
653
- // member decorators
654
- [
655
- dec, // dec or array of decs
656
- 0, // kind of value being decorated
657
- 'prop', // name of public prop on class containing the value being decorated,
658
- '#p', // the name of the private property (if is private, void 0 otherwise),
659
- ]
660
- ],
661
- [
662
- // class decorators
663
- dec1, dec2
664
- ]
665
- )
666
- ```
667
-
668
- Fully transpiled example:
669
-
670
- ```js
671
- @dec
672
- class Class {
673
- @dec
674
- a = 123;
675
-
676
- @dec
677
- #a = 123;
678
-
679
- @dec
680
- @dec2
681
- accessor b = 123;
682
-
683
- @dec
684
- accessor #b = 123;
685
-
686
- @dec
687
- c() { console.log('c'); }
688
-
689
- @dec
690
- #c() { console.log('privC'); }
691
-
692
- @dec
693
- get d() { console.log('d'); }
694
-
695
- @dec
696
- get #d() { console.log('privD'); }
697
-
698
- @dec
699
- set e(v) { console.log('e'); }
700
-
701
- @dec
702
- set #e(v) { console.log('privE'); }
703
- }
704
-
705
-
706
- // becomes
707
- let initializeInstance;
708
- let initializeClass;
709
-
710
- let initA;
711
- let initPrivA;
712
-
713
- let initB;
714
- let initPrivB, getPrivB, setPrivB;
715
-
716
- let privC;
717
- let privD;
718
- let privE;
719
-
720
- let Class;
721
- class _Class {
722
- static {
723
- let ret = applyDecs(
724
- this,
725
- [
726
- [dec, 0, 'a'],
727
- [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
728
- [[dec, dec2], 1, 'b'],
729
- [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
730
- [dec, 2, 'c'],
731
- [dec, 2, 'c', () => console.log('privC')],
732
- [dec, 3, 'd'],
733
- [dec, 3, 'd', () => console.log('privD')],
734
- [dec, 4, 'e'],
735
- [dec, 4, 'e', () => console.log('privE')],
736
- ],
737
- [
738
- dec
739
- ]
740
- )
741
-
742
- initA = ret[0];
743
-
744
- initPrivA = ret[1];
745
-
746
- initB = ret[2];
747
-
748
- initPrivB = ret[3];
749
- getPrivB = ret[4];
750
- setPrivB = ret[5];
751
-
752
- privC = ret[6];
753
-
754
- privD = ret[7];
755
-
756
- privE = ret[8];
757
-
758
- initializeInstance = ret[9];
759
-
760
- Class = ret[10]
761
-
762
- initializeClass = ret[11];
763
- }
764
-
765
- a = (initializeInstance(this), initA(this, 123));
766
-
767
- #a = initPrivA(this, 123);
768
-
769
- #bData = initB(this, 123);
770
- get b() { return this.#bData }
771
- set b(v) { this.#bData = v }
772
-
773
- #privBData = initPrivB(this, 123);
774
- get #b() { return getPrivB(this); }
775
- set #b(v) { setPrivB(this, v); }
776
-
777
- c() { console.log('c'); }
778
-
779
- #c(...args) { return privC(this, ...args) }
780
-
781
- get d() { console.log('d'); }
782
-
783
- get #d() { return privD(this); }
784
-
785
- set e(v) { console.log('e'); }
786
-
787
- set #e(v) { privE(this, v); }
788
- }
789
-
790
- initializeClass(Class);
791
- */
792
- export default function applyDecs(targetClass, memberDecs, classDecs) {
793
- var ret = [];
794
- var staticMetadataMap = {};
795
-
796
- var protoMetadataMap = {};
797
-
798
- old_applyMemberDecs(
799
- ret,
800
- targetClass,
801
- protoMetadataMap,
802
- staticMetadataMap,
803
- memberDecs,
804
- );
805
-
806
- old_convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
807
-
808
- old_applyClassDecs(ret, targetClass, staticMetadataMap, classDecs);
809
-
810
- old_convertMetadataMapToFinal(targetClass, staticMetadataMap);
811
-
812
- return ret;
813
- }