@jsenv/core 38.3.10 → 38.4.0

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 (118) hide show
  1. package/README.md +17 -18
  2. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +3 -3
  3. package/dist/babel_helpers/AwaitValue/AwaitValue.js +2 -2
  4. package/dist/babel_helpers/{overloadYield/overloadYield.js → OverloadYield/OverloadYield.js} +1 -1
  5. package/dist/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +23 -14
  6. package/dist/babel_helpers/applyDecs/applyDecs.js +32 -21
  7. package/dist/babel_helpers/applyDecs2203/applyDecs2203.js +549 -549
  8. package/dist/babel_helpers/applyDecs2203R/applyDecs2203R.js +27 -15
  9. package/dist/babel_helpers/applyDecs2301/applyDecs2301.js +29 -18
  10. package/dist/babel_helpers/applyDecs2305/applyDecs2305.js +362 -541
  11. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +4 -4
  12. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +2 -2
  13. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +3 -3
  14. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +5 -3
  15. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +2 -2
  16. package/dist/babel_helpers/asyncIterator/asyncIterator.js +1 -1
  17. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +17 -17
  18. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +2 -2
  19. package/dist/babel_helpers/callSuper/callSuper.js +25 -0
  20. package/dist/babel_helpers/checkInRHS/checkInRHS.js +10 -8
  21. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +9 -6
  22. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +2 -2
  23. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +3 -3
  24. package/dist/babel_helpers/classCallCheck/classCallCheck.js +1 -1
  25. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -2
  26. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +7 -2
  27. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +9 -3
  28. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +3 -1
  29. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +4 -4
  30. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +4 -4
  31. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +2 -2
  32. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +2 -2
  33. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +5 -5
  34. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +2 -2
  35. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +1 -1
  36. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +11 -7
  37. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +7 -7
  38. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +8 -4
  39. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +1 -1
  40. package/dist/babel_helpers/construct/construct.js +18 -14
  41. package/dist/babel_helpers/createClass/createClass.js +1 -1
  42. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +21 -20
  43. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +10 -9
  44. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +11 -11
  45. package/dist/babel_helpers/createSuper/createSuper.js +11 -11
  46. package/dist/babel_helpers/decorate/decorate.js +255 -170
  47. package/dist/babel_helpers/defaults/defaults.js +5 -5
  48. package/dist/babel_helpers/defineAccessor/defineAccessor.js +1 -1
  49. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +11 -11
  50. package/dist/babel_helpers/defineProperty/defineProperty.js +4 -4
  51. package/dist/babel_helpers/dispose/dispose.js +39 -39
  52. package/dist/babel_helpers/extends/extends.js +4 -4
  53. package/dist/babel_helpers/get/get.js +2 -2
  54. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +1 -1
  55. package/dist/babel_helpers/identity/identity.js +1 -1
  56. package/dist/babel_helpers/importDeferProxy/importDeferProxy.js +27 -27
  57. package/dist/babel_helpers/inherits/inherits.js +4 -4
  58. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +4 -4
  59. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +5 -3
  60. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +1 -1
  61. package/dist/babel_helpers/instanceof/instanceof.js +7 -3
  62. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +1 -1
  63. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +3 -1
  64. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +1 -1
  65. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +12 -14
  66. package/dist/babel_helpers/iterableToArray/iterableToArray.js +1 -1
  67. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +1 -1
  68. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +1 -1
  69. package/dist/babel_helpers/jsx/jsx.js +1 -1
  70. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +4 -4
  71. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +1 -1
  72. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +2 -2
  73. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +2 -2
  74. package/dist/babel_helpers/nullishReceiverError/nullishReceiverError.js +1 -1
  75. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +1 -1
  76. package/dist/babel_helpers/objectSpread/objectSpread.js +8 -8
  77. package/dist/babel_helpers/objectSpread2/objectSpread2.js +5 -3
  78. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +12 -12
  79. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +10 -10
  80. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +7 -5
  81. package/dist/babel_helpers/readOnlyError/readOnlyError.js +1 -1
  82. package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +1 -1
  83. package/dist/babel_helpers/set/set.js +22 -19
  84. package/dist/babel_helpers/setFunctionName/setFunctionName.js +18 -0
  85. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +7 -6
  86. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +4 -4
  87. package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -5
  88. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +5 -5
  89. package/dist/babel_helpers/superPropBase/superPropBase.js +4 -4
  90. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +2 -2
  91. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +3 -3
  92. package/dist/babel_helpers/tdz/tdz.js +1 -1
  93. package/dist/babel_helpers/temporalRef/temporalRef.js +3 -3
  94. package/dist/babel_helpers/toArray/toArray.js +5 -5
  95. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -5
  96. package/dist/babel_helpers/toPrimitive/toPrimitive.js +11 -7
  97. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +8 -4
  98. package/dist/babel_helpers/typeof/typeof.js +6 -5
  99. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +7 -7
  100. package/dist/babel_helpers/using/using.js +20 -20
  101. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +3 -3
  102. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +12 -12
  103. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +5 -3
  104. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +1 -1
  105. package/dist/js/ribbon.js +1 -1
  106. package/dist/js/ws.js +234 -146
  107. package/dist/jsenv_core.js +1365 -1211
  108. package/package.json +26 -22
  109. package/src/build/build.js +22 -14
  110. package/src/dev/start_dev_server.js +8 -21
  111. package/src/kitchen/errors.js +29 -24
  112. package/src/kitchen/kitchen.js +1 -1
  113. package/src/kitchen/url_graph/references.js +8 -0
  114. package/src/kitchen/url_graph/url_graph_report.js +5 -3
  115. package/src/plugins/plugins.js +2 -2
  116. package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +17 -7
  117. package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +10 -12
  118. package/src/plugins/ribbon/client/ribbon.js +1 -1
@@ -1,536 +1,9 @@
1
1
  /* @minVersion 7.21.0 */
2
+ /* @mangleFns */
2
3
 
3
4
  import checkInRHS from "../checkInRHS/checkInRHS.js";
4
-
5
- /**
6
- Enums are used in this file, but not assigned to vars to avoid non-hoistable values
7
-
8
- CONSTRUCTOR = 0;
9
- PUBLIC = 1;
10
- PRIVATE = 2;
11
-
12
- FIELD = 0;
13
- ACCESSOR = 1;
14
- METHOD = 2;
15
- GETTER = 3;
16
- SETTER = 4;
17
- CLASS = 5; // only used in assertValidReturnValue
18
-
19
- STATIC = 8;
20
-
21
- DECORATORS_HAVE_THIS = 16;
22
- */
23
-
24
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
25
- return function addInitializer(initializer) {
26
- assertNotFinished(decoratorFinishedRef, "addInitializer");
27
- assertCallable(initializer, "An initializer");
28
- initializers.push(initializer);
29
- };
30
- }
31
-
32
- function assertInstanceIfPrivate(has, target) {
33
- if (!has(target)) {
34
- throw new TypeError("Attempted to access private element on non-instance");
35
- }
36
- }
37
-
38
- function memberDec(
39
- dec,
40
- thisArg,
41
- name,
42
- desc,
43
- initializers,
44
- kind,
45
- isStatic,
46
- isPrivate,
47
- value,
48
- hasPrivateBrand,
49
- metadata
50
- ) {
51
- var kindStr;
52
-
53
- switch (kind) {
54
- case 1 /* ACCESSOR */:
55
- kindStr = "accessor";
56
- break;
57
- case 2 /* METHOD */:
58
- kindStr = "method";
59
- break;
60
- case 3 /* GETTER */:
61
- kindStr = "getter";
62
- break;
63
- case 4 /* SETTER */:
64
- kindStr = "setter";
65
- break;
66
- default:
67
- kindStr = "field";
68
- }
69
-
70
- var ctx = {
71
- kind: kindStr,
72
- name: isPrivate ? "#" + name : name,
73
- static: isStatic,
74
- private: isPrivate,
75
- metadata: metadata,
76
- };
77
-
78
- var decoratorFinishedRef = { v: false };
79
-
80
- if (kind !== 0 /* FIELD */) {
81
- ctx.addInitializer = createAddInitializerMethod(
82
- initializers,
83
- decoratorFinishedRef
84
- );
85
- }
86
-
87
- var get, set;
88
- if (!isPrivate && (kind === 0 /* FIELD */ || kind === 2) /* METHOD */) {
89
- get = function (target) {
90
- return target[name];
91
- };
92
- if (kind === 0 /* FIELD */) {
93
- set = function (target, v) {
94
- target[name] = v;
95
- };
96
- }
97
- } else if (kind === 2 /* METHOD */) {
98
- // Assert: isPrivate is true.
99
- get = function (target) {
100
- assertInstanceIfPrivate(hasPrivateBrand, target);
101
- return desc.value;
102
- };
103
- } else {
104
- // Assert: If kind === 0, then isPrivate is true.
105
- var t = kind === 0 /* FIELD */ || kind === 1; /* ACCESSOR */
106
- if (t || kind === 3 /* GETTER */) {
107
- if (isPrivate) {
108
- get = function (target) {
109
- assertInstanceIfPrivate(hasPrivateBrand, target);
110
- return desc.get.call(target);
111
- };
112
- } else {
113
- get = function (target) {
114
- return desc.get.call(target);
115
- };
116
- }
117
- }
118
- if (t || kind === 4 /* SETTER */) {
119
- if (isPrivate) {
120
- set = function (target, value) {
121
- assertInstanceIfPrivate(hasPrivateBrand, target);
122
- desc.set.call(target, value);
123
- };
124
- } else {
125
- set = function (target, value) {
126
- desc.set.call(target, value);
127
- };
128
- }
129
- }
130
- }
131
- var has = isPrivate
132
- ? hasPrivateBrand.bind()
133
- : function (target) {
134
- return name in target;
135
- };
136
- ctx.access =
137
- get && set
138
- ? { get: get, set: set, has: has }
139
- : get
140
- ? { get: get, has: has }
141
- : { set: set, has: has };
142
-
143
- try {
144
- return dec.call(thisArg, value, ctx);
145
- } finally {
146
- decoratorFinishedRef.v = true;
147
- }
148
- }
149
-
150
- function assertNotFinished(decoratorFinishedRef, fnName) {
151
- if (decoratorFinishedRef.v) {
152
- throw new Error(
153
- "attempted to call " + fnName + " after decoration was finished"
154
- );
155
- }
156
- }
157
-
158
- function assertCallable(fn, hint) {
159
- if (typeof fn !== "function") {
160
- throw new TypeError(hint + " must be a function");
161
- }
162
- }
163
-
164
- function assertValidReturnValue(kind, value) {
165
- var type = typeof value;
166
-
167
- if (kind === 1 /* ACCESSOR */) {
168
- if (type !== "object" || value === null) {
169
- throw new TypeError(
170
- "accessor decorators must return an object with get, set, or init properties or void 0"
171
- );
172
- }
173
- if (value.get !== undefined) {
174
- assertCallable(value.get, "accessor.get");
175
- }
176
- if (value.set !== undefined) {
177
- assertCallable(value.set, "accessor.set");
178
- }
179
- if (value.init !== undefined) {
180
- assertCallable(value.init, "accessor.init");
181
- }
182
- } else if (type !== "function") {
183
- var hint;
184
- if (kind === 0 /* FIELD */) {
185
- hint = "field";
186
- } else if (kind === 5 /* CLASS */) {
187
- hint = "class";
188
- } else {
189
- hint = "method";
190
- }
191
- throw new TypeError(hint + " decorators must return a function or void 0");
192
- }
193
- }
194
-
195
- function curryThis1(fn) {
196
- return function () {
197
- return fn(this);
198
- };
199
- }
200
- function curryThis2(fn) {
201
- return function (value) {
202
- fn(this, value);
203
- };
204
- }
205
-
206
- function applyMemberDec(
207
- ret,
208
- base,
209
- decInfo,
210
- decoratorsHaveThis,
211
- name,
212
- kind,
213
- isStatic,
214
- isPrivate,
215
- initializers,
216
- hasPrivateBrand,
217
- metadata
218
- ) {
219
- var decs = decInfo[0];
220
-
221
- if (!decoratorsHaveThis && !Array.isArray(decs)) {
222
- decs = [decs];
223
- }
224
-
225
- var desc, init, value;
226
-
227
- if (isPrivate) {
228
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
229
- desc = {
230
- get: curryThis1(decInfo[3]),
231
- set: curryThis2(decInfo[4]),
232
- };
233
- } else {
234
- if (kind === 3 /* GETTER */) {
235
- desc = {
236
- get: decInfo[3],
237
- };
238
- } else if (kind === 4 /* SETTER */) {
239
- desc = {
240
- set: decInfo[3],
241
- };
242
- } else {
243
- desc = {
244
- value: decInfo[3],
245
- };
246
- }
247
- }
248
- } else if (kind !== 0 /* FIELD */) {
249
- desc = Object.getOwnPropertyDescriptor(base, name);
250
- }
251
-
252
- if (kind === 1 /* ACCESSOR */) {
253
- value = {
254
- get: desc.get,
255
- set: desc.set,
256
- };
257
- } else if (kind === 2 /* METHOD */) {
258
- value = desc.value;
259
- } else if (kind === 3 /* GETTER */) {
260
- value = desc.get;
261
- } else if (kind === 4 /* SETTER */) {
262
- value = desc.set;
263
- }
264
-
265
- var newValue, get, set;
266
-
267
- var inc = decoratorsHaveThis ? 2 : 1;
268
-
269
- for (var i = decs.length - 1; i >= 0; i -= inc) {
270
- var dec = decs[i];
271
-
272
- newValue = memberDec(
273
- dec,
274
- decoratorsHaveThis ? decs[i - 1] : undefined,
275
- name,
276
- desc,
277
- initializers,
278
- kind,
279
- isStatic,
280
- isPrivate,
281
- value,
282
- hasPrivateBrand,
283
- metadata
284
- );
285
-
286
- if (newValue !== void 0) {
287
- assertValidReturnValue(kind, newValue);
288
- var newInit;
289
-
290
- if (kind === 0 /* FIELD */) {
291
- newInit = newValue;
292
- } else if (kind === 1 /* ACCESSOR */) {
293
- newInit = newValue.init;
294
- get = newValue.get || value.get;
295
- set = newValue.set || value.set;
296
-
297
- value = { get: get, set: set };
298
- } else {
299
- value = newValue;
300
- }
301
-
302
- if (newInit !== void 0) {
303
- if (init === void 0) {
304
- init = newInit;
305
- } else if (typeof init === "function") {
306
- init = [init, newInit];
307
- } else {
308
- init.push(newInit);
309
- }
310
- }
311
- }
312
- }
313
-
314
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
315
- if (init === void 0) {
316
- // If the initializer was void 0, sub in a dummy initializer
317
- init = function (instance, init) {
318
- return init;
319
- };
320
- } else if (typeof init !== "function") {
321
- var ownInitializers = init;
322
-
323
- init = function (instance, init) {
324
- var value = init;
325
-
326
- for (var i = ownInitializers.length - 1; i >= 0; i--) {
327
- value = ownInitializers[i].call(instance, value);
328
- }
329
-
330
- return value;
331
- };
332
- } else {
333
- var originalInitializer = init;
334
-
335
- init = function (instance, init) {
336
- return originalInitializer.call(instance, init);
337
- };
338
- }
339
-
340
- ret.push(init);
341
- }
342
-
343
- if (kind !== 0 /* FIELD */) {
344
- if (kind === 1 /* ACCESSOR */) {
345
- desc.get = value.get;
346
- desc.set = value.set;
347
- } else if (kind === 2 /* METHOD */) {
348
- desc.value = value;
349
- } else if (kind === 3 /* GETTER */) {
350
- desc.get = value;
351
- } else if (kind === 4 /* SETTER */) {
352
- desc.set = value;
353
- }
354
-
355
- if (isPrivate) {
356
- if (kind === 1 /* ACCESSOR */) {
357
- ret.push(function (instance, args) {
358
- return value.get.call(instance, args);
359
- });
360
- ret.push(function (instance, args) {
361
- return value.set.call(instance, args);
362
- });
363
- } else if (kind === 2 /* METHOD */) {
364
- ret.push(value);
365
- } else {
366
- ret.push(function (instance, args) {
367
- return value.call(instance, args);
368
- });
369
- }
370
- } else {
371
- Object.defineProperty(base, name, desc);
372
- }
373
- }
374
- }
375
-
376
- function applyMemberDecs(Class, decInfos, instanceBrand, metadata) {
377
- var ret = [];
378
- var protoInitializers;
379
- var staticInitializers;
380
- var staticBrand;
381
-
382
- var existingProtoNonFields = new Map();
383
- var existingStaticNonFields = new Map();
384
-
385
- for (var i = 0; i < decInfos.length; i++) {
386
- var decInfo = decInfos[i];
387
-
388
- // skip computed property names
389
- if (!Array.isArray(decInfo)) continue;
390
-
391
- var kind = decInfo[1];
392
- var name = decInfo[2];
393
- var isPrivate = decInfo.length > 3;
394
-
395
- var decoratorsHaveThis = kind & 16; /* DECORATORS_HAVE_THIS */
396
- var isStatic = !!(kind & 8); /* STATIC */
397
- var base;
398
- var initializers;
399
- var hasPrivateBrand = instanceBrand;
400
-
401
- kind &= 7 /* 0b111 */;
402
-
403
- if (isStatic) {
404
- base = Class;
405
- // initialize staticInitializers when we see a non-field static member
406
- if (kind !== 0 /* FIELD */) {
407
- staticInitializers = staticInitializers || [];
408
- initializers = staticInitializers;
409
- }
410
- if (isPrivate && !staticBrand) {
411
- staticBrand = function (_) {
412
- return checkInRHS(_) === Class;
413
- };
414
- }
415
- hasPrivateBrand = staticBrand;
416
- } else {
417
- base = Class.prototype;
418
- // initialize protoInitializers when we see a non-field member
419
- if (kind !== 0 /* FIELD */) {
420
- protoInitializers = protoInitializers || [];
421
- initializers = protoInitializers;
422
- }
423
- }
424
-
425
- if (kind !== 0 /* FIELD */ && !isPrivate) {
426
- var existingNonFields = isStatic
427
- ? existingStaticNonFields
428
- : existingProtoNonFields;
429
-
430
- var existingKind = existingNonFields.get(name) || 0;
431
-
432
- if (
433
- existingKind === true ||
434
- (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ ||
435
- (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */
436
- ) {
437
- throw new Error(
438
- "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: " +
439
- name
440
- );
441
- }
442
- existingNonFields.set(
443
- name,
444
- !existingKind && kind > 2 /* METHOD */ ? kind : true
445
- );
446
- }
447
-
448
- applyMemberDec(
449
- ret,
450
- base,
451
- decInfo,
452
- decoratorsHaveThis,
453
- name,
454
- kind,
455
- isStatic,
456
- isPrivate,
457
- initializers,
458
- hasPrivateBrand,
459
- metadata
460
- );
461
- }
462
-
463
- pushInitializers(ret, protoInitializers);
464
- pushInitializers(ret, staticInitializers);
465
- return ret;
466
- }
467
-
468
- function pushInitializers(ret, initializers) {
469
- if (initializers) {
470
- ret.push(function (instance) {
471
- for (var i = 0; i < initializers.length; i++) {
472
- initializers[i].call(instance);
473
- }
474
- return instance;
475
- });
476
- }
477
- }
478
-
479
- function applyClassDecs(targetClass, classDecs, decoratorsHaveThis, metadata) {
480
- if (classDecs.length) {
481
- var initializers = [];
482
- var newClass = targetClass;
483
- var name = targetClass.name;
484
-
485
- var inc = decoratorsHaveThis ? 2 : 1;
486
-
487
- for (var i = classDecs.length - 1; i >= 0; i -= inc) {
488
- var decoratorFinishedRef = { v: false };
489
-
490
- try {
491
- var nextNewClass = classDecs[i].call(
492
- decoratorsHaveThis ? classDecs[i - 1] : undefined,
493
- newClass,
494
- {
495
- kind: "class",
496
- name: name,
497
- addInitializer: createAddInitializerMethod(
498
- initializers,
499
- decoratorFinishedRef
500
- ),
501
- metadata,
502
- }
503
- );
504
- } finally {
505
- decoratorFinishedRef.v = true;
506
- }
507
-
508
- if (nextNewClass !== undefined) {
509
- assertValidReturnValue(5 /* CLASS */, nextNewClass);
510
- newClass = nextNewClass;
511
- }
512
- }
513
-
514
- return [
515
- defineMetadata(newClass, metadata),
516
- function () {
517
- for (var i = 0; i < initializers.length; i++) {
518
- initializers[i].call(newClass);
519
- }
520
- },
521
- ];
522
- }
523
- // The transformer will not emit assignment when there are no class decorators,
524
- // so we don't have to return an empty array here.
525
- }
526
-
527
- function defineMetadata(Class, metadata) {
528
- return Object.defineProperty(
529
- Class,
530
- Symbol.metadata || Symbol.for("Symbol.metadata"),
531
- { configurable: true, enumerable: true, value: metadata }
532
- );
533
- }
5
+ import setFunctionName from "../setFunctionName/setFunctionName.js";
6
+ import toPropertyKey from "../toPropertyKey/toPropertyKey.js";
534
7
 
535
8
  /**
536
9
  Basic usage:
@@ -678,33 +151,381 @@ function defineMetadata(Class, metadata) {
678
151
  initializeClass(Class);
679
152
  */
680
153
 
681
- export default function applyDecs2305(
154
+ export default /* @no-mangle */ function applyDecs2305(
682
155
  targetClass,
683
156
  memberDecs,
684
157
  classDecs,
685
158
  classDecsHaveThis,
686
159
  instanceBrand,
687
- parentClass
160
+ parentClass,
688
161
  ) {
162
+ function _bindPropCall(obj, name, before) {
163
+ return function (_this, value) {
164
+ if (before) {
165
+ before(_this);
166
+ }
167
+ return obj[name].call(_this, value);
168
+ };
169
+ }
170
+
171
+ function runInitializers(initializers, value) {
172
+ for (var i = 0; i < initializers.length; i++) {
173
+ initializers[i].call(value);
174
+ }
175
+ return value;
176
+ }
177
+
178
+ function assertCallable(fn, hint1, hint2, throwUndefined) {
179
+ if (typeof fn !== "function") {
180
+ if (throwUndefined || fn !== void 0) {
181
+ throw new TypeError(
182
+ hint1 +
183
+ " must " +
184
+ (hint2 || "be") +
185
+ " a function" +
186
+ (throwUndefined ? "" : " or undefined"),
187
+ );
188
+ }
189
+ }
190
+ return fn;
191
+ }
192
+
193
+ /* @no-mangle */
194
+ function applyDec(
195
+ Class,
196
+ decInfo,
197
+ decoratorsHaveThis,
198
+ name,
199
+ kind,
200
+ metadata,
201
+ initializers,
202
+ ret,
203
+ isStatic,
204
+ isPrivate,
205
+ isField,
206
+ isAccessor,
207
+ hasPrivateBrand,
208
+ ) {
209
+ function assertInstanceIfPrivate(target) {
210
+ if (!hasPrivateBrand(target)) {
211
+ throw new TypeError(
212
+ "Attempted to access private element on non-instance",
213
+ );
214
+ }
215
+ }
216
+
217
+ var decs = decInfo[0],
218
+ decVal = decInfo[3],
219
+ _,
220
+ isClass = !ret;
221
+
222
+ if (!isClass) {
223
+ if (!decoratorsHaveThis && !Array.isArray(decs)) {
224
+ decs = [decs];
225
+ }
226
+
227
+ var desc = {},
228
+ init = [],
229
+ key =
230
+ kind === PROP_KIND.GETTER
231
+ ? "get"
232
+ : kind === PROP_KIND.SETTER || isAccessor
233
+ ? "set"
234
+ : "value";
235
+
236
+ if (isPrivate) {
237
+ if (isField || isAccessor) {
238
+ desc = {
239
+ get: setFunctionName(
240
+ function (_this) {
241
+ return decVal(_this);
242
+ },
243
+ name,
244
+ "get",
245
+ ),
246
+ set: function (_this, value) {
247
+ decInfo[4](_this, value);
248
+ },
249
+ };
250
+ } else {
251
+ desc[key] = decVal;
252
+ }
253
+
254
+ if (!isField) {
255
+ setFunctionName(
256
+ desc[key],
257
+ name,
258
+ kind === PROP_KIND.METHOD ? "" : key,
259
+ );
260
+ }
261
+ } else if (!isField) {
262
+ desc = Object.getOwnPropertyDescriptor(Class, name);
263
+ }
264
+ }
265
+
266
+ var newValue = Class;
267
+
268
+ for (var i = decs.length - 1; i >= 0; i -= decoratorsHaveThis ? 2 : 1) {
269
+ var dec = decs[i],
270
+ decThis = decoratorsHaveThis ? decs[i - 1] : void 0;
271
+
272
+ var decoratorFinishedRef = {};
273
+ var ctx = {
274
+ kind: ["field", "accessor", "method", "getter", "setter", "class"][
275
+ kind
276
+ ],
277
+
278
+ name: name,
279
+ metadata: metadata,
280
+ addInitializer: function (decoratorFinishedRef, initializer) {
281
+ if (decoratorFinishedRef.v) {
282
+ throw new Error(
283
+ "attempted to call addInitializer after decoration was finished",
284
+ );
285
+ }
286
+ assertCallable(initializer, "An initializer", "be", true);
287
+ initializers.push(initializer);
288
+ }.bind(null, decoratorFinishedRef),
289
+ };
290
+
291
+ try {
292
+ if (isClass) {
293
+ if (
294
+ (_ = assertCallable(
295
+ dec.call(decThis, newValue, ctx),
296
+ "class decorators",
297
+ "return",
298
+ ))
299
+ ) {
300
+ newValue = _;
301
+ }
302
+ } else {
303
+ ctx.static = isStatic;
304
+ ctx.private = isPrivate;
305
+
306
+ var get, set;
307
+ if (!isPrivate) {
308
+ get = function (target) {
309
+ return target[name];
310
+ };
311
+ if (kind < PROP_KIND.METHOD || kind === PROP_KIND.SETTER) {
312
+ set = function (target, v) {
313
+ target[name] = v;
314
+ };
315
+ }
316
+ } else if (kind === PROP_KIND.METHOD) {
317
+ get = function (_this) {
318
+ assertInstanceIfPrivate(_this);
319
+ return desc.value;
320
+ };
321
+ } else {
322
+ if (kind < PROP_KIND.SETTER) {
323
+ get = _bindPropCall(desc, "get", assertInstanceIfPrivate);
324
+ }
325
+ if (kind !== PROP_KIND.GETTER) {
326
+ set = _bindPropCall(desc, "set", assertInstanceIfPrivate);
327
+ }
328
+ }
329
+
330
+ var access = (ctx.access = {
331
+ has: isPrivate
332
+ ? // @ts-expect-error no thisArg
333
+ hasPrivateBrand.bind()
334
+ : function (target) {
335
+ return name in target;
336
+ },
337
+ });
338
+ if (get) access.get = get;
339
+ if (set) access.set = set;
340
+
341
+ newValue = dec.call(
342
+ decThis,
343
+ isAccessor
344
+ ? {
345
+ get: desc.get,
346
+ set: desc.set,
347
+ }
348
+ : desc[key],
349
+ ctx,
350
+ );
351
+
352
+ if (isAccessor) {
353
+ if (typeof newValue === "object" && newValue) {
354
+ if ((_ = assertCallable(newValue.get, "accessor.get"))) {
355
+ desc.get = _;
356
+ }
357
+ if ((_ = assertCallable(newValue.set, "accessor.set"))) {
358
+ desc.set = _;
359
+ }
360
+ if ((_ = assertCallable(newValue.init, "accessor.init"))) {
361
+ init.push(_);
362
+ }
363
+ } else if (newValue !== void 0) {
364
+ throw new TypeError(
365
+ "accessor decorators must return an object with get, set, or init properties or void 0",
366
+ );
367
+ }
368
+ } else if (
369
+ assertCallable(
370
+ newValue,
371
+ (isField ? "field" : "method") + " decorators",
372
+ "return",
373
+ )
374
+ ) {
375
+ if (isField) {
376
+ init.push(newValue);
377
+ } else {
378
+ desc[key] = newValue;
379
+ }
380
+ }
381
+ }
382
+ } finally {
383
+ decoratorFinishedRef.v = true;
384
+ }
385
+ }
386
+
387
+ if (isField || isAccessor) {
388
+ ret.push(function (instance, value) {
389
+ for (var i = init.length - 1; i >= 0; i--) {
390
+ value = init[i].call(instance, value);
391
+ }
392
+ return value;
393
+ });
394
+ }
395
+
396
+ if (!isField && !isClass) {
397
+ if (isPrivate) {
398
+ if (isAccessor) {
399
+ ret.push(_bindPropCall(desc, "get"), _bindPropCall(desc, "set"));
400
+ } else {
401
+ ret.push(
402
+ kind === PROP_KIND.METHOD
403
+ ? desc[key]
404
+ : _bindPropCall.call.bind(desc[key]),
405
+ );
406
+ }
407
+ } else {
408
+ Object.defineProperty(Class, name, desc);
409
+ }
410
+ }
411
+ return newValue;
412
+ }
413
+
414
+ /* @no-mangle */
415
+ function applyMemberDecs(Class, decInfos, instanceBrand, metadata) {
416
+ var ret = [];
417
+ var protoInitializers;
418
+ var staticInitializers;
419
+ var staticBrand = function (_) {
420
+ return checkInRHS(_) === Class;
421
+ };
422
+
423
+ var existingNonFields = new Map();
424
+
425
+ function pushInitializers(initializers) {
426
+ if (initializers) {
427
+ ret.push(runInitializers.bind(null, initializers));
428
+ }
429
+ }
430
+
431
+ for (var i = 0; i < decInfos.length; i++) {
432
+ var decInfo = decInfos[i];
433
+
434
+ // skip computed property names
435
+ if (!Array.isArray(decInfo)) continue;
436
+
437
+ var kind = decInfo[1];
438
+ var name = decInfo[2];
439
+ var isPrivate = decInfo.length > 3;
440
+
441
+ var decoratorsHaveThis = kind & PROP_KIND.DECORATORS_HAVE_THIS;
442
+ var isStatic = !!(kind & PROP_KIND.STATIC);
443
+
444
+ kind &= 7; /* 0b111 */
445
+
446
+ var isField = kind === PROP_KIND.FIELD;
447
+
448
+ var key = name + "/" + isStatic;
449
+
450
+ if (!isField && !isPrivate) {
451
+ var existingKind = existingNonFields.get(key);
452
+
453
+ if (
454
+ existingKind === true ||
455
+ (existingKind === PROP_KIND.GETTER && kind !== PROP_KIND.SETTER) ||
456
+ (existingKind === PROP_KIND.SETTER && kind !== PROP_KIND.GETTER)
457
+ ) {
458
+ throw new Error(
459
+ "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: " +
460
+ name,
461
+ );
462
+ }
463
+ existingNonFields.set(key, kind > PROP_KIND.METHOD ? kind : true);
464
+ }
465
+
466
+ applyDec(
467
+ isStatic ? Class : Class.prototype,
468
+ decInfo,
469
+ decoratorsHaveThis,
470
+ isPrivate ? "#" + name : toPropertyKey(name),
471
+ kind,
472
+ metadata,
473
+ isStatic
474
+ ? (staticInitializers = staticInitializers || [])
475
+ : (protoInitializers = protoInitializers || []),
476
+ ret,
477
+ isStatic,
478
+ isPrivate,
479
+ isField,
480
+ kind === PROP_KIND.ACCESSOR,
481
+ isStatic && isPrivate ? staticBrand : instanceBrand,
482
+ );
483
+ }
484
+
485
+ pushInitializers(protoInitializers);
486
+ pushInitializers(staticInitializers);
487
+ return ret;
488
+ }
489
+
490
+ function defineMetadata(Class, metadata) {
491
+ return Object.defineProperty(
492
+ Class,
493
+ Symbol.metadata || Symbol.for("Symbol.metadata"),
494
+ { configurable: true, enumerable: true, value: metadata },
495
+ );
496
+ }
497
+
689
498
  if (arguments.length >= 6) {
690
499
  var parentMetadata =
691
500
  parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
692
501
  }
693
- var metadata = Object.create(
694
- parentMetadata === void 0 ? null : parentMetadata
695
- );
502
+ var metadata = Object.create(parentMetadata == null ? null : parentMetadata);
696
503
  var e = applyMemberDecs(targetClass, memberDecs, instanceBrand, metadata);
697
504
  if (!classDecs.length) defineMetadata(targetClass, metadata);
698
505
  return {
699
506
  e: e,
700
507
  // Lazily apply class decorations so that member init locals can be properly bound.
701
508
  get c() {
702
- return applyClassDecs(
703
- targetClass,
704
- classDecs,
705
- classDecsHaveThis,
706
- metadata
509
+ // The transformer will not emit assignment when there are no class decorators,
510
+ // so we don't have to return an empty array here.
511
+ var initializers = [];
512
+ return (
513
+ classDecs.length && [
514
+ defineMetadata(
515
+ applyDec(
516
+ targetClass,
517
+ [classDecs],
518
+ classDecsHaveThis,
519
+ targetClass.name,
520
+ PROP_KIND.CLASS,
521
+ metadata,
522
+ initializers,
523
+ ),
524
+ metadata,
525
+ ),
526
+ runInitializers.bind(null, initializers, targetClass),
527
+ ]
707
528
  );
708
529
  },
709
530
  };
710
- }
531
+ }