@jsenv/core 28.3.4 → 28.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.
@@ -1,4 +1,5 @@
1
- import AwaitValue from "../AwaitValue/AwaitValue.js";
1
+ /* @minVersion 7.0.0-beta.0 */
2
+ import OverloadYield from "../overloadYield/overloadYield.js";
2
3
  export default function AsyncGenerator(gen) {
3
4
  var front, back;
4
5
 
@@ -25,11 +26,30 @@ export default function AsyncGenerator(gen) {
25
26
  try {
26
27
  var result = gen[key](arg);
27
28
  var value = result.value;
28
- var wrappedAwait = value instanceof AwaitValue;
29
- Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {
30
- if (wrappedAwait) {
31
- resume(key === "return" ? "return" : "next", arg);
32
- return;
29
+ var overloaded = value instanceof OverloadYield;
30
+ Promise.resolve(overloaded ? value.v : value).then(function (arg) {
31
+ if (overloaded) {
32
+ // Overloaded yield requires calling into the generator twice:
33
+ // - first we get the iterator result wrapped in a promise
34
+ // (the gen[key](arg) call above)
35
+ // - then we await it (the Promise.resolve call above)
36
+ // - then we give the result back to the iterator, so that it can:
37
+ // * if it was an await, use its result
38
+ // * if it was a yield*, possibly return the `done: true` signal
39
+ // so that yield* knows that the iterator is finished.
40
+ // This needs to happen in the second call, because in the
41
+ // first one `done: true` was hidden in the promise and thus
42
+ // not visible to the (sync) yield*.
43
+ // The other part of this implementation is in asyncGeneratorDelegate.
44
+ var nextKey = key === "return" ? "return" : "next";
45
+
46
+ if (!value.k || arg.done) {
47
+ // await or end of yield*
48
+ return resume(nextKey, arg);
49
+ } else {
50
+ // yield*, not done
51
+ arg = gen[nextKey](arg).value;
52
+ }
33
53
  }
34
54
 
35
55
  settle(result.done ? "return" : "normal", arg);
@@ -1,4 +1,9 @@
1
- /* @minVersion 7.16.6 */
1
+ /* @minVersion 7.17.8 */
2
+
3
+ /**
4
+ * NOTE: This is an old version of the helper, used for 2021-12 decorators.
5
+ * Updates should be done in applyDecs2203.js.
6
+ */
2
7
 
3
8
  /**
4
9
  Enums are used in this file, but not assigned to vars to avoid non-hoistable values
@@ -14,14 +19,14 @@
14
19
  SETTER = 4;
15
20
 
16
21
  STATIC = 5;
22
+
23
+ CLASS = 10; // only used in assertValidReturnValue
17
24
  */
18
- function createMetadataMethodsForProperty(metadataMap, kind, property) {
25
+ function old_createMetadataMethodsForProperty(metadataMap, kind, property, decoratorFinishedRef) {
19
26
  return {
20
- getMetadata(key) {
21
- if (typeof key !== "symbol") {
22
- throw new TypeError("Metadata keys must be symbols, received: " + key);
23
- }
24
-
27
+ getMetadata: function (key) {
28
+ old_assertNotFinished(decoratorFinishedRef, "getMetadata");
29
+ old_assertMetadataKey(key);
25
30
  var metadataForKey = metadataMap[key];
26
31
  if (metadataForKey === void 0) return void 0;
27
32
 
@@ -45,12 +50,9 @@ function createMetadataMethodsForProperty(metadataMap, kind, property) {
45
50
  return metadataForKey.constructor;
46
51
  }
47
52
  },
48
-
49
- setMetadata(key, value) {
50
- if (typeof key !== "symbol") {
51
- throw new TypeError("Metadata keys must be symbols, received: " + key);
52
- }
53
-
53
+ setMetadata: function (key, value) {
54
+ old_assertNotFinished(decoratorFinishedRef, "setMetadata");
55
+ old_assertMetadataKey(key);
54
56
  var metadataForKey = metadataMap[key];
55
57
 
56
58
  if (metadataForKey === void 0) {
@@ -81,11 +83,10 @@ function createMetadataMethodsForProperty(metadataMap, kind, property) {
81
83
  metadataForKey.constructor = value;
82
84
  }
83
85
  }
84
-
85
86
  };
86
87
  }
87
88
 
88
- function convertMetadataMapToFinal(obj, metadataMap) {
89
+ function old_convertMetadataMapToFinal(obj, metadataMap) {
89
90
  var parentMetadataMap = obj[Symbol.metadata || Symbol.for("Symbol.metadata")];
90
91
  var metadataKeys = Object.getOwnPropertySymbols(metadataMap);
91
92
  if (metadataKeys.length === 0) return;
@@ -126,14 +127,15 @@ function convertMetadataMapToFinal(obj, metadataMap) {
126
127
  obj[Symbol.metadata || Symbol.for("Symbol.metadata")] = metadataMap;
127
128
  }
128
129
 
129
- function createAddInitializerMethod(initializers) {
130
+ function old_createAddInitializerMethod(initializers, decoratorFinishedRef) {
130
131
  return function addInitializer(initializer) {
131
- assertValidInitializer(initializer);
132
+ old_assertNotFinished(decoratorFinishedRef, "addInitializer");
133
+ old_assertCallable(initializer, "An initializer");
132
134
  initializers.push(initializer);
133
135
  };
134
136
  }
135
137
 
136
- function memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate) {
138
+ function old_memberDec(dec, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value) {
137
139
  var kindStr;
138
140
 
139
141
  switch (kind) {
@@ -171,11 +173,14 @@ function memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStati
171
173
  isStatic: isStatic,
172
174
  isPrivate: isPrivate
173
175
  };
176
+ var decoratorFinishedRef = {
177
+ v: false
178
+ };
174
179
 
175
180
  if (kind !== 0
176
181
  /* FIELD */
177
182
  ) {
178
- ctx.addInitializer = createAddInitializerMethod(initializers);
183
+ ctx.addInitializer = old_createAddInitializerMethod(initializers, decoratorFinishedRef);
179
184
  }
180
185
 
181
186
  var metadataKind, metadataName;
@@ -229,36 +234,86 @@ function memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStati
229
234
  metadataName = name;
230
235
  }
231
236
 
232
- return Object.assign(ctx, createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName));
237
+ try {
238
+ return dec(value, Object.assign(ctx, old_createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName, decoratorFinishedRef)));
239
+ } finally {
240
+ decoratorFinishedRef.v = true;
241
+ }
242
+ }
243
+
244
+ function old_assertNotFinished(decoratorFinishedRef, fnName) {
245
+ if (decoratorFinishedRef.v) {
246
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
247
+ }
248
+ }
249
+
250
+ function old_assertMetadataKey(key) {
251
+ if (typeof key !== "symbol") {
252
+ throw new TypeError("Metadata keys must be symbols, received: " + key);
253
+ }
233
254
  }
234
255
 
235
- function assertValidInitializer(initializer) {
236
- if (typeof initializer !== "function") {
237
- throw new Error("initializers must be functions");
256
+ function old_assertCallable(fn, hint) {
257
+ if (typeof fn !== "function") {
258
+ throw new TypeError(hint + " must be a function");
238
259
  }
239
260
  }
240
261
 
241
- function assertValidReturnValue(kind, value) {
262
+ function old_assertValidReturnValue(kind, value) {
242
263
  var type = typeof value;
243
264
 
244
265
  if (kind === 1
245
266
  /* ACCESSOR */
246
267
  ) {
247
268
  if (type !== "object" || value === null) {
248
- throw new Error("accessor decorators must return an object with get, set, or initializer properties or void 0");
269
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
270
+ }
271
+
272
+ if (value.get !== undefined) {
273
+ old_assertCallable(value.get, "accessor.get");
274
+ }
275
+
276
+ if (value.set !== undefined) {
277
+ old_assertCallable(value.set, "accessor.set");
278
+ }
279
+
280
+ if (value.init !== undefined) {
281
+ old_assertCallable(value.init, "accessor.init");
282
+ }
283
+
284
+ if (value.initializer !== undefined) {
285
+ old_assertCallable(value.initializer, "accessor.initializer");
249
286
  }
250
287
  } else if (type !== "function") {
288
+ var hint;
289
+
251
290
  if (kind === 0
252
291
  /* FIELD */
253
292
  ) {
254
- throw new Error("field decorators must return a initializer function or void 0");
293
+ hint = "field";
294
+ } else if (kind === 10
295
+ /* CLASS */
296
+ ) {
297
+ hint = "class";
255
298
  } else {
256
- throw new Error("method decorators must return a function or void 0");
299
+ hint = "method";
257
300
  }
301
+
302
+ throw new TypeError(hint + " decorators must return a function or void 0");
303
+ }
304
+ }
305
+
306
+ function old_getInit(desc) {
307
+ var initializer;
308
+
309
+ if ((initializer = desc.init) == null && (initializer = desc.initializer) && typeof console !== "undefined") {
310
+ console.warn(".initializer has been renamed to .init as of March 2022");
258
311
  }
312
+
313
+ return initializer;
259
314
  }
260
315
 
261
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {
316
+ function old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {
262
317
  var decs = decInfo[0];
263
318
  var desc, initializer, value;
264
319
 
@@ -316,14 +371,13 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, met
316
371
  value = desc.set;
317
372
  }
318
373
 
319
- var ctx = memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate);
320
374
  var newValue, get, set;
321
375
 
322
376
  if (typeof decs === "function") {
323
- newValue = decs(value, ctx);
377
+ newValue = old_memberDec(decs, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value);
324
378
 
325
379
  if (newValue !== void 0) {
326
- assertValidReturnValue(kind, newValue);
380
+ old_assertValidReturnValue(kind, newValue);
327
381
 
328
382
  if (kind === 0
329
383
  /* FIELD */
@@ -332,7 +386,7 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, met
332
386
  } else if (kind === 1
333
387
  /* ACCESSOR */
334
388
  ) {
335
- initializer = newValue.initializer;
389
+ initializer = old_getInit(newValue);
336
390
  get = newValue.get || value.get;
337
391
  set = newValue.set || value.set;
338
392
  value = {
@@ -344,12 +398,12 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, met
344
398
  }
345
399
  }
346
400
  } else {
347
- for (var i = 0; i < decs.length; i++) {
401
+ for (var i = decs.length - 1; i >= 0; i--) {
348
402
  var dec = decs[i];
349
- newValue = dec(value, ctx);
403
+ newValue = old_memberDec(dec, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value);
350
404
 
351
405
  if (newValue !== void 0) {
352
- assertValidReturnValue(kind, newValue);
406
+ old_assertValidReturnValue(kind, newValue);
353
407
  var newInit;
354
408
 
355
409
  if (kind === 0
@@ -359,7 +413,7 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, met
359
413
  } else if (kind === 1
360
414
  /* ACCESSOR */
361
415
  ) {
362
- newInit = newValue.initializer;
416
+ newInit = old_getInit(newValue);
363
417
  get = newValue.get || value.get;
364
418
  set = newValue.set || value.set;
365
419
  value = {
@@ -463,7 +517,7 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, met
463
517
  }
464
518
  }
465
519
 
466
- function applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInfos) {
520
+ function old_applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInfos) {
467
521
  var protoInitializers;
468
522
  var staticInitializers;
469
523
  var existingProtoNonFields = new Map();
@@ -488,22 +542,24 @@ function applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInf
488
542
  metadataMap = staticMetadataMap;
489
543
  kind = kind - 5
490
544
  /* STATIC */
491
- ;
545
+ ; // initialize staticInitializers when we see a non-field static member
492
546
 
493
- if (!staticInitializers) {
494
- staticInitializers = [];
547
+ if (kind !== 0
548
+ /* FIELD */
549
+ ) {
550
+ staticInitializers = staticInitializers || [];
551
+ initializers = staticInitializers;
495
552
  }
496
-
497
- initializers = staticInitializers;
498
553
  } else {
499
554
  base = Class.prototype;
500
- metadataMap = protoMetadataMap;
555
+ metadataMap = protoMetadataMap; // initialize protoInitializers when we see a non-field member
501
556
 
502
- if (!protoInitializers) {
503
- protoInitializers = [];
557
+ if (kind !== 0
558
+ /* FIELD */
559
+ ) {
560
+ protoInitializers = protoInitializers || [];
561
+ initializers = protoInitializers;
504
562
  }
505
-
506
- initializers = protoInitializers;
507
563
  }
508
564
 
509
565
  if (kind !== 0
@@ -531,63 +587,62 @@ function applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInf
531
587
  }
532
588
  }
533
589
 
534
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);
535
- }
536
-
537
- if (protoInitializers) {
538
- pushInitializers(ret, protoInitializers);
590
+ old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);
539
591
  }
540
592
 
541
- if (staticInitializers) {
542
- pushInitializers(ret, staticInitializers);
543
- }
593
+ old_pushInitializers(ret, protoInitializers);
594
+ old_pushInitializers(ret, staticInitializers);
544
595
  }
545
596
 
546
- function pushInitializers(ret, initializers) {
547
- if (initializers.length > 0) {
548
- // Slice the array, which means that `addInitializer` can no longer add
549
- // additional initializers to the array
550
- initializers = initializers.slice();
597
+ function old_pushInitializers(ret, initializers) {
598
+ if (initializers) {
551
599
  ret.push(function (instance) {
552
600
  for (var i = 0; i < initializers.length; i++) {
553
- initializers[i].call(instance, instance);
601
+ initializers[i].call(instance);
554
602
  }
555
603
 
556
- return instance;
557
- });
558
- } else {
559
- ret.push(function (instance) {
560
604
  return instance;
561
605
  });
562
606
  }
563
607
  }
564
608
 
565
- function applyClassDecs(ret, targetClass, metadataMap, classDecs) {
566
- var initializers = [];
567
- var newClass = targetClass;
568
- var name = targetClass.name;
569
- var ctx = Object.assign({
570
- kind: "class",
571
- name: name,
572
- addInitializer: createAddInitializerMethod(initializers)
573
- }, createMetadataMethodsForProperty(metadataMap, 0
574
- /* CONSTRUCTOR */
575
- , name));
576
-
577
- for (var i = 0; i < classDecs.length; i++) {
578
- newClass = classDecs[i](newClass, ctx) || newClass;
579
- }
609
+ function old_applyClassDecs(ret, targetClass, metadataMap, classDecs) {
610
+ if (classDecs.length > 0) {
611
+ var initializers = [];
612
+ var newClass = targetClass;
613
+ var name = targetClass.name;
614
+
615
+ for (var i = classDecs.length - 1; i >= 0; i--) {
616
+ var decoratorFinishedRef = {
617
+ v: false
618
+ };
580
619
 
581
- ret.push(newClass);
620
+ try {
621
+ var ctx = Object.assign({
622
+ kind: "class",
623
+ name: name,
624
+ addInitializer: old_createAddInitializerMethod(initializers, decoratorFinishedRef)
625
+ }, old_createMetadataMethodsForProperty(metadataMap, 0
626
+ /* CONSTRUCTOR */
627
+ , name, decoratorFinishedRef));
628
+ var nextNewClass = classDecs[i](newClass, ctx);
629
+ } finally {
630
+ decoratorFinishedRef.v = true;
631
+ }
582
632
 
583
- if (initializers.length > 0) {
584
- ret.push(function () {
633
+ if (nextNewClass !== undefined) {
634
+ old_assertValidReturnValue(10
635
+ /* CLASS */
636
+ , nextNewClass);
637
+ newClass = nextNewClass;
638
+ }
639
+ }
640
+
641
+ ret.push(newClass, function () {
585
642
  for (var i = 0; i < initializers.length; i++) {
586
- initializers[i].call(newClass, newClass);
643
+ initializers[i].call(newClass);
587
644
  }
588
645
  });
589
- } else {
590
- ret.push(function () {});
591
646
  }
592
647
  }
593
648
  /**
@@ -740,17 +795,10 @@ function applyClassDecs(ret, targetClass, metadataMap, classDecs) {
740
795
  export default function applyDecs(targetClass, memberDecs, classDecs) {
741
796
  var ret = [];
742
797
  var staticMetadataMap = {};
743
-
744
- if (memberDecs) {
745
- var protoMetadataMap = {};
746
- applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs);
747
- convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
748
- }
749
-
750
- if (classDecs) {
751
- applyClassDecs(ret, targetClass, staticMetadataMap, classDecs);
752
- }
753
-
754
- convertMetadataMapToFinal(targetClass, staticMetadataMap);
798
+ var protoMetadataMap = {};
799
+ old_applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs);
800
+ old_convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
801
+ old_applyClassDecs(ret, targetClass, staticMetadataMap, classDecs);
802
+ old_convertMetadataMapToFinal(targetClass, staticMetadataMap);
755
803
  return ret;
756
804
  }