@jsenv/core 28.3.3 → 28.3.6

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.
@@ -0,0 +1,668 @@
1
+ /* @minVersion 7.19.0 */
2
+
3
+ /**
4
+ Enums are used in this file, but not assigned to vars to avoid non-hoistable values
5
+
6
+ CONSTRUCTOR = 0;
7
+ PUBLIC = 1;
8
+ PRIVATE = 2;
9
+
10
+ FIELD = 0;
11
+ ACCESSOR = 1;
12
+ METHOD = 2;
13
+ GETTER = 3;
14
+ SETTER = 4;
15
+
16
+ STATIC = 5;
17
+
18
+ CLASS = 10; // only used in assertValidReturnValue
19
+ */
20
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
21
+ return function addInitializer(initializer) {
22
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
23
+ assertCallable(initializer, "An initializer");
24
+ initializers.push(initializer);
25
+ };
26
+ }
27
+
28
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value) {
29
+ var kindStr;
30
+
31
+ switch (kind) {
32
+ case 1
33
+ /* ACCESSOR */
34
+ :
35
+ kindStr = "accessor";
36
+ break;
37
+
38
+ case 2
39
+ /* METHOD */
40
+ :
41
+ kindStr = "method";
42
+ break;
43
+
44
+ case 3
45
+ /* GETTER */
46
+ :
47
+ kindStr = "getter";
48
+ break;
49
+
50
+ case 4
51
+ /* SETTER */
52
+ :
53
+ kindStr = "setter";
54
+ break;
55
+
56
+ default:
57
+ kindStr = "field";
58
+ }
59
+
60
+ var ctx = {
61
+ kind: kindStr,
62
+ name: isPrivate ? "#" + name : name,
63
+ static: isStatic,
64
+ private: isPrivate
65
+ };
66
+ var decoratorFinishedRef = {
67
+ v: false
68
+ };
69
+
70
+ if (kind !== 0
71
+ /* FIELD */
72
+ ) {
73
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
74
+ }
75
+
76
+ var get, set;
77
+
78
+ if (kind === 0
79
+ /* FIELD */
80
+ ) {
81
+ if (isPrivate) {
82
+ get = desc.get;
83
+ set = desc.set;
84
+ } else {
85
+ get = function () {
86
+ return this[name];
87
+ };
88
+
89
+ set = function (v) {
90
+ this[name] = v;
91
+ };
92
+ }
93
+ } else if (kind === 2
94
+ /* METHOD */
95
+ ) {
96
+ get = function () {
97
+ return desc.value;
98
+ };
99
+ } else {
100
+ // replace with values that will go through the final getter and setter
101
+ if (kind === 1
102
+ /* ACCESSOR */
103
+ || kind === 3
104
+ /* GETTER */
105
+ ) {
106
+ get = function () {
107
+ return desc.get.call(this);
108
+ };
109
+ }
110
+
111
+ if (kind === 1
112
+ /* ACCESSOR */
113
+ || kind === 4
114
+ /* SETTER */
115
+ ) {
116
+ set = function (v) {
117
+ desc.set.call(this, v);
118
+ };
119
+ }
120
+ }
121
+
122
+ ctx.access = get && set ? {
123
+ get: get,
124
+ set: set
125
+ } : get ? {
126
+ get: get
127
+ } : {
128
+ set: set
129
+ };
130
+
131
+ try {
132
+ return dec(value, ctx);
133
+ } finally {
134
+ decoratorFinishedRef.v = true;
135
+ }
136
+ }
137
+
138
+ function assertNotFinished(decoratorFinishedRef, fnName) {
139
+ if (decoratorFinishedRef.v) {
140
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
141
+ }
142
+ }
143
+
144
+ function assertCallable(fn, hint) {
145
+ if (typeof fn !== "function") {
146
+ throw new TypeError(hint + " must be a function");
147
+ }
148
+ }
149
+
150
+ function assertValidReturnValue(kind, value) {
151
+ var type = typeof value;
152
+
153
+ if (kind === 1
154
+ /* ACCESSOR */
155
+ ) {
156
+ if (type !== "object" || value === null) {
157
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
158
+ }
159
+
160
+ if (value.get !== undefined) {
161
+ assertCallable(value.get, "accessor.get");
162
+ }
163
+
164
+ if (value.set !== undefined) {
165
+ assertCallable(value.set, "accessor.set");
166
+ }
167
+
168
+ if (value.init !== undefined) {
169
+ assertCallable(value.init, "accessor.init");
170
+ }
171
+ } else if (type !== "function") {
172
+ var hint;
173
+
174
+ if (kind === 0
175
+ /* FIELD */
176
+ ) {
177
+ hint = "field";
178
+ } else if (kind === 10
179
+ /* CLASS */
180
+ ) {
181
+ hint = "class";
182
+ } else {
183
+ hint = "method";
184
+ }
185
+
186
+ throw new TypeError(hint + " decorators must return a function or void 0");
187
+ }
188
+ }
189
+
190
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers) {
191
+ var decs = decInfo[0];
192
+ var desc, init, value;
193
+
194
+ if (isPrivate) {
195
+ if (kind === 0
196
+ /* FIELD */
197
+ || kind === 1
198
+ /* ACCESSOR */
199
+ ) {
200
+ desc = {
201
+ get: decInfo[3],
202
+ set: decInfo[4]
203
+ };
204
+ } else if (kind === 3
205
+ /* GETTER */
206
+ ) {
207
+ desc = {
208
+ get: decInfo[3]
209
+ };
210
+ } else if (kind === 4
211
+ /* SETTER */
212
+ ) {
213
+ desc = {
214
+ set: decInfo[3]
215
+ };
216
+ } else {
217
+ desc = {
218
+ value: decInfo[3]
219
+ };
220
+ }
221
+ } else if (kind !== 0
222
+ /* FIELD */
223
+ ) {
224
+ desc = Object.getOwnPropertyDescriptor(base, name);
225
+ }
226
+
227
+ if (kind === 1
228
+ /* ACCESSOR */
229
+ ) {
230
+ value = {
231
+ get: desc.get,
232
+ set: desc.set
233
+ };
234
+ } else if (kind === 2
235
+ /* METHOD */
236
+ ) {
237
+ value = desc.value;
238
+ } else if (kind === 3
239
+ /* GETTER */
240
+ ) {
241
+ value = desc.get;
242
+ } else if (kind === 4
243
+ /* SETTER */
244
+ ) {
245
+ value = desc.set;
246
+ }
247
+
248
+ var newValue, get, set;
249
+
250
+ if (typeof decs === "function") {
251
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, value);
252
+
253
+ if (newValue !== void 0) {
254
+ assertValidReturnValue(kind, newValue);
255
+
256
+ if (kind === 0
257
+ /* FIELD */
258
+ ) {
259
+ init = newValue;
260
+ } else if (kind === 1
261
+ /* ACCESSOR */
262
+ ) {
263
+ init = newValue.init;
264
+ get = newValue.get || value.get;
265
+ set = newValue.set || value.set;
266
+ value = {
267
+ get: get,
268
+ set: set
269
+ };
270
+ } else {
271
+ value = newValue;
272
+ }
273
+ }
274
+ } else {
275
+ for (var i = decs.length - 1; i >= 0; i--) {
276
+ var dec = decs[i];
277
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value);
278
+
279
+ if (newValue !== void 0) {
280
+ assertValidReturnValue(kind, newValue);
281
+ var newInit;
282
+
283
+ if (kind === 0
284
+ /* FIELD */
285
+ ) {
286
+ newInit = newValue;
287
+ } else if (kind === 1
288
+ /* ACCESSOR */
289
+ ) {
290
+ newInit = newValue.init;
291
+ get = newValue.get || value.get;
292
+ set = newValue.set || value.set;
293
+ value = {
294
+ get: get,
295
+ set: set
296
+ };
297
+ } else {
298
+ value = newValue;
299
+ }
300
+
301
+ if (newInit !== void 0) {
302
+ if (init === void 0) {
303
+ init = newInit;
304
+ } else if (typeof init === "function") {
305
+ init = [init, newInit];
306
+ } else {
307
+ init.push(newInit);
308
+ }
309
+ }
310
+ }
311
+ }
312
+ }
313
+
314
+ if (kind === 0
315
+ /* FIELD */
316
+ || kind === 1
317
+ /* ACCESSOR */
318
+ ) {
319
+ if (init === void 0) {
320
+ // If the initializer was void 0, sub in a dummy initializer
321
+ init = function (instance, init) {
322
+ return init;
323
+ };
324
+ } else if (typeof init !== "function") {
325
+ var ownInitializers = init;
326
+
327
+ init = function (instance, init) {
328
+ var value = init;
329
+
330
+ for (var i = 0; i < ownInitializers.length; i++) {
331
+ value = ownInitializers[i].call(instance, value);
332
+ }
333
+
334
+ return value;
335
+ };
336
+ } else {
337
+ var originalInitializer = init;
338
+
339
+ init = function (instance, init) {
340
+ return originalInitializer.call(instance, init);
341
+ };
342
+ }
343
+
344
+ ret.push(init);
345
+ }
346
+
347
+ if (kind !== 0
348
+ /* FIELD */
349
+ ) {
350
+ if (kind === 1
351
+ /* ACCESSOR */
352
+ ) {
353
+ desc.get = value.get;
354
+ desc.set = value.set;
355
+ } else if (kind === 2
356
+ /* METHOD */
357
+ ) {
358
+ desc.value = value;
359
+ } else if (kind === 3
360
+ /* GETTER */
361
+ ) {
362
+ desc.get = value;
363
+ } else if (kind === 4
364
+ /* SETTER */
365
+ ) {
366
+ desc.set = value;
367
+ }
368
+
369
+ if (isPrivate) {
370
+ if (kind === 1
371
+ /* ACCESSOR */
372
+ ) {
373
+ ret.push(function (instance, args) {
374
+ return value.get.call(instance, args);
375
+ });
376
+ ret.push(function (instance, args) {
377
+ return value.set.call(instance, args);
378
+ });
379
+ } else if (kind === 2
380
+ /* METHOD */
381
+ ) {
382
+ ret.push(value);
383
+ } else {
384
+ ret.push(function (instance, args) {
385
+ return value.call(instance, args);
386
+ });
387
+ }
388
+ } else {
389
+ Object.defineProperty(base, name, desc);
390
+ }
391
+ }
392
+ }
393
+
394
+ function applyMemberDecs(ret, Class, decInfos) {
395
+ var protoInitializers;
396
+ var staticInitializers;
397
+ var existingProtoNonFields = new Map();
398
+ var existingStaticNonFields = new Map();
399
+
400
+ for (var i = 0; i < decInfos.length; i++) {
401
+ var decInfo = decInfos[i]; // skip computed property names
402
+
403
+ if (!Array.isArray(decInfo)) continue;
404
+ var kind = decInfo[1];
405
+ var name = decInfo[2];
406
+ var isPrivate = decInfo.length > 3;
407
+ var isStatic = kind >= 5;
408
+ /* STATIC */
409
+
410
+ var base;
411
+ var initializers;
412
+
413
+ if (isStatic) {
414
+ base = Class;
415
+ kind = kind - 5
416
+ /* STATIC */
417
+ ; // initialize staticInitializers when we see a non-field static member
418
+
419
+ if (kind !== 0
420
+ /* FIELD */
421
+ ) {
422
+ staticInitializers = staticInitializers || [];
423
+ initializers = staticInitializers;
424
+ }
425
+ } else {
426
+ base = Class.prototype; // initialize protoInitializers when we see a non-field member
427
+
428
+ if (kind !== 0
429
+ /* FIELD */
430
+ ) {
431
+ protoInitializers = protoInitializers || [];
432
+ initializers = protoInitializers;
433
+ }
434
+ }
435
+
436
+ if (kind !== 0
437
+ /* FIELD */
438
+ && !isPrivate) {
439
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
440
+ var existingKind = existingNonFields.get(name) || 0;
441
+
442
+ if (existingKind === true || existingKind === 3
443
+ /* GETTER */
444
+ && kind !== 4
445
+ /* SETTER */
446
+ || existingKind === 4
447
+ /* SETTER */
448
+ && kind !== 3
449
+ /* GETTER */
450
+ ) {
451
+ 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);
452
+ } else if (!existingKind && kind > 2
453
+ /* METHOD */
454
+ ) {
455
+ existingNonFields.set(name, kind);
456
+ } else {
457
+ existingNonFields.set(name, true);
458
+ }
459
+ }
460
+
461
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);
462
+ }
463
+
464
+ pushInitializers(ret, protoInitializers);
465
+ pushInitializers(ret, staticInitializers);
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
+
475
+ return instance;
476
+ });
477
+ }
478
+ }
479
+
480
+ function applyClassDecs(ret, targetClass, classDecs) {
481
+ if (classDecs.length > 0) {
482
+ var initializers = [];
483
+ var newClass = targetClass;
484
+ var name = targetClass.name;
485
+
486
+ for (var i = classDecs.length - 1; i >= 0; i--) {
487
+ var decoratorFinishedRef = {
488
+ v: false
489
+ };
490
+
491
+ try {
492
+ var nextNewClass = classDecs[i](newClass, {
493
+ kind: "class",
494
+ name: name,
495
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)
496
+ });
497
+ } finally {
498
+ decoratorFinishedRef.v = true;
499
+ }
500
+
501
+ if (nextNewClass !== undefined) {
502
+ assertValidReturnValue(10
503
+ /* CLASS */
504
+ , nextNewClass);
505
+ newClass = nextNewClass;
506
+ }
507
+ }
508
+
509
+ ret.push(newClass, function () {
510
+ for (var i = 0; i < initializers.length; i++) {
511
+ initializers[i].call(newClass);
512
+ }
513
+ });
514
+ }
515
+ }
516
+ /**
517
+ Basic usage:
518
+
519
+ applyDecs(
520
+ Class,
521
+ [
522
+ // member decorators
523
+ [
524
+ dec, // dec or array of decs
525
+ 0, // kind of value being decorated
526
+ 'prop', // name of public prop on class containing the value being decorated,
527
+ '#p', // the name of the private property (if is private, void 0 otherwise),
528
+ ]
529
+ ],
530
+ [
531
+ // class decorators
532
+ dec1, dec2
533
+ ]
534
+ )
535
+ ```
536
+
537
+ Fully transpiled example:
538
+
539
+ ```js
540
+ @dec
541
+ class Class {
542
+ @dec
543
+ a = 123;
544
+
545
+ @dec
546
+ #a = 123;
547
+
548
+ @dec
549
+ @dec2
550
+ accessor b = 123;
551
+
552
+ @dec
553
+ accessor #b = 123;
554
+
555
+ @dec
556
+ c() { console.log('c'); }
557
+
558
+ @dec
559
+ #c() { console.log('privC'); }
560
+
561
+ @dec
562
+ get d() { console.log('d'); }
563
+
564
+ @dec
565
+ get #d() { console.log('privD'); }
566
+
567
+ @dec
568
+ set e(v) { console.log('e'); }
569
+
570
+ @dec
571
+ set #e(v) { console.log('privE'); }
572
+ }
573
+
574
+
575
+ // becomes
576
+ let initializeInstance;
577
+ let initializeClass;
578
+
579
+ let initA;
580
+ let initPrivA;
581
+
582
+ let initB;
583
+ let initPrivB, getPrivB, setPrivB;
584
+
585
+ let privC;
586
+ let privD;
587
+ let privE;
588
+
589
+ let Class;
590
+ class _Class {
591
+ static {
592
+ let ret = applyDecs(
593
+ this,
594
+ [
595
+ [dec, 0, 'a'],
596
+ [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
597
+ [[dec, dec2], 1, 'b'],
598
+ [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
599
+ [dec, 2, 'c'],
600
+ [dec, 2, 'c', () => console.log('privC')],
601
+ [dec, 3, 'd'],
602
+ [dec, 3, 'd', () => console.log('privD')],
603
+ [dec, 4, 'e'],
604
+ [dec, 4, 'e', () => console.log('privE')],
605
+ ],
606
+ [
607
+ dec
608
+ ]
609
+ )
610
+
611
+ initA = ret[0];
612
+
613
+ initPrivA = ret[1];
614
+
615
+ initB = ret[2];
616
+
617
+ initPrivB = ret[3];
618
+ getPrivB = ret[4];
619
+ setPrivB = ret[5];
620
+
621
+ privC = ret[6];
622
+
623
+ privD = ret[7];
624
+
625
+ privE = ret[8];
626
+
627
+ initializeInstance = ret[9];
628
+
629
+ Class = ret[10]
630
+
631
+ initializeClass = ret[11];
632
+ }
633
+
634
+ a = (initializeInstance(this), initA(this, 123));
635
+
636
+ #a = initPrivA(this, 123);
637
+
638
+ #bData = initB(this, 123);
639
+ get b() { return this.#bData }
640
+ set b(v) { this.#bData = v }
641
+
642
+ #privBData = initPrivB(this, 123);
643
+ get #b() { return getPrivB(this); }
644
+ set #b(v) { setPrivB(this, v); }
645
+
646
+ c() { console.log('c'); }
647
+
648
+ #c(...args) { return privC(this, ...args) }
649
+
650
+ get d() { console.log('d'); }
651
+
652
+ get #d() { return privD(this); }
653
+
654
+ set e(v) { console.log('e'); }
655
+
656
+ set #e(v) { privE(this, v); }
657
+ }
658
+
659
+ initializeClass(Class);
660
+ */
661
+
662
+
663
+ export default function applyDecs2203(targetClass, memberDecs, classDecs) {
664
+ var ret = [];
665
+ applyMemberDecs(ret, targetClass, memberDecs);
666
+ applyClassDecs(ret, targetClass, classDecs);
667
+ return ret;
668
+ }
@@ -1,6 +1,9 @@
1
- export default function _asyncGeneratorDelegate(inner, awaitWrap) {
1
+ /* @minVersion 7.0.0-beta.0 */
2
+ import OverloadYield from "../overloadYield/overloadYield.js";
3
+ export default function _asyncGeneratorDelegate(inner) {
2
4
  var iter = {},
3
- waiting = false;
5
+ // See the comment in AsyncGenerator to understand what this is.
6
+ waiting = false;
4
7
 
5
8
  function pump(key, value) {
6
9
  waiting = true;
@@ -9,7 +12,9 @@ export default function _asyncGeneratorDelegate(inner, awaitWrap) {
9
12
  });
10
13
  return {
11
14
  done: false,
12
- value: awaitWrap(value)
15
+ value: new OverloadYield(value,
16
+ /* kind: delegate */
17
+ 1)
13
18
  };
14
19
  }
15
20
 
@@ -1,4 +1,6 @@
1
- import AwaitValue from "../AwaitValue/AwaitValue.js";
2
- export default function (value) {
3
- return new AwaitValue(value);
1
+ import OverloadYield from "../overloadYield/overloadYield.js";
2
+ export default function _awaitAsyncGenerator(value) {
3
+ return new OverloadYield(value,
4
+ /* kind: await */
5
+ 0);
4
6
  }
@@ -0,0 +1,11 @@
1
+ /* @minVersion 7.18.14 */
2
+
3
+ /*
4
+ * 'kind' is an enum:
5
+ * 0 => This yield was an await expression
6
+ * 1 => This yield comes from yield*
7
+ */
8
+ export default function _OverloadYield(value, kind) {
9
+ this.v = value;
10
+ this.k = kind;
11
+ }