seroval 0.12.3 → 0.13.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 (140) hide show
  1. package/dist/cjs/development/index.cjs +1432 -958
  2. package/dist/cjs/development/index.cjs.map +3 -3
  3. package/dist/cjs/production/index.cjs +3 -3
  4. package/dist/esm/development/index.mjs +1432 -958
  5. package/dist/esm/development/index.mjs.map +3 -3
  6. package/dist/esm/production/index.mjs +3 -3
  7. package/dist/types/core/Serializer.d.ts +2 -1
  8. package/dist/types/core/Serializer.d.ts.map +1 -1
  9. package/dist/types/core/base-primitives.d.ts +12 -1
  10. package/dist/types/core/base-primitives.d.ts.map +1 -1
  11. package/dist/types/core/compat.d.ts +0 -2
  12. package/dist/types/core/compat.d.ts.map +1 -1
  13. package/dist/types/core/constants.d.ts +8 -2
  14. package/dist/types/core/constants.d.ts.map +1 -1
  15. package/dist/types/core/{tree/deserialize.d.ts → context/deserializer.d.ts} +19 -13
  16. package/dist/types/core/context/deserializer.d.ts.map +1 -0
  17. package/dist/types/core/{base → context/parser}/async.d.ts +6 -5
  18. package/dist/types/core/context/parser/async.d.ts.map +1 -0
  19. package/dist/types/core/{base → context/parser}/stream.d.ts +2 -1
  20. package/dist/types/core/context/parser/stream.d.ts.map +1 -0
  21. package/dist/types/core/{base → context/parser}/sync.d.ts +7 -9
  22. package/dist/types/core/context/parser/sync.d.ts.map +1 -0
  23. package/dist/types/core/context/parser.d.ts +27 -0
  24. package/dist/types/core/context/parser.d.ts.map +1 -0
  25. package/dist/types/core/{serializer-context.old.d.ts → context/serializer.d.ts} +21 -22
  26. package/dist/types/core/context/serializer.d.ts.map +1 -0
  27. package/dist/types/core/cross/async.d.ts +2 -2
  28. package/dist/types/core/cross/async.d.ts.map +1 -1
  29. package/dist/types/core/cross/deserializer.d.ts +9 -0
  30. package/dist/types/core/cross/deserializer.d.ts.map +1 -0
  31. package/dist/types/core/cross/index.d.ts +11 -1
  32. package/dist/types/core/cross/index.d.ts.map +1 -1
  33. package/dist/types/core/cross/parser.d.ts +6 -0
  34. package/dist/types/core/cross/parser.d.ts.map +1 -0
  35. package/dist/types/core/cross/{serialize.d.ts → serializer.d.ts} +6 -5
  36. package/dist/types/core/cross/serializer.d.ts.map +1 -0
  37. package/dist/types/core/cross/stream.d.ts +2 -2
  38. package/dist/types/core/cross/stream.d.ts.map +1 -1
  39. package/dist/types/core/cross/sync.d.ts +2 -2
  40. package/dist/types/core/cross/sync.d.ts.map +1 -1
  41. package/dist/types/core/keys.d.ts +3 -1
  42. package/dist/types/core/keys.d.ts.map +1 -1
  43. package/dist/types/core/plugin.d.ts +6 -7
  44. package/dist/types/core/plugin.d.ts.map +1 -1
  45. package/dist/types/core/special-reference.d.ts +6 -0
  46. package/dist/types/core/special-reference.d.ts.map +1 -0
  47. package/dist/types/core/tree/async.d.ts +2 -2
  48. package/dist/types/core/tree/async.d.ts.map +1 -1
  49. package/dist/types/core/tree/deserializer.d.ts +13 -0
  50. package/dist/types/core/tree/deserializer.d.ts.map +1 -0
  51. package/dist/types/core/tree/{serialize.d.ts → serializer.d.ts} +4 -4
  52. package/dist/types/core/tree/serializer.d.ts.map +1 -0
  53. package/dist/types/core/tree/sync.d.ts +2 -2
  54. package/dist/types/core/tree/sync.d.ts.map +1 -1
  55. package/dist/types/core/types.d.ts +47 -6
  56. package/dist/types/core/types.d.ts.map +1 -1
  57. package/dist/types/core/utils/assert.d.ts.map +1 -0
  58. package/dist/types/core/utils/constructors.d.ts.map +1 -0
  59. package/dist/types/core/utils/deferred.d.ts +14 -0
  60. package/dist/types/core/utils/deferred.d.ts.map +1 -0
  61. package/dist/types/core/utils/error.d.ts +5 -0
  62. package/dist/types/core/utils/error.d.ts.map +1 -0
  63. package/dist/types/core/utils/get-identifier.d.ts.map +1 -0
  64. package/dist/types/core/utils/get-object-flag.d.ts +3 -0
  65. package/dist/types/core/utils/get-object-flag.d.ts.map +1 -0
  66. package/dist/types/core/utils/is-valid-identifier.d.ts +2 -0
  67. package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -0
  68. package/dist/types/core/utils/iterator-to-sequence.d.ts +20 -0
  69. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -0
  70. package/dist/types/core/utils/promise-to-result.d.ts.map +1 -0
  71. package/dist/types/core/utils/typed-array.d.ts +4 -0
  72. package/dist/types/core/utils/typed-array.d.ts.map +1 -0
  73. package/dist/types/core/web-api.d.ts +4 -1
  74. package/dist/types/core/web-api.d.ts.map +1 -1
  75. package/package.json +2 -2
  76. package/src/core/Serializer.ts +3 -1
  77. package/src/core/base-primitives.ts +229 -1
  78. package/src/core/compat.ts +0 -2
  79. package/src/core/constants.ts +7 -2
  80. package/src/core/{tree/deserialize.ts → context/deserializer.ts} +159 -66
  81. package/src/core/{base → context/parser}/async.ts +181 -309
  82. package/src/core/{base → context/parser}/stream.ts +86 -11
  83. package/src/core/{base → context/parser}/sync.ts +120 -281
  84. package/src/core/context/parser.ts +259 -0
  85. package/src/core/{serializer-context.old.ts → context/serializer.ts} +241 -166
  86. package/src/core/cross/async.ts +2 -2
  87. package/src/core/cross/deserializer.ts +19 -0
  88. package/src/core/cross/index.ts +68 -47
  89. package/src/core/cross/parser.ts +7 -0
  90. package/src/core/cross/{serialize.ts → serializer.ts} +31 -12
  91. package/src/core/cross/stream.ts +2 -2
  92. package/src/core/cross/sync.ts +2 -2
  93. package/src/core/is-serializable.new.ts +1 -1
  94. package/src/core/keys.ts +8 -2
  95. package/src/core/plugin.ts +7 -7
  96. package/src/core/reference.ts +1 -1
  97. package/src/core/special-reference.ts +9 -0
  98. package/src/core/tree/async.ts +2 -2
  99. package/src/core/tree/deserializer.ts +31 -0
  100. package/src/core/tree/index.ts +2 -2
  101. package/src/core/tree/{serialize.ts → serializer.ts} +5 -16
  102. package/src/core/tree/sync.ts +2 -2
  103. package/src/core/types.ts +60 -7
  104. package/src/core/utils/deferred.ts +49 -0
  105. package/src/core/{shared.ts → utils/error.ts} +3 -60
  106. package/src/core/utils/get-object-flag.ts +14 -0
  107. package/src/core/utils/is-valid-identifier.ts +11 -0
  108. package/src/core/utils/iterator-to-sequence.ts +238 -0
  109. package/src/core/utils/typed-array.ts +30 -0
  110. package/src/core/web-api.ts +75 -1
  111. package/src/example.ts +0 -3
  112. package/dist/types/core/assert.d.ts.map +0 -1
  113. package/dist/types/core/base/async.d.ts.map +0 -1
  114. package/dist/types/core/base/stream.d.ts.map +0 -1
  115. package/dist/types/core/base/sync.d.ts.map +0 -1
  116. package/dist/types/core/constructors.d.ts.map +0 -1
  117. package/dist/types/core/cross/cross-parser.d.ts +0 -8
  118. package/dist/types/core/cross/cross-parser.d.ts.map +0 -1
  119. package/dist/types/core/cross/serialize.d.ts.map +0 -1
  120. package/dist/types/core/get-identifier.d.ts.map +0 -1
  121. package/dist/types/core/parser-context.d.ts +0 -23
  122. package/dist/types/core/parser-context.d.ts.map +0 -1
  123. package/dist/types/core/promise-to-result.d.ts.map +0 -1
  124. package/dist/types/core/serializer-context.old.d.ts.map +0 -1
  125. package/dist/types/core/shared.d.ts +0 -10
  126. package/dist/types/core/shared.d.ts.map +0 -1
  127. package/dist/types/core/tree/deserialize.d.ts.map +0 -1
  128. package/dist/types/core/tree/serialize.d.ts.map +0 -1
  129. package/src/core/cross/cross-parser.ts +0 -9
  130. package/src/core/parser-context.ts +0 -131
  131. package/src/core/serializer-context.new.ts +0 -1168
  132. package/src/core/tree/parser.ts +0 -45
  133. /package/dist/types/core/{assert.d.ts → utils/assert.d.ts} +0 -0
  134. /package/dist/types/core/{constructors.d.ts → utils/constructors.d.ts} +0 -0
  135. /package/dist/types/core/{get-identifier.d.ts → utils/get-identifier.d.ts} +0 -0
  136. /package/dist/types/core/{promise-to-result.d.ts → utils/promise-to-result.d.ts} +0 -0
  137. /package/src/core/{assert.ts → utils/assert.ts} +0 -0
  138. /package/src/core/{constructors.ts → utils/constructors.ts} +0 -0
  139. /package/src/core/{get-identifier.ts → utils/get-identifier.ts} +0 -0
  140. /package/src/core/{promise-to-result.ts → utils/promise-to-result.ts} +0 -0
@@ -31,10 +31,14 @@ __export(src_exports, {
31
31
  crossSerializeStream: () => crossSerializeStream,
32
32
  default: () => src_default,
33
33
  deserialize: () => deserialize,
34
+ fromCrossJSON: () => fromCrossJSON,
34
35
  fromJSON: () => fromJSON,
35
36
  getCrossReferenceHeader: () => getCrossReferenceHeader,
36
37
  serialize: () => serialize,
37
38
  serializeAsync: () => serializeAsync,
39
+ toCrossJSON: () => toCrossJSON,
40
+ toCrossJSONAsync: () => toCrossJSONAsync,
41
+ toCrossJSONStream: () => toCrossJSONStream,
38
42
  toJSON: () => toJSON,
39
43
  toJSONAsync: () => toJSONAsync
40
44
  });
@@ -49,7 +53,7 @@ var UnsupportedTypeError = class extends Error {
49
53
  }
50
54
  };
51
55
 
52
- // src/core/assert.ts
56
+ // src/core/utils/assert.ts
53
57
  function assert(cond, error) {
54
58
  if (!cond) {
55
59
  throw error;
@@ -140,7 +144,6 @@ var ERROR_CONSTRUCTOR = {
140
144
  [5 /* TypeError */]: TypeError,
141
145
  [6 /* URIError */]: URIError
142
146
  };
143
- var UNIVERSAL_SENTINEL = Symbol("why");
144
147
 
145
148
  // src/core/literals.ts
146
149
  function createConstantNode(value) {
@@ -228,9 +231,11 @@ var GLOBAL_CONTEXT_PROMISE_RESOLVE = "Ps";
228
231
  var GLOBAL_CONTEXT_PROMISE_REJECT = "Pf";
229
232
  var LOCAL_CONTEXT_STREAM_CONTROLLER = "c";
230
233
  var GLOBAL_CONTEXT_STREAM_CONSTRUCTOR = "S";
231
- var GLOBAL_CONTEXT_STREAM_EMIT = "Se";
234
+ var GLOBAL_CONTEXT_STREAM_ENQUEUE = "Se";
235
+ var GLOBAL_CONTEXT_STREAM_ERROR = "St";
236
+ var GLOBAL_CONTEXT_STREAM_CLOSE = "Sc";
232
237
  var GLOBAL_CONTEXT_API_REF = `self.${GLOBAL_CONTEXT_API}`;
233
- var GLOBAL_CONTEXT_API_SCRIPT = `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},${GLOBAL_CONTEXT_PROMISE_RESOLVE}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_RESOLVE}(d),p.status="success",p.value=d,this.uP(p)},${GLOBAL_CONTEXT_PROMISE_REJECT}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_REJECT}(d),p.status="failure",p.value=d,this.uP(p)},uS:function(s){delete s.${LOCAL_CONTEXT_STREAM_CONTROLLER}},${GLOBAL_CONTEXT_STREAM_EMIT}:function(s,t,d,c){switch(c=s.${LOCAL_CONTEXT_STREAM_CONTROLLER},t){case 0:return c.enqueue(d);case 1:return(this.uS(s),c.error(d));case 2:return(this.uS(s),c.close())}},${GLOBAL_CONTEXT_STREAM_CONSTRUCTOR}:function(s,c){return(s=new ReadableStream({start:function(x){c=x}})).${LOCAL_CONTEXT_STREAM_CONTROLLER}=c,s}}`;
238
+ var GLOBAL_CONTEXT_API_SCRIPT = `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},${GLOBAL_CONTEXT_PROMISE_RESOLVE}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_RESOLVE}(d),p.status="success",p.value=d,this.uP(p)},${GLOBAL_CONTEXT_PROMISE_REJECT}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_REJECT}(d),p.status="failure",p.value=d,this.uP(p)},uS:function(s){delete s.${LOCAL_CONTEXT_STREAM_CONTROLLER}},${GLOBAL_CONTEXT_STREAM_CLOSE}:function(s){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.close(),this.uS(s)},${GLOBAL_CONTEXT_STREAM_ERROR}:function(s,e){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.error(e),this.uS(s)},${GLOBAL_CONTEXT_STREAM_ENQUEUE}:function(s,d){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.enqueue(d)},${GLOBAL_CONTEXT_STREAM_CONSTRUCTOR}:function(s,c){return(s=new ReadableStream({start:function(x){c=x}})).${LOCAL_CONTEXT_STREAM_CONTROLLER}=c,s}}`;
234
239
  var GLOBAL_CONTEXT_R = `self.${GLOBAL_CONTEXT_REFERENCES}`;
235
240
  function getCrossReferenceHeader(id) {
236
241
  if (id == null) {
@@ -291,6 +296,87 @@ if (typeof globalThis !== void 0) {
291
296
  });
292
297
  }
293
298
 
299
+ // src/core/compat.ts
300
+ var Feature = /* @__PURE__ */ ((Feature2) => {
301
+ Feature2[Feature2["AggregateError"] = 1] = "AggregateError";
302
+ Feature2[Feature2["ArrowFunction"] = 4] = "ArrowFunction";
303
+ Feature2[Feature2["BigInt"] = 8] = "BigInt";
304
+ Feature2[Feature2["ErrorPrototypeStack"] = 16] = "ErrorPrototypeStack";
305
+ Feature2[Feature2["Map"] = 32] = "Map";
306
+ Feature2[Feature2["ObjectAssign"] = 128] = "ObjectAssign";
307
+ Feature2[Feature2["Promise"] = 256] = "Promise";
308
+ Feature2[Feature2["Set"] = 512] = "Set";
309
+ Feature2[Feature2["Symbol"] = 1024] = "Symbol";
310
+ Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
311
+ Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
312
+ Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
313
+ return Feature2;
314
+ })(Feature || {});
315
+ var ALL_ENABLED = 16383;
316
+ var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
317
+
318
+ // src/core/utils/error.ts
319
+ function getErrorConstructor(error) {
320
+ if (error instanceof EvalError) {
321
+ return 1 /* EvalError */;
322
+ }
323
+ if (error instanceof RangeError) {
324
+ return 2 /* RangeError */;
325
+ }
326
+ if (error instanceof ReferenceError) {
327
+ return 3 /* ReferenceError */;
328
+ }
329
+ if (error instanceof SyntaxError) {
330
+ return 4 /* SyntaxError */;
331
+ }
332
+ if (error instanceof TypeError) {
333
+ return 5 /* TypeError */;
334
+ }
335
+ if (error instanceof URIError) {
336
+ return 6 /* URIError */;
337
+ }
338
+ return 0 /* Error */;
339
+ }
340
+ function getErrorOptions(error, features) {
341
+ let options;
342
+ const constructor = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
343
+ if (error.name !== constructor) {
344
+ options = { name: error.name };
345
+ } else if (error.constructor.name !== constructor) {
346
+ options = { name: error.constructor.name };
347
+ }
348
+ const names = Object.getOwnPropertyNames(error);
349
+ for (let i = 0, len = names.length, name; i < len; i++) {
350
+ name = names[i];
351
+ if (name !== "name" && name !== "message") {
352
+ if (name === "stack") {
353
+ if (features & 16 /* ErrorPrototypeStack */) {
354
+ options = options || {};
355
+ options[name] = error[name];
356
+ }
357
+ } else {
358
+ options = options || {};
359
+ options[name] = error[name];
360
+ }
361
+ }
362
+ }
363
+ return options;
364
+ }
365
+
366
+ // src/core/utils/get-object-flag.ts
367
+ function getObjectFlag(obj) {
368
+ if (Object.isFrozen(obj)) {
369
+ return 3 /* Frozen */;
370
+ }
371
+ if (Object.isSealed(obj)) {
372
+ return 2 /* Sealed */;
373
+ }
374
+ if (Object.isExtensible(obj)) {
375
+ return 0 /* None */;
376
+ }
377
+ return 1 /* NonExtensible */;
378
+ }
379
+
294
380
  // src/core/base-primitives.ts
295
381
  function createNumberNode(value) {
296
382
  switch (value) {
@@ -472,29 +558,174 @@ function createPluginNode(id, tag, value) {
472
558
  o: void 0
473
559
  };
474
560
  }
561
+ function createArrayNode(id, current, parsedItems) {
562
+ return {
563
+ t: 9 /* Array */,
564
+ i: id,
565
+ s: void 0,
566
+ l: current.length,
567
+ c: void 0,
568
+ m: void 0,
569
+ p: void 0,
570
+ e: void 0,
571
+ a: parsedItems,
572
+ f: void 0,
573
+ b: void 0,
574
+ o: getObjectFlag(current)
575
+ };
576
+ }
577
+ function createBoxedNode(id, boxed) {
578
+ return {
579
+ t: 27 /* Boxed */,
580
+ i: id,
581
+ s: void 0,
582
+ l: void 0,
583
+ c: void 0,
584
+ m: void 0,
585
+ p: void 0,
586
+ e: void 0,
587
+ a: void 0,
588
+ f: boxed,
589
+ b: void 0,
590
+ o: void 0
591
+ };
592
+ }
593
+ function createTypedArrayNode(id, current, buffer) {
594
+ return {
595
+ t: 15 /* TypedArray */,
596
+ i: id,
597
+ s: void 0,
598
+ l: current.length,
599
+ c: current.constructor.name,
600
+ m: void 0,
601
+ p: void 0,
602
+ e: void 0,
603
+ a: void 0,
604
+ f: buffer,
605
+ b: current.byteOffset,
606
+ o: void 0
607
+ };
608
+ }
609
+ function createBigIntTypedArrayNode(id, current, buffer) {
610
+ return {
611
+ t: 16 /* BigIntTypedArray */,
612
+ i: id,
613
+ s: void 0,
614
+ l: current.length,
615
+ c: current.constructor.name,
616
+ m: void 0,
617
+ p: void 0,
618
+ e: void 0,
619
+ a: void 0,
620
+ f: buffer,
621
+ b: current.byteOffset,
622
+ o: void 0
623
+ };
624
+ }
625
+ function createDataViewNode(id, current, buffer) {
626
+ return {
627
+ t: 22 /* DataView */,
628
+ i: id,
629
+ s: void 0,
630
+ l: current.byteLength,
631
+ c: void 0,
632
+ m: void 0,
633
+ p: void 0,
634
+ e: void 0,
635
+ a: void 0,
636
+ f: buffer,
637
+ b: current.byteOffset,
638
+ o: void 0
639
+ };
640
+ }
641
+ function createErrorNode(id, current, options) {
642
+ return {
643
+ t: 13 /* Error */,
644
+ i: id,
645
+ s: getErrorConstructor(current),
646
+ l: void 0,
647
+ c: void 0,
648
+ m: serializeString(current.message),
649
+ p: options,
650
+ e: void 0,
651
+ a: void 0,
652
+ f: void 0,
653
+ b: void 0,
654
+ o: void 0
655
+ };
656
+ }
657
+ function createAggregateErrorNode(id, current, options) {
658
+ return {
659
+ t: 14 /* AggregateError */,
660
+ i: id,
661
+ s: getErrorConstructor(current),
662
+ l: void 0,
663
+ c: void 0,
664
+ m: serializeString(current.message),
665
+ p: options,
666
+ e: void 0,
667
+ a: void 0,
668
+ f: void 0,
669
+ b: void 0,
670
+ o: void 0
671
+ };
672
+ }
673
+ function createSetNode(id, size, items) {
674
+ return {
675
+ t: 7 /* Set */,
676
+ i: id,
677
+ s: void 0,
678
+ l: size,
679
+ c: void 0,
680
+ m: void 0,
681
+ p: void 0,
682
+ e: void 0,
683
+ a: items,
684
+ f: void 0,
685
+ b: void 0,
686
+ o: void 0
687
+ };
688
+ }
689
+ function createIteratorFactoryInstanceNode(factory, items) {
690
+ return {
691
+ t: 43 /* IteratorFactoryInstance */,
692
+ i: void 0,
693
+ s: void 0,
694
+ l: void 0,
695
+ c: void 0,
696
+ m: void 0,
697
+ p: void 0,
698
+ e: void 0,
699
+ a: [
700
+ factory,
701
+ items
702
+ ],
703
+ f: void 0,
704
+ b: void 0,
705
+ o: void 0
706
+ };
707
+ }
708
+ function createAsyncIteratorFactoryInstanceNode(factory, items) {
709
+ return {
710
+ t: 45 /* AsyncIteratorFactoryInstance */,
711
+ i: void 0,
712
+ s: void 0,
713
+ l: void 0,
714
+ c: void 0,
715
+ m: void 0,
716
+ p: void 0,
717
+ e: void 0,
718
+ a: [
719
+ factory,
720
+ items
721
+ ],
722
+ f: void 0,
723
+ b: void 0,
724
+ o: void 0
725
+ };
726
+ }
475
727
 
476
- // src/core/compat.ts
477
- var Feature = /* @__PURE__ */ ((Feature2) => {
478
- Feature2[Feature2["AggregateError"] = 1] = "AggregateError";
479
- Feature2[Feature2["ArrayPrototypeValues"] = 2] = "ArrayPrototypeValues";
480
- Feature2[Feature2["ArrowFunction"] = 4] = "ArrowFunction";
481
- Feature2[Feature2["BigInt"] = 8] = "BigInt";
482
- Feature2[Feature2["ErrorPrototypeStack"] = 16] = "ErrorPrototypeStack";
483
- Feature2[Feature2["Map"] = 32] = "Map";
484
- Feature2[Feature2["MethodShorthand"] = 64] = "MethodShorthand";
485
- Feature2[Feature2["ObjectAssign"] = 128] = "ObjectAssign";
486
- Feature2[Feature2["Promise"] = 256] = "Promise";
487
- Feature2[Feature2["Set"] = 512] = "Set";
488
- Feature2[Feature2["Symbol"] = 1024] = "Symbol";
489
- Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
490
- Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
491
- Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
492
- return Feature2;
493
- })(Feature || {});
494
- var ALL_ENABLED = 16383;
495
- var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
496
-
497
- // src/core/constructors.ts
728
+ // src/core/utils/constructors.ts
498
729
  function createRequestOptions(current, body) {
499
730
  return {
500
731
  body,
@@ -533,210 +764,399 @@ function createCustomEventOptions(current) {
533
764
  };
534
765
  }
535
766
 
536
- // src/core/parser-context.ts
537
- var BaseParserContext = class {
538
- constructor(options) {
539
- this.marked = /* @__PURE__ */ new Set();
540
- this.plugins = options.plugins;
541
- this.features = ALL_ENABLED ^ (options.disabledFeatures || 0);
542
- this.refs = options.refs || /* @__PURE__ */ new Map();
543
- }
544
- markRef(id) {
545
- this.marked.add(id);
546
- }
547
- isMarked(id) {
548
- return this.marked.has(id);
549
- }
550
- getReference(current) {
551
- const registeredID = this.refs.get(current);
552
- if (registeredID != null) {
553
- this.markRef(registeredID);
554
- return createIndexedValueNode(registeredID);
767
+ // src/core/utils/iterator-to-sequence.ts
768
+ function iteratorToSequence(source) {
769
+ const values = [];
770
+ let throwsAt = -1;
771
+ let doneAt = -1;
772
+ const iterator = source[Symbol.iterator]();
773
+ while (true) {
774
+ try {
775
+ const value = iterator.next();
776
+ values.push(value.value);
777
+ if (value.done) {
778
+ doneAt = values.length - 1;
779
+ break;
780
+ }
781
+ } catch (error) {
782
+ throwsAt = values.length;
783
+ values.push(error);
555
784
  }
556
- const id = this.refs.size;
557
- this.refs.set(current, id);
558
- if (hasReferenceID(current)) {
559
- return createReferenceNode(id, current);
785
+ }
786
+ return {
787
+ v: values,
788
+ t: throwsAt,
789
+ d: doneAt
790
+ };
791
+ }
792
+ function sequenceToIterator(sequence) {
793
+ return () => {
794
+ let index = 0;
795
+ return {
796
+ [Symbol.iterator]() {
797
+ return this;
798
+ },
799
+ next() {
800
+ if (index > sequence.d) {
801
+ return {
802
+ done: true,
803
+ value: void 0
804
+ };
805
+ }
806
+ const currentIndex = index++;
807
+ const currentItem = sequence.v[currentIndex];
808
+ if (currentIndex === sequence.t) {
809
+ throw currentItem;
810
+ }
811
+ return {
812
+ done: currentIndex === sequence.d,
813
+ value: currentItem
814
+ };
815
+ }
816
+ };
817
+ };
818
+ }
819
+ async function asyncIteratorToSequence(source) {
820
+ const values = [];
821
+ let throwsAt = -1;
822
+ let doneAt = -1;
823
+ const iterator = source[Symbol.asyncIterator]();
824
+ while (true) {
825
+ try {
826
+ const value = await iterator.next();
827
+ values.push(value.value);
828
+ if (value.done) {
829
+ doneAt = values.length - 1;
830
+ break;
831
+ }
832
+ } catch (error) {
833
+ throwsAt = values.length;
834
+ values.push(error);
560
835
  }
561
- return id;
562
836
  }
563
- getStrictReference(current) {
564
- const registeredID = this.refs.get(current);
565
- if (registeredID != null) {
566
- this.markRef(registeredID);
567
- return createIndexedValueNode(registeredID);
568
- }
569
- const id = this.refs.size;
570
- this.refs.set(current, id);
571
- return createReferenceNode(id, current);
572
- }
573
- /**
574
- * @private
575
- */
576
- isIterable(value) {
577
- if (!value || typeof value !== "object") {
578
- return false;
579
- }
580
- if (Array.isArray(value)) {
581
- return false;
582
- }
583
- const currentClass = value.constructor;
584
- const currentFeatures = this.features;
585
- if (currentFeatures & 2048 /* TypedArray */) {
586
- switch (currentClass) {
587
- case Int8Array:
588
- case Int16Array:
589
- case Int32Array:
590
- case Uint8Array:
591
- case Uint16Array:
592
- case Uint32Array:
593
- case Uint8ClampedArray:
594
- case Float32Array:
595
- case Float64Array:
596
- return false;
597
- default:
598
- break;
837
+ return {
838
+ v: values,
839
+ t: throwsAt,
840
+ d: doneAt
841
+ };
842
+ }
843
+ function sequenceToAsyncIterator(sequence) {
844
+ return () => {
845
+ let index = 0;
846
+ return {
847
+ [Symbol.asyncIterator]() {
848
+ return this;
849
+ },
850
+ async next() {
851
+ if (index > sequence.d) {
852
+ return {
853
+ done: true,
854
+ value: void 0
855
+ };
856
+ }
857
+ const currentIndex = index++;
858
+ const currentItem = sequence.v[currentIndex];
859
+ if (currentIndex === sequence.t) {
860
+ throw currentItem;
861
+ }
862
+ return Promise.resolve({
863
+ done: currentIndex === sequence.d,
864
+ value: currentItem
865
+ });
599
866
  }
600
- }
601
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
602
- switch (currentClass) {
603
- case BigInt64Array:
604
- case BigUint64Array:
605
- return false;
606
- default:
607
- break;
867
+ };
868
+ };
869
+ }
870
+ function asyncIteratorToReadableStream(source, parser) {
871
+ return new ReadableStream({
872
+ async start(controller) {
873
+ const iterator = source[Symbol.asyncIterator]();
874
+ while (parser.isAlive()) {
875
+ try {
876
+ const result = await iterator.next();
877
+ controller.enqueue([result.done ? 2 : 0, result.value]);
878
+ if (result.done) {
879
+ controller.close();
880
+ return;
881
+ }
882
+ } catch (error) {
883
+ controller.enqueue([1, error]);
884
+ }
608
885
  }
886
+ controller.close();
609
887
  }
610
- if (currentFeatures & 32 /* Map */ && currentClass === Map) {
611
- return false;
612
- }
613
- if (currentFeatures & 512 /* Set */ && currentClass === Set) {
614
- return false;
615
- }
616
- if (currentFeatures & 8192 /* WebAPI */) {
617
- if (typeof Headers !== "undefined" && currentClass === Headers) {
618
- return false;
888
+ });
889
+ }
890
+ function readableStreamToAsyncIterator(source) {
891
+ let current = source;
892
+ return () => {
893
+ const [left, right] = current.tee();
894
+ const clone = left;
895
+ current = right;
896
+ const reader = clone.getReader();
897
+ return {
898
+ [Symbol.asyncIterator]() {
899
+ return this;
900
+ },
901
+ async next() {
902
+ const result = await reader.read();
903
+ if (result.done) {
904
+ return {
905
+ done: true,
906
+ value: void 0
907
+ };
908
+ }
909
+ const [status, value] = result.value;
910
+ if (status === 1) {
911
+ throw value;
912
+ }
913
+ return {
914
+ done: status === 2,
915
+ value
916
+ };
619
917
  }
620
- if (typeof File !== "undefined" && currentClass === File) {
621
- return false;
918
+ };
919
+ };
920
+ }
921
+ async function readableStreamToSequence(stream) {
922
+ const values = [];
923
+ let throwsAt = -1;
924
+ let doneAt = -1;
925
+ const iterator = stream.getReader();
926
+ while (true) {
927
+ try {
928
+ const value = await iterator.read();
929
+ values.push(value.value);
930
+ if (value.done) {
931
+ doneAt = values.length - 1;
932
+ break;
622
933
  }
934
+ } catch (error) {
935
+ throwsAt = values.length;
936
+ doneAt = throwsAt;
937
+ values.push(error);
938
+ break;
623
939
  }
624
- const currentPlugins = this.plugins;
625
- if (currentPlugins) {
626
- for (let i = 0, len = currentPlugins.length; i < len; i++) {
627
- const plugin = currentPlugins[i];
628
- if (plugin.test(value) && plugin.isIterable && plugin.isIterable(value)) {
629
- return false;
630
- }
940
+ }
941
+ return {
942
+ v: values,
943
+ t: throwsAt,
944
+ d: doneAt
945
+ };
946
+ }
947
+ function sequenceToReadableStream(sequence) {
948
+ return new ReadableStream({
949
+ start(controller) {
950
+ for (let i = 0; i < sequence.d; i++) {
951
+ controller.enqueue(sequence.v[i]);
952
+ }
953
+ if (sequence.t === -1) {
954
+ controller.close();
955
+ } else {
956
+ controller.error(sequence.v[sequence.t]);
631
957
  }
632
958
  }
633
- if (currentFeatures & 1024 /* Symbol */) {
634
- return Symbol.iterator in value;
635
- }
636
- return false;
637
- }
638
- };
639
-
640
- // src/core/promise-to-result.ts
641
- async function promiseToResult(current) {
642
- try {
643
- return [1, await current];
644
- } catch (e) {
645
- return [0, e];
646
- }
959
+ });
647
960
  }
648
961
 
649
- // src/core/shared.ts
650
- function getErrorConstructor(error) {
651
- if (error instanceof EvalError) {
652
- return 1 /* EvalError */;
962
+ // src/core/special-reference.ts
963
+ var MAP_SENTINEL = {};
964
+ var ITERATOR = {};
965
+ var ASYNC_ITERATOR = {};
966
+ var READABLE_STREAM = {};
967
+ var UNIVERSAL_SENTINEL = {};
968
+
969
+ // src/core/context/parser.ts
970
+ var BaseParserContext = class {
971
+ constructor(options) {
972
+ this.marked = /* @__PURE__ */ new Set();
973
+ this.plugins = options.plugins;
974
+ this.features = ALL_ENABLED ^ (options.disabledFeatures || 0);
975
+ this.refs = options.refs || /* @__PURE__ */ new Map();
653
976
  }
654
- if (error instanceof RangeError) {
655
- return 2 /* RangeError */;
977
+ markRef(id) {
978
+ this.marked.add(id);
656
979
  }
657
- if (error instanceof ReferenceError) {
658
- return 3 /* ReferenceError */;
980
+ isMarked(id) {
981
+ return this.marked.has(id);
659
982
  }
660
- if (error instanceof SyntaxError) {
661
- return 4 /* SyntaxError */;
983
+ getReference(current) {
984
+ const registeredID = this.refs.get(current);
985
+ if (registeredID != null) {
986
+ this.markRef(registeredID);
987
+ return createIndexedValueNode(registeredID);
988
+ }
989
+ const id = this.refs.size;
990
+ this.refs.set(current, id);
991
+ if (hasReferenceID(current)) {
992
+ return createReferenceNode(id, current);
993
+ }
994
+ return id;
662
995
  }
663
- if (error instanceof TypeError) {
664
- return 5 /* TypeError */;
996
+ getStrictReference(current) {
997
+ const registeredID = this.refs.get(current);
998
+ if (registeredID != null) {
999
+ this.markRef(registeredID);
1000
+ return createIndexedValueNode(registeredID);
1001
+ }
1002
+ const id = this.refs.size;
1003
+ this.refs.set(current, id);
1004
+ return createReferenceNode(id, current);
665
1005
  }
666
- if (error instanceof URIError) {
667
- return 6 /* URIError */;
1006
+ // eslint-disable-next-line @typescript-eslint/ban-types
1007
+ parseFunction(current) {
1008
+ assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
1009
+ return this.getStrictReference(current);
668
1010
  }
669
- return 0 /* Error */;
670
- }
671
- function getTypedArrayConstructor(name) {
672
- switch (name) {
673
- case "Int8Array":
674
- return Int8Array;
675
- case "Int16Array":
676
- return Int16Array;
677
- case "Int32Array":
678
- return Int32Array;
679
- case "Uint8Array":
680
- return Uint8Array;
681
- case "Uint16Array":
682
- return Uint16Array;
683
- case "Uint32Array":
684
- return Uint32Array;
685
- case "Uint8ClampedArray":
686
- return Uint8ClampedArray;
687
- case "Float32Array":
688
- return Float32Array;
689
- case "Float64Array":
690
- return Float64Array;
691
- case "BigInt64Array":
692
- return BigInt64Array;
693
- case "BigUint64Array":
694
- return BigUint64Array;
695
- default:
696
- throw new Error(`Unknown TypedArray "${name}"`);
1011
+ parseWKSymbol(current) {
1012
+ assert(this.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
1013
+ const registeredID = this.refs.get(current);
1014
+ if (registeredID != null) {
1015
+ this.markRef(registeredID);
1016
+ return createIndexedValueNode(registeredID);
1017
+ }
1018
+ const isValid = current in INV_SYMBOL_REF;
1019
+ assert(current in INV_SYMBOL_REF || hasReferenceID(current), new Error("Cannot serialize symbol without reference ID."));
1020
+ const id = this.refs.size;
1021
+ this.refs.set(current, id);
1022
+ if (isValid) {
1023
+ return createWKSymbolNode(id, current);
1024
+ }
1025
+ return createReferenceNode(id, current);
697
1026
  }
698
- }
699
- var IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
700
- function isValidIdentifier(name) {
701
- const char = name[0];
702
- return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
703
- }
704
- function getObjectFlag(obj) {
705
- if (Object.isFrozen(obj)) {
706
- return 3 /* Frozen */;
1027
+ parseMapSentinel() {
1028
+ const registeredID = this.refs.get(MAP_SENTINEL);
1029
+ if (registeredID != null) {
1030
+ this.markRef(registeredID);
1031
+ return createIndexedValueNode(registeredID);
1032
+ }
1033
+ const id = this.refs.size;
1034
+ this.refs.set(MAP_SENTINEL, id);
1035
+ return {
1036
+ t: 41 /* MapSentinel */,
1037
+ i: id,
1038
+ s: void 0,
1039
+ l: void 0,
1040
+ c: void 0,
1041
+ m: void 0,
1042
+ p: void 0,
1043
+ e: void 0,
1044
+ a: void 0,
1045
+ f: void 0,
1046
+ b: void 0,
1047
+ o: void 0
1048
+ };
707
1049
  }
708
- if (Object.isSealed(obj)) {
709
- return 2 /* Sealed */;
1050
+ parseIteratorFactory() {
1051
+ const registeredID = this.refs.get(ITERATOR);
1052
+ if (registeredID != null) {
1053
+ this.markRef(registeredID);
1054
+ return createIndexedValueNode(registeredID);
1055
+ }
1056
+ const id = this.refs.size;
1057
+ this.refs.set(ITERATOR, id);
1058
+ return {
1059
+ t: 42 /* IteratorFactory */,
1060
+ i: id,
1061
+ s: void 0,
1062
+ l: void 0,
1063
+ c: void 0,
1064
+ m: void 0,
1065
+ p: void 0,
1066
+ e: void 0,
1067
+ a: void 0,
1068
+ f: this.parseWKSymbol(Symbol.iterator),
1069
+ b: void 0,
1070
+ o: void 0
1071
+ };
710
1072
  }
711
- if (Object.isExtensible(obj)) {
712
- return 0 /* None */;
1073
+ parseAsyncIteratorFactory() {
1074
+ const registeredID = this.refs.get(ASYNC_ITERATOR);
1075
+ if (registeredID != null) {
1076
+ this.markRef(registeredID);
1077
+ return createIndexedValueNode(registeredID);
1078
+ }
1079
+ const id = this.refs.size;
1080
+ this.refs.set(ASYNC_ITERATOR, id);
1081
+ return {
1082
+ t: 44 /* AsyncIteratorFactory */,
1083
+ i: id,
1084
+ s: void 0,
1085
+ l: void 0,
1086
+ c: void 0,
1087
+ m: void 0,
1088
+ p: void 0,
1089
+ e: void 0,
1090
+ a: void 0,
1091
+ f: this.parseWKSymbol(Symbol.asyncIterator),
1092
+ b: void 0,
1093
+ o: void 0
1094
+ };
713
1095
  }
714
- return 1 /* NonExtensible */;
715
- }
716
- function getErrorOptions(error, features) {
717
- let options;
718
- const constructor = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
719
- if (error.name !== constructor) {
720
- options = { name: error.name };
721
- } else if (error.constructor.name !== constructor) {
722
- options = { name: error.constructor.name };
1096
+ createObjectNode(id, current, empty, record) {
1097
+ return {
1098
+ t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
1099
+ i: id,
1100
+ s: void 0,
1101
+ l: void 0,
1102
+ c: void 0,
1103
+ m: void 0,
1104
+ p: record,
1105
+ e: void 0,
1106
+ a: void 0,
1107
+ f: void 0,
1108
+ b: void 0,
1109
+ o: getObjectFlag(current)
1110
+ };
723
1111
  }
724
- const names = Object.getOwnPropertyNames(error);
725
- for (let i = 0, len = names.length, name; i < len; i++) {
726
- name = names[i];
727
- if (name !== "name" && name !== "message") {
728
- if (name === "stack") {
729
- if (features & 16 /* ErrorPrototypeStack */) {
730
- options = options || {};
731
- options[name] = error[name];
732
- }
733
- } else {
734
- options = options || {};
735
- options[name] = error[name];
736
- }
1112
+ createMapNode(id, k, v, s) {
1113
+ return {
1114
+ t: 8 /* Map */,
1115
+ i: id,
1116
+ s: void 0,
1117
+ l: void 0,
1118
+ c: void 0,
1119
+ m: void 0,
1120
+ p: void 0,
1121
+ e: { k, v, s },
1122
+ a: void 0,
1123
+ f: this.parseMapSentinel(),
1124
+ b: void 0,
1125
+ o: void 0
1126
+ };
1127
+ }
1128
+ parseReadableStreamFactory() {
1129
+ const registeredID = this.refs.get(READABLE_STREAM);
1130
+ if (registeredID != null) {
1131
+ this.markRef(registeredID);
1132
+ return createIndexedValueNode(registeredID);
737
1133
  }
1134
+ const id = this.refs.size;
1135
+ this.refs.set(READABLE_STREAM, id);
1136
+ return {
1137
+ t: 47 /* ReadableStreamFactory */,
1138
+ i: id,
1139
+ s: void 0,
1140
+ l: void 0,
1141
+ c: void 0,
1142
+ m: void 0,
1143
+ p: void 0,
1144
+ e: void 0,
1145
+ a: void 0,
1146
+ f: void 0,
1147
+ b: void 0,
1148
+ o: void 0
1149
+ };
1150
+ }
1151
+ };
1152
+
1153
+ // src/core/utils/promise-to-result.ts
1154
+ async function promiseToResult(current) {
1155
+ try {
1156
+ return [1, await current];
1157
+ } catch (e) {
1158
+ return [0, e];
738
1159
  }
739
- return options;
740
1160
  }
741
1161
 
742
1162
  // src/core/web-api.ts
@@ -788,135 +1208,122 @@ function createDOMExceptionNode(id, current) {
788
1208
  o: void 0
789
1209
  };
790
1210
  }
1211
+ function createEventNode(id, type, options) {
1212
+ return {
1213
+ t: 37 /* Event */,
1214
+ i: id,
1215
+ s: serializeString(type),
1216
+ l: void 0,
1217
+ c: void 0,
1218
+ m: void 0,
1219
+ p: void 0,
1220
+ e: void 0,
1221
+ a: void 0,
1222
+ f: options,
1223
+ b: void 0,
1224
+ o: void 0
1225
+ };
1226
+ }
1227
+ function createCustomEventNode(id, type, options) {
1228
+ return {
1229
+ t: 38 /* CustomEvent */,
1230
+ i: id,
1231
+ s: serializeString(type),
1232
+ l: void 0,
1233
+ c: void 0,
1234
+ m: void 0,
1235
+ p: void 0,
1236
+ e: void 0,
1237
+ a: void 0,
1238
+ f: options,
1239
+ b: void 0,
1240
+ o: void 0
1241
+ };
1242
+ }
1243
+ function createReadableStreamNode(id, factory, items) {
1244
+ return {
1245
+ t: 46 /* ReadableStream */,
1246
+ i: id,
1247
+ s: void 0,
1248
+ l: void 0,
1249
+ c: void 0,
1250
+ m: void 0,
1251
+ p: void 0,
1252
+ e: void 0,
1253
+ a: [
1254
+ factory,
1255
+ items
1256
+ ],
1257
+ f: void 0,
1258
+ b: void 0,
1259
+ o: void 0
1260
+ };
1261
+ }
791
1262
 
792
- // src/core/base/async.ts
1263
+ // src/core/context/parser/async.ts
793
1264
  var BaseAsyncParserContext = class extends BaseParserContext {
794
1265
  async parseItems(current) {
795
- const size = current.length;
796
1266
  const nodes = [];
797
- const deferred = [];
798
- for (let i = 0, item; i < size; i++) {
1267
+ for (let i = 0, len = current.length; i < len; i++) {
799
1268
  if (i in current) {
800
- item = current[i];
801
- if (this.isIterable(item)) {
802
- deferred[i] = item;
803
- } else {
804
- nodes[i] = await this.parse(item);
805
- }
806
- }
807
- }
808
- for (let i = 0; i < size; i++) {
809
- if (i in deferred) {
810
- nodes[i] = await this.parse(deferred[i]);
1269
+ nodes[i] = await this.parse(current[i]);
811
1270
  }
812
1271
  }
813
1272
  return nodes;
814
1273
  }
815
1274
  async parseArray(id, current) {
816
- return {
817
- t: 9 /* Array */,
818
- i: id,
819
- s: void 0,
820
- l: current.length,
821
- c: void 0,
822
- m: void 0,
823
- p: void 0,
824
- e: void 0,
825
- a: await this.parseItems(current),
826
- f: void 0,
827
- b: void 0,
828
- o: getObjectFlag(current)
829
- };
830
- }
831
- async parseBoxed(id, current) {
832
- return {
833
- t: 27 /* Boxed */,
834
- i: id,
835
- s: void 0,
836
- l: void 0,
837
- c: void 0,
838
- m: void 0,
839
- p: void 0,
840
- e: void 0,
841
- a: void 0,
842
- f: await this.parse(current.valueOf()),
843
- b: void 0,
844
- o: void 0
845
- };
846
- }
847
- async parseTypedArray(id, current) {
848
- return {
849
- t: 15 /* TypedArray */,
850
- i: id,
851
- s: void 0,
852
- l: current.length,
853
- c: current.constructor.name,
854
- m: void 0,
855
- p: void 0,
856
- e: void 0,
857
- a: void 0,
858
- f: await this.parse(current.buffer),
859
- b: current.byteOffset,
860
- o: void 0
861
- };
862
- }
863
- async parseBigIntTypedArray(id, current) {
864
- return {
865
- t: 16 /* BigIntTypedArray */,
866
- i: id,
867
- s: void 0,
868
- l: current.length,
869
- c: current.constructor.name,
870
- m: void 0,
871
- p: void 0,
872
- e: void 0,
873
- a: void 0,
874
- f: await this.parse(current.buffer),
875
- b: current.byteOffset,
876
- o: void 0
877
- };
878
- }
879
- async parseDataView(id, current) {
880
- return {
881
- t: 22 /* DataView */,
882
- i: id,
883
- s: void 0,
884
- l: current.byteLength,
885
- c: void 0,
886
- m: void 0,
887
- p: void 0,
888
- e: void 0,
889
- a: void 0,
890
- f: await this.parse(current.buffer),
891
- b: current.byteOffset,
892
- o: void 0
893
- };
1275
+ return createArrayNode(
1276
+ id,
1277
+ current,
1278
+ await this.parseItems(current)
1279
+ );
894
1280
  }
895
1281
  async parseProperties(properties) {
896
1282
  const entries = Object.entries(properties);
897
1283
  const keyNodes = [];
898
1284
  const valueNodes = [];
899
- const deferredKeys = [];
900
- const deferredValues = [];
901
- for (let i = 0, len = entries.length, key, item; i < len; i++) {
902
- key = serializeString(entries[i][0]);
903
- item = entries[i][1];
904
- if (this.isIterable(item)) {
905
- deferredKeys.push(key);
906
- deferredValues.push(item);
907
- } else {
908
- keyNodes.push(key);
909
- valueNodes.push(await this.parse(item));
910
- }
911
- }
912
- for (let i = 0, len = deferredKeys.length; i < len; i++) {
913
- keyNodes.push(deferredKeys[i]);
914
- valueNodes.push(await this.parse(deferredValues[i]));
1285
+ for (let i = 0, len = entries.length; i < len; i++) {
1286
+ keyNodes.push(serializeString(entries[i][0]));
1287
+ valueNodes.push(await this.parse(entries[i][1]));
915
1288
  }
916
1289
  if (this.features & 1024 /* Symbol */) {
917
- if (Symbol.iterator in properties) {
918
- keyNodes.push(0 /* SymbolIterator */);
919
- valueNodes.push(await this.parse(Array.from(properties)));
1290
+ let symbol = Symbol.iterator;
1291
+ if (symbol in properties) {
1292
+ keyNodes.push(
1293
+ this.parseWKSymbol(symbol)
1294
+ );
1295
+ valueNodes.push(
1296
+ createIteratorFactoryInstanceNode(
1297
+ this.parseIteratorFactory(),
1298
+ await this.parse(
1299
+ iteratorToSequence(properties)
1300
+ )
1301
+ )
1302
+ );
1303
+ }
1304
+ symbol = Symbol.asyncIterator;
1305
+ if (symbol in properties) {
1306
+ keyNodes.push(
1307
+ this.parseWKSymbol(symbol)
1308
+ );
1309
+ valueNodes.push(
1310
+ createAsyncIteratorFactoryInstanceNode(
1311
+ this.parseAsyncIteratorFactory(),
1312
+ await this.parse(
1313
+ await asyncIteratorToSequence(properties)
1314
+ )
1315
+ )
1316
+ );
1317
+ }
1318
+ symbol = Symbol.toStringTag;
1319
+ if (symbol in properties) {
1320
+ keyNodes.push(this.parseWKSymbol(symbol));
1321
+ valueNodes.push(createStringNode(properties[symbol]));
1322
+ }
1323
+ symbol = Symbol.isConcatSpreadable;
1324
+ if (symbol in properties) {
1325
+ keyNodes.push(this.parseWKSymbol(symbol));
1326
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
920
1327
  }
921
1328
  }
922
1329
  return {
@@ -926,99 +1333,61 @@ var BaseAsyncParserContext = class extends BaseParserContext {
926
1333
  };
927
1334
  }
928
1335
  async parsePlainObject(id, current, empty) {
929
- return {
930
- t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
931
- i: id,
932
- s: void 0,
933
- l: void 0,
934
- c: void 0,
935
- m: void 0,
936
- p: await this.parseProperties(current),
937
- e: void 0,
938
- a: void 0,
939
- f: void 0,
940
- b: void 0,
941
- o: getObjectFlag(current)
942
- };
1336
+ return this.createObjectNode(
1337
+ id,
1338
+ current,
1339
+ empty,
1340
+ await this.parseProperties(current)
1341
+ );
1342
+ }
1343
+ async parseBoxed(id, current) {
1344
+ return createBoxedNode(id, await this.parse(current.valueOf()));
1345
+ }
1346
+ async parseTypedArray(id, current) {
1347
+ return createTypedArrayNode(id, current, await this.parse(current.buffer));
1348
+ }
1349
+ async parseBigIntTypedArray(id, current) {
1350
+ return createBigIntTypedArrayNode(id, current, await this.parse(current.buffer));
1351
+ }
1352
+ async parseDataView(id, current) {
1353
+ return createDataViewNode(id, current, await this.parse(current.buffer));
943
1354
  }
944
1355
  async parseError(id, current) {
945
1356
  const options = getErrorOptions(current, this.features);
946
- const optionsNode = options ? await this.parseProperties(options) : void 0;
947
- return {
948
- t: 13 /* Error */,
949
- i: id,
950
- s: getErrorConstructor(current),
951
- l: void 0,
952
- c: void 0,
953
- m: serializeString(current.message),
954
- p: optionsNode,
955
- e: void 0,
956
- a: void 0,
957
- f: void 0,
958
- b: void 0,
959
- o: void 0
960
- };
1357
+ return createErrorNode(
1358
+ id,
1359
+ current,
1360
+ options ? await this.parseProperties(options) : void 0
1361
+ );
1362
+ }
1363
+ async parseAggregateError(id, current) {
1364
+ const options = getErrorOptions(current, this.features);
1365
+ return createAggregateErrorNode(
1366
+ id,
1367
+ current,
1368
+ options ? await this.parseProperties(options) : void 0
1369
+ );
961
1370
  }
962
1371
  async parseMap(id, current) {
963
1372
  const keyNodes = [];
964
1373
  const valueNodes = [];
965
- const deferredKey = [];
966
- const deferredValue = [];
967
1374
  for (const [key, value] of current.entries()) {
968
- if (this.isIterable(key) || this.isIterable(value)) {
969
- deferredKey.push(key);
970
- deferredValue.push(value);
971
- } else {
972
- keyNodes.push(await this.parse(key));
973
- valueNodes.push(await this.parse(value));
974
- }
975
- }
976
- for (let i = 0, len = deferredKey.length; i < len; i++) {
977
- keyNodes.push(await this.parse(deferredKey[i]));
978
- valueNodes.push(await this.parse(deferredValue[i]));
979
- }
980
- return {
981
- t: 8 /* Map */,
982
- i: id,
983
- s: void 0,
984
- l: void 0,
985
- c: void 0,
986
- m: void 0,
987
- p: void 0,
988
- e: { k: keyNodes, v: valueNodes, s: current.size },
989
- a: void 0,
990
- f: void 0,
991
- b: void 0,
992
- o: void 0
993
- };
1375
+ keyNodes.push(await this.parse(key));
1376
+ valueNodes.push(await this.parse(value));
1377
+ }
1378
+ return this.createMapNode(
1379
+ id,
1380
+ keyNodes,
1381
+ valueNodes,
1382
+ current.size
1383
+ );
994
1384
  }
995
1385
  async parseSet(id, current) {
996
- const nodes = [];
997
- const deferred = [];
1386
+ const items = [];
998
1387
  for (const item of current.keys()) {
999
- if (this.isIterable(item)) {
1000
- deferred.push(item);
1001
- } else {
1002
- nodes.push(await this.parse(item));
1003
- }
1004
- }
1005
- for (let i = 0, len = deferred.length; i < len; i++) {
1006
- nodes.push(await this.parse(deferred[i]));
1388
+ items.push(await this.parse(item));
1007
1389
  }
1008
- return {
1009
- t: 7 /* Set */,
1010
- i: id,
1011
- s: void 0,
1012
- l: current.size,
1013
- c: void 0,
1014
- m: void 0,
1015
- p: void 0,
1016
- e: void 0,
1017
- a: nodes,
1018
- f: void 0,
1019
- b: void 0,
1020
- o: void 0
1021
- };
1390
+ return createSetNode(id, current.size, items);
1022
1391
  }
1023
1392
  async parseBlob(id, current) {
1024
1393
  return {
@@ -1056,22 +1425,9 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1056
1425
  const size = entries.length;
1057
1426
  const keyNodes = [];
1058
1427
  const valueNodes = [];
1059
- const deferredKeys = [];
1060
- const deferredValues = [];
1061
- for (let i = 0, key, item; i < size; i++) {
1062
- key = serializeString(entries[i][0]);
1063
- item = entries[i][1];
1064
- if (this.isIterable(item)) {
1065
- deferredKeys.push(key);
1066
- deferredValues.push(item);
1067
- } else {
1068
- keyNodes.push(key);
1069
- valueNodes.push(await this.parse(item));
1070
- }
1071
- }
1072
- for (let i = 0, len = deferredKeys.length; i < len; i++) {
1073
- keyNodes.push(deferredKeys[i]);
1074
- valueNodes.push(await this.parse(deferredValues[i]));
1428
+ for (let i = 0; i < size; i++) {
1429
+ keyNodes.push(serializeString(entries[i][0]));
1430
+ valueNodes.push(await this.parse(entries[i][1]));
1075
1431
  }
1076
1432
  return {
1077
1433
  k: keyNodes,
@@ -1099,113 +1455,73 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1099
1455
  o: void 0
1100
1456
  };
1101
1457
  }
1102
- async parseFormData(id, current) {
1103
- const items = [];
1104
- current.forEach((value, key) => {
1105
- items.push([key, value]);
1106
- });
1107
- return {
1108
- t: 26 /* FormData */,
1109
- i: id,
1110
- s: void 0,
1111
- l: void 0,
1112
- c: void 0,
1113
- m: void 0,
1114
- p: void 0,
1115
- e: await this.parsePlainProperties(items),
1116
- a: void 0,
1117
- f: void 0,
1118
- b: void 0,
1119
- o: void 0
1120
- };
1121
- }
1122
- async parseRequest(id, current) {
1123
- return {
1124
- t: 35 /* Request */,
1125
- i: id,
1126
- s: serializeString(current.url),
1127
- l: void 0,
1128
- c: void 0,
1129
- m: void 0,
1130
- p: void 0,
1131
- e: void 0,
1132
- f: await this.parse(
1133
- createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1134
- ),
1135
- a: void 0,
1136
- b: void 0,
1137
- o: void 0
1138
- };
1139
- }
1140
- async parseResponse(id, current) {
1141
- return {
1142
- t: 36 /* Response */,
1143
- i: id,
1144
- s: void 0,
1145
- l: void 0,
1146
- c: void 0,
1147
- m: void 0,
1148
- p: void 0,
1149
- e: void 0,
1150
- f: void 0,
1151
- a: [
1152
- current.body ? await this.parse(await current.clone().arrayBuffer()) : NULL_NODE,
1153
- await this.parse(createResponseOptions(current))
1154
- ],
1155
- b: void 0,
1156
- o: void 0
1157
- };
1158
- }
1159
- async parseEvent(id, current) {
1458
+ async parseFormData(id, current) {
1459
+ const items = [];
1460
+ current.forEach((value, key) => {
1461
+ items.push([key, value]);
1462
+ });
1160
1463
  return {
1161
- t: 37 /* Event */,
1464
+ t: 26 /* FormData */,
1162
1465
  i: id,
1163
- s: serializeString(current.type),
1466
+ s: void 0,
1164
1467
  l: void 0,
1165
1468
  c: void 0,
1166
1469
  m: void 0,
1167
1470
  p: void 0,
1168
- e: void 0,
1471
+ e: await this.parsePlainProperties(items),
1169
1472
  a: void 0,
1170
- f: await this.parse(createEventOptions(current)),
1473
+ f: void 0,
1171
1474
  b: void 0,
1172
1475
  o: void 0
1173
1476
  };
1174
1477
  }
1175
- async parseCustomEvent(id, current) {
1478
+ async parseRequest(id, current) {
1176
1479
  return {
1177
- t: 38 /* CustomEvent */,
1480
+ t: 35 /* Request */,
1178
1481
  i: id,
1179
- s: serializeString(current.type),
1482
+ s: serializeString(current.url),
1180
1483
  l: void 0,
1181
1484
  c: void 0,
1182
1485
  m: void 0,
1183
1486
  p: void 0,
1184
1487
  e: void 0,
1488
+ f: await this.parse(
1489
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1490
+ ),
1185
1491
  a: void 0,
1186
- f: await this.parse(createCustomEventOptions(current)),
1187
1492
  b: void 0,
1188
1493
  o: void 0
1189
1494
  };
1190
1495
  }
1191
- async parseAggregateError(id, current) {
1192
- const options = getErrorOptions(current, this.features);
1193
- const optionsNode = options ? await this.parseProperties(options) : void 0;
1496
+ async parseResponse(id, current) {
1194
1497
  return {
1195
- t: 14 /* AggregateError */,
1498
+ t: 36 /* Response */,
1196
1499
  i: id,
1197
1500
  s: void 0,
1198
1501
  l: void 0,
1199
1502
  c: void 0,
1200
- m: serializeString(current.message),
1201
- p: optionsNode,
1503
+ m: void 0,
1504
+ p: void 0,
1202
1505
  e: void 0,
1203
- a: void 0,
1204
1506
  f: void 0,
1507
+ a: [
1508
+ current.body ? await this.parse(await current.clone().arrayBuffer()) : NULL_NODE,
1509
+ await this.parse(createResponseOptions(current))
1510
+ ],
1205
1511
  b: void 0,
1206
1512
  o: void 0
1207
1513
  };
1208
1514
  }
1515
+ async parseEvent(id, current) {
1516
+ return createEventNode(id, current.type, await this.parse(createEventOptions(current)));
1517
+ }
1518
+ async parseCustomEvent(id, current) {
1519
+ return createCustomEventNode(
1520
+ id,
1521
+ current.type,
1522
+ await this.parse(createCustomEventOptions(current))
1523
+ );
1524
+ }
1209
1525
  async parsePromise(id, current) {
1210
1526
  const [status, result] = await promiseToResult(current);
1211
1527
  return {
@@ -1241,6 +1557,15 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1241
1557
  }
1242
1558
  return void 0;
1243
1559
  }
1560
+ async parseReadableStream(id, current) {
1561
+ return createReadableStreamNode(
1562
+ id,
1563
+ this.parseReadableStreamFactory(),
1564
+ await this.parse(
1565
+ await readableStreamToSequence(current)
1566
+ )
1567
+ );
1568
+ }
1244
1569
  async parseObject(id, current) {
1245
1570
  if (Array.isArray(current)) {
1246
1571
  return this.parseArray(id, current);
@@ -1348,6 +1673,8 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1348
1673
  return this.parseCustomEvent(id, current);
1349
1674
  case (typeof DOMException !== "undefined" ? DOMException : UNIVERSAL_SENTINEL):
1350
1675
  return createDOMExceptionNode(id, current);
1676
+ case (typeof ReadableStream !== "undefined" ? ReadableStream : UNIVERSAL_SENTINEL):
1677
+ return this.parseReadableStream(id, current);
1351
1678
  default:
1352
1679
  break;
1353
1680
  }
@@ -1362,7 +1689,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1362
1689
  if (current instanceof Error) {
1363
1690
  return this.parseError(id, current);
1364
1691
  }
1365
- if (currentFeatures & 1024 /* Symbol */ && Symbol.iterator in current) {
1692
+ if (currentFeatures & 1024 /* Symbol */ && (Symbol.iterator in current || Symbol.asyncIterator in current)) {
1366
1693
  return this.parsePlainObject(id, current, !!currentClass);
1367
1694
  }
1368
1695
  throw new UnsupportedTypeError(current);
@@ -1392,14 +1719,10 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1392
1719
  const id = this.getReference(current);
1393
1720
  return typeof id === "number" ? this.parseObject(id, current) : id;
1394
1721
  }
1395
- case "symbol": {
1396
- assert(this.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
1397
- const id = this.getReference(current);
1398
- return typeof id === "number" ? createWKSymbolNode(id, current) : id;
1399
- }
1722
+ case "symbol":
1723
+ return this.parseWKSymbol(current);
1400
1724
  case "function":
1401
- assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
1402
- return this.getStrictReference(current);
1725
+ return this.parseFunction(current);
1403
1726
  default:
1404
1727
  throw new UnsupportedTypeError(current);
1405
1728
  }
@@ -1414,50 +1737,90 @@ var AsyncParserContext = class extends BaseAsyncParserContext {
1414
1737
  }
1415
1738
  };
1416
1739
 
1417
- // src/core/tree/deserialize.ts
1418
- function applyObjectFlag(obj, flag) {
1419
- switch (flag) {
1420
- case 3 /* Frozen */:
1421
- return Object.freeze(obj);
1422
- case 1 /* NonExtensible */:
1423
- return Object.preventExtensions(obj);
1424
- case 2 /* Sealed */:
1425
- return Object.seal(obj);
1740
+ // src/core/utils/typed-array.ts
1741
+ function getTypedArrayConstructor(name) {
1742
+ switch (name) {
1743
+ case "Int8Array":
1744
+ return Int8Array;
1745
+ case "Int16Array":
1746
+ return Int16Array;
1747
+ case "Int32Array":
1748
+ return Int32Array;
1749
+ case "Uint8Array":
1750
+ return Uint8Array;
1751
+ case "Uint16Array":
1752
+ return Uint16Array;
1753
+ case "Uint32Array":
1754
+ return Uint32Array;
1755
+ case "Uint8ClampedArray":
1756
+ return Uint8ClampedArray;
1757
+ case "Float32Array":
1758
+ return Float32Array;
1759
+ case "Float64Array":
1760
+ return Float64Array;
1761
+ case "BigInt64Array":
1762
+ return BigInt64Array;
1763
+ case "BigUint64Array":
1764
+ return BigUint64Array;
1426
1765
  default:
1427
- return obj;
1766
+ throw new Error(`Unknown TypedArray "${name}"`);
1428
1767
  }
1429
1768
  }
1769
+
1770
+ // src/core/utils/deferred.ts
1430
1771
  function createDeferred() {
1431
1772
  let resolve;
1432
1773
  let reject;
1433
1774
  return {
1434
- resolve(v) {
1435
- resolve(v);
1436
- },
1437
- reject(v) {
1438
- reject(v);
1439
- },
1440
1775
  promise: new Promise((res, rej) => {
1441
1776
  resolve = res;
1442
1777
  reject = rej;
1443
- })
1778
+ }),
1779
+ resolve(value) {
1780
+ resolve(value);
1781
+ },
1782
+ reject(value) {
1783
+ reject(value);
1784
+ }
1785
+ };
1786
+ }
1787
+ function createDeferredStream() {
1788
+ let controller;
1789
+ return {
1790
+ stream: new ReadableStream({
1791
+ start(current) {
1792
+ controller = current;
1793
+ }
1794
+ }),
1795
+ close() {
1796
+ controller.close();
1797
+ },
1798
+ enqueue(data) {
1799
+ controller.enqueue(data);
1800
+ },
1801
+ error(e) {
1802
+ controller.error(e);
1803
+ }
1444
1804
  };
1445
1805
  }
1446
- var VanillaDeserializerContext = class {
1806
+
1807
+ // src/core/context/deserializer.ts
1808
+ function applyObjectFlag(obj, flag) {
1809
+ switch (flag) {
1810
+ case 3 /* Frozen */:
1811
+ return Object.freeze(obj);
1812
+ case 1 /* NonExtensible */:
1813
+ return Object.preventExtensions(obj);
1814
+ case 2 /* Sealed */:
1815
+ return Object.seal(obj);
1816
+ default:
1817
+ return obj;
1818
+ }
1819
+ }
1820
+ var BaseDeserializerContext = class {
1447
1821
  constructor(options) {
1448
- /**
1449
- * Mapping ids to values
1450
- * @private
1451
- */
1452
- this.values = /* @__PURE__ */ new Map();
1453
1822
  this.plugins = options.plugins;
1454
- this.refs = new Set(options.markedRefs);
1455
- }
1456
- assignIndexedValue(index, value) {
1457
- if (this.refs.has(index)) {
1458
- this.values.set(index, value);
1459
- }
1460
- return value;
1823
+ this.refs = options.refs || /* @__PURE__ */ new Map();
1461
1824
  }
1462
1825
  deserializeReference(node) {
1463
1826
  return this.assignIndexedValue(node.i, getReference(deserializeString(node.s)));
@@ -1481,23 +1844,14 @@ var VanillaDeserializerContext = class {
1481
1844
  deserializeProperties(node, result) {
1482
1845
  const len = node.s;
1483
1846
  if (len) {
1484
- let key;
1485
- let value;
1486
1847
  const keys = node.k;
1487
1848
  const vals = node.v;
1488
- for (let i = 0; i < len; i++) {
1849
+ for (let i = 0, key; i < len; i++) {
1489
1850
  key = keys[i];
1490
- value = this.deserialize(vals[i]);
1491
- switch (key) {
1492
- case 0 /* SymbolIterator */:
1493
- {
1494
- const current = value;
1495
- result[Symbol.iterator] = () => current.values();
1496
- }
1497
- break;
1498
- default:
1499
- result[deserializeString(key)] = value;
1500
- break;
1851
+ if (typeof key === "string") {
1852
+ result[deserializeString(key)] = this.deserialize(vals[i]);
1853
+ } else {
1854
+ result[this.deserialize(key)] = this.deserialize(vals[i]);
1501
1855
  }
1502
1856
  }
1503
1857
  }
@@ -1589,14 +1943,14 @@ var VanillaDeserializerContext = class {
1589
1943
  }
1590
1944
  async deserializePromise(node) {
1591
1945
  const deferred = createDeferred();
1592
- const result = this.assignIndexedValue(node.i, deferred.promise);
1946
+ const result = this.assignIndexedValue(node.i, deferred);
1593
1947
  const deserialized = this.deserialize(node.f);
1594
1948
  if (node.s) {
1595
1949
  deferred.resolve(deserialized);
1596
1950
  } else {
1597
1951
  deferred.reject(deserialized);
1598
1952
  }
1599
- return result;
1953
+ return result.promise;
1600
1954
  }
1601
1955
  deserializeURL(node) {
1602
1956
  return this.assignIndexedValue(node.i, new URL(deserializeString(node.s)));
@@ -1699,14 +2053,88 @@ var VanillaDeserializerContext = class {
1699
2053
  for (let i = 0, len = currentPlugins.length; i < len; i++) {
1700
2054
  const plugin = currentPlugins[i];
1701
2055
  if (plugin.tag === node.c) {
1702
- return plugin.deserialize(node.s, this, {
1703
- id: node.i
1704
- });
2056
+ return this.assignIndexedValue(
2057
+ node.i,
2058
+ plugin.deserialize(node.s, this, {
2059
+ id: node.i
2060
+ })
2061
+ );
1705
2062
  }
1706
2063
  }
1707
2064
  }
1708
2065
  throw new Error('Missing plugin for tag "' + node.c + '".');
1709
2066
  }
2067
+ deserializePromiseConstructor(node) {
2068
+ return this.assignIndexedValue(
2069
+ node.i,
2070
+ createDeferred()
2071
+ ).promise;
2072
+ }
2073
+ deserializePromiseResolve(node) {
2074
+ const deferred = this.refs.get(node.i);
2075
+ assert(deferred, new Error("Missing Promise instance."));
2076
+ deferred.resolve(
2077
+ this.deserialize(node.f)
2078
+ );
2079
+ return void 0;
2080
+ }
2081
+ deserializePromiseReject(node) {
2082
+ const deferred = this.refs.get(node.i);
2083
+ assert(deferred, new Error("Missing Promise instance."));
2084
+ deferred.reject(
2085
+ this.deserialize(node.f)
2086
+ );
2087
+ return void 0;
2088
+ }
2089
+ deserializeReadableStreamConstructor(node) {
2090
+ return this.assignIndexedValue(
2091
+ node.i,
2092
+ createDeferredStream()
2093
+ ).stream;
2094
+ }
2095
+ deserializeReadableStreamEnqueue(node) {
2096
+ const deferred = this.refs.get(node.i);
2097
+ assert(deferred, new Error("Missing ReadableStream instance."));
2098
+ deferred.enqueue(
2099
+ this.deserialize(node.f)
2100
+ );
2101
+ return void 0;
2102
+ }
2103
+ deserializeReadableStreamError(node) {
2104
+ const deferred = this.refs.get(node.i);
2105
+ assert(deferred, new Error("Missing Promise instance."));
2106
+ deferred.error(
2107
+ this.deserialize(node.f)
2108
+ );
2109
+ return void 0;
2110
+ }
2111
+ deserializeReadableStreamClose(node) {
2112
+ const deferred = this.refs.get(node.i);
2113
+ assert(deferred, new Error("Missing Promise instance."));
2114
+ deferred.close();
2115
+ return void 0;
2116
+ }
2117
+ deserializeIteratorFactoryInstance(node) {
2118
+ const source = this.deserialize(node.a[1]);
2119
+ return sequenceToIterator(source);
2120
+ }
2121
+ deserializeAsyncIteratorFactoryInstance(node) {
2122
+ const source = this.deserialize(node.a[1]);
2123
+ if (source.constructor === ReadableStream) {
2124
+ return readableStreamToAsyncIterator(
2125
+ source
2126
+ );
2127
+ }
2128
+ return sequenceToAsyncIterator(source);
2129
+ }
2130
+ deserializeReadableStream(node) {
2131
+ return this.assignIndexedValue(
2132
+ node.i,
2133
+ sequenceToReadableStream(
2134
+ this.deserialize(node.a[1])
2135
+ )
2136
+ );
2137
+ }
1710
2138
  deserialize(node) {
1711
2139
  switch (node.t) {
1712
2140
  case 2 /* Constant */:
@@ -1718,7 +2146,7 @@ var VanillaDeserializerContext = class {
1718
2146
  case 3 /* BigInt */:
1719
2147
  return BigInt(node.s);
1720
2148
  case 4 /* IndexedValue */:
1721
- return this.values.get(node.i);
2149
+ return this.refs.get(node.i);
1722
2150
  case 20 /* Reference */:
1723
2151
  return this.deserializeReference(node);
1724
2152
  case 9 /* Array */:
@@ -1775,13 +2203,62 @@ var VanillaDeserializerContext = class {
1775
2203
  return this.deserializeDOMException(node);
1776
2204
  case 40 /* Plugin */:
1777
2205
  return this.deserializePlugin(node);
2206
+ case 28 /* PromiseConstructor */:
2207
+ return this.deserializePromiseConstructor(node);
2208
+ case 29 /* PromiseResolve */:
2209
+ return this.deserializePromiseResolve(node);
2210
+ case 30 /* PromiseReject */:
2211
+ return this.deserializePromiseReject(node);
2212
+ case 31 /* ReadableStreamConstructor */:
2213
+ return this.deserializeReadableStreamConstructor(node);
2214
+ case 32 /* ReadableStreamEnqueue */:
2215
+ return this.deserializeReadableStreamEnqueue(node);
2216
+ case 34 /* ReadableStreamError */:
2217
+ return this.deserializeReadableStreamError(node);
2218
+ case 33 /* ReadableStreamClose */:
2219
+ return this.deserializeReadableStreamClose(node);
2220
+ case 43 /* IteratorFactoryInstance */:
2221
+ return this.deserializeIteratorFactoryInstance(node);
2222
+ case 45 /* AsyncIteratorFactoryInstance */:
2223
+ return this.deserializeAsyncIteratorFactoryInstance(node);
2224
+ case 46 /* ReadableStream */:
2225
+ return this.deserializeReadableStream(node);
2226
+ case 41 /* MapSentinel */:
2227
+ case 42 /* IteratorFactory */:
2228
+ case 44 /* AsyncIteratorFactory */:
2229
+ case 47 /* ReadableStreamFactory */:
1778
2230
  default:
1779
2231
  throw new Error("invariant");
1780
2232
  }
1781
2233
  }
1782
2234
  };
1783
2235
 
1784
- // src/core/serializer-context.old.ts
2236
+ // src/core/tree/deserializer.ts
2237
+ var VanillaDeserializerContext = class extends BaseDeserializerContext {
2238
+ constructor(options) {
2239
+ super({
2240
+ plugins: options.plugins,
2241
+ refs: void 0
2242
+ });
2243
+ this.mode = "vanilla";
2244
+ this.marked = new Set(options.markedRefs);
2245
+ }
2246
+ assignIndexedValue(index, value) {
2247
+ if (this.marked.has(index)) {
2248
+ this.refs.set(index, value);
2249
+ }
2250
+ return value;
2251
+ }
2252
+ };
2253
+
2254
+ // src/core/utils/is-valid-identifier.ts
2255
+ var IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
2256
+ function isValidIdentifier(name) {
2257
+ const char = name[0];
2258
+ return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
2259
+ }
2260
+
2261
+ // src/core/context/serializer.ts
1785
2262
  function getAssignmentExpression(assignment) {
1786
2263
  switch (assignment.t) {
1787
2264
  case "index":
@@ -1854,10 +2331,6 @@ var SET_CONSTRUCTOR = "new Set";
1854
2331
  var MAP_CONSTRUCTOR = "new Map";
1855
2332
  var PROMISE_RESOLVE = "Promise.resolve";
1856
2333
  var PROMISE_REJECT = "Promise.reject";
1857
- var SYMBOL_ITERATOR = "Symbol.iterator";
1858
- var SPECIAL_REFERENCE_VALUE = {
1859
- [0 /* Sentinel */]: "[]"
1860
- };
1861
2334
  var OBJECT_FLAG_CONSTRUCTOR = {
1862
2335
  [3 /* Frozen */]: "Object.freeze",
1863
2336
  [2 /* Sealed */]: "Object.seal",
@@ -1881,11 +2354,24 @@ var BaseSerializerContext = class {
1881
2354
  * @private
1882
2355
  */
1883
2356
  this.assignments = [];
1884
- this.specials = /* @__PURE__ */ new Set();
1885
2357
  this.plugins = options.plugins;
1886
2358
  this.features = options.features;
1887
2359
  this.marked = new Set(options.markedRefs);
1888
2360
  }
2361
+ createFunction(parameters, body) {
2362
+ if (this.features & 4 /* ArrowFunction */) {
2363
+ const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
2364
+ return joined + "=>" + body;
2365
+ }
2366
+ return "function(" + parameters.join(",") + "){return " + body + "}";
2367
+ }
2368
+ createEffectfulFunction(parameters, body) {
2369
+ if (this.features & 4 /* ArrowFunction */) {
2370
+ const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
2371
+ return joined + "=>{" + body + "}";
2372
+ }
2373
+ return "function(" + parameters.join(",") + "){" + body + "}";
2374
+ }
1889
2375
  /**
1890
2376
  * A tiny function that tells if a reference
1891
2377
  * is to be accessed. This is a requirement for
@@ -1898,18 +2384,6 @@ var BaseSerializerContext = class {
1898
2384
  isMarked(id) {
1899
2385
  return this.marked.has(id);
1900
2386
  }
1901
- /**
1902
- * Generates special references that isn't provided by the user
1903
- * but by the script.
1904
- */
1905
- getSpecialReference(ref) {
1906
- const param = this.getRefParam("_" + ref);
1907
- if (this.specials.has(ref)) {
1908
- return param;
1909
- }
1910
- this.specials.add(ref);
1911
- return param + "=" + SPECIAL_REFERENCE_VALUE[ref];
1912
- }
1913
2387
  pushObjectFlag(flag, id) {
1914
2388
  if (flag !== 0 /* None */) {
1915
2389
  this.markRef(id);
@@ -1991,24 +2465,6 @@ var BaseSerializerContext = class {
1991
2465
  serializeReference(node) {
1992
2466
  return this.assignIndexedValue(node.i, REFERENCES_KEY + '.get("' + node.s + '")');
1993
2467
  }
1994
- getIterableAccess() {
1995
- return this.features & 2 /* ArrayPrototypeValues */ ? ".values()" : "[" + SYMBOL_ITERATOR + "]()";
1996
- }
1997
- serializeIterable(node) {
1998
- const key = "[" + SYMBOL_ITERATOR + "]";
1999
- const parent = this.stack;
2000
- this.stack = [];
2001
- let serialized = this.serialize(node) + this.getIterableAccess();
2002
- this.stack = parent;
2003
- if (this.features & 4 /* ArrowFunction */) {
2004
- serialized = ":()=>" + serialized;
2005
- } else if (this.features & 64 /* MethodShorthand */) {
2006
- serialized = "(){return " + serialized + "}";
2007
- } else {
2008
- serialized = ":function(){return " + serialized + "}";
2009
- }
2010
- return key + serialized;
2011
- }
2012
2468
  serializeArrayItem(id, item, index) {
2013
2469
  if (item) {
2014
2470
  if (this.isIndexedValueInStack(item)) {
@@ -2038,36 +2494,33 @@ var BaseSerializerContext = class {
2038
2494
  }
2039
2495
  return this.assignIndexedValue(id, "[]");
2040
2496
  }
2041
- serializeProperty(id, key, val) {
2042
- switch (key) {
2043
- case 0 /* SymbolIterator */:
2044
- return this.serializeIterable(val);
2045
- default: {
2046
- const check = Number(key);
2047
- const isIdentifier = check >= 0 || isValidIdentifier(key);
2048
- if (this.isIndexedValueInStack(val)) {
2049
- const refParam = this.getRefParam(val.i);
2050
- this.markRef(id);
2051
- if (isIdentifier && check !== check) {
2052
- this.createObjectAssign(id, key, refParam);
2053
- } else {
2054
- this.createArrayAssign(id, isIdentifier ? key : '"' + key + '"', refParam);
2055
- }
2056
- return "";
2497
+ serializeProperty(source, key, val) {
2498
+ if (typeof key === "string") {
2499
+ const check = Number(key);
2500
+ const isIdentifier = check >= 0 || isValidIdentifier(key);
2501
+ if (this.isIndexedValueInStack(val)) {
2502
+ const refParam = this.getRefParam(val.i);
2503
+ this.markRef(source.i);
2504
+ if (isIdentifier && check !== check) {
2505
+ this.createObjectAssign(source.i, key, refParam);
2506
+ } else {
2507
+ this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', refParam);
2057
2508
  }
2058
- return (isIdentifier ? key : '"' + key + '"') + ":" + this.serialize(val);
2509
+ return "";
2059
2510
  }
2511
+ return (isIdentifier ? key : '"' + key + '"') + ":" + this.serialize(val);
2060
2512
  }
2513
+ return "[" + this.serialize(key) + "]:" + this.serialize(val);
2061
2514
  }
2062
- serializeProperties(sourceID, node) {
2063
- const len = node.s;
2515
+ serializeProperties(source, record) {
2516
+ const len = record.s;
2064
2517
  if (len) {
2065
- this.stack.push(sourceID);
2066
- const keys = node.k;
2067
- const values = node.v;
2068
- let result = this.serializeProperty(sourceID, keys[0], values[0]);
2518
+ this.stack.push(source.i);
2519
+ const keys = record.k;
2520
+ const values = record.v;
2521
+ let result = this.serializeProperty(source, keys[0], values[0]);
2069
2522
  for (let i = 1, item = result; i < len; i++) {
2070
- item = this.serializeProperty(sourceID, keys[i], values[i]);
2523
+ item = this.serializeProperty(source, keys[i], values[i]);
2071
2524
  result += (item && result && ",") + item;
2072
2525
  }
2073
2526
  this.stack.pop();
@@ -2077,88 +2530,83 @@ var BaseSerializerContext = class {
2077
2530
  }
2078
2531
  serializeObject(node) {
2079
2532
  this.pushObjectFlag(node.o, node.i);
2080
- return this.assignIndexedValue(node.i, this.serializeProperties(node.i, node.p));
2533
+ return this.assignIndexedValue(node.i, this.serializeProperties(node, node.p));
2081
2534
  }
2082
- serializeWithObjectAssign(value, id, serialized) {
2083
- const fields = this.serializeProperties(id, value);
2535
+ serializeWithObjectAssign(source, value, serialized) {
2536
+ const fields = this.serializeProperties(source, value);
2084
2537
  if (fields !== "{}") {
2085
2538
  return "Object.assign(" + serialized + "," + fields + ")";
2086
2539
  }
2087
2540
  return serialized;
2088
2541
  }
2089
- serializeAssignment(sourceID, mainAssignments, key, value) {
2090
- switch (key) {
2091
- case 0 /* SymbolIterator */:
2092
- {
2093
- const parent = this.stack;
2094
- this.stack = [];
2095
- const serialized = this.serialize(value) + this.getIterableAccess();
2096
- this.stack = parent;
2097
- const parentAssignment = this.assignments;
2098
- this.assignments = mainAssignments;
2099
- this.createArrayAssign(
2100
- sourceID,
2101
- this.getSpecialReference(0 /* Sentinel */),
2102
- this.features & 4 /* ArrowFunction */ ? "()=>" + serialized : "function(){return " + serialized + "}"
2103
- );
2104
- this.assignments = parentAssignment;
2542
+ serializeAssignment(source, mainAssignments, key, value) {
2543
+ if (typeof key === "string") {
2544
+ const serialized = this.serialize(value);
2545
+ const check = Number(key);
2546
+ const isIdentifier = check >= 0 || isValidIdentifier(key);
2547
+ if (this.isIndexedValueInStack(value)) {
2548
+ if (isIdentifier && check !== check) {
2549
+ this.createObjectAssign(source.i, key, serialized);
2550
+ } else {
2551
+ this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', serialized);
2105
2552
  }
2106
- break;
2107
- default: {
2108
- const serialized = this.serialize(value);
2109
- const check = Number(key);
2110
- const isIdentifier = check >= 0 || isValidIdentifier(key);
2111
- if (this.isIndexedValueInStack(value)) {
2112
- if (isIdentifier && check !== check) {
2113
- this.createObjectAssign(sourceID, key, serialized);
2114
- } else {
2115
- this.createArrayAssign(sourceID, isIdentifier ? key : '"' + key + '"', serialized);
2116
- }
2553
+ } else {
2554
+ const parentAssignment = this.assignments;
2555
+ this.assignments = mainAssignments;
2556
+ if (isIdentifier) {
2557
+ this.createObjectAssign(source.i, key, serialized);
2117
2558
  } else {
2118
- const parentAssignment = this.assignments;
2119
- this.assignments = mainAssignments;
2120
- if (isIdentifier) {
2121
- this.createObjectAssign(sourceID, key, serialized);
2122
- } else {
2123
- this.createArrayAssign(sourceID, isIdentifier ? key : '"' + key + '"', serialized);
2124
- }
2125
- this.assignments = parentAssignment;
2559
+ this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', serialized);
2126
2560
  }
2561
+ this.assignments = parentAssignment;
2127
2562
  }
2563
+ } else {
2564
+ const parent = this.stack;
2565
+ this.stack = [];
2566
+ const serialized = this.serialize(value);
2567
+ this.stack = parent;
2568
+ const parentAssignment = this.assignments;
2569
+ this.assignments = mainAssignments;
2570
+ this.createArrayAssign(
2571
+ source.i,
2572
+ this.serialize(key),
2573
+ serialized
2574
+ );
2575
+ this.assignments = parentAssignment;
2128
2576
  }
2129
2577
  }
2130
- serializeAssignments(sourceID, node) {
2578
+ serializeAssignments(source, node) {
2131
2579
  const len = node.s;
2132
2580
  if (len) {
2133
- this.stack.push(sourceID);
2581
+ this.stack.push(source.i);
2134
2582
  const mainAssignments = [];
2135
2583
  const keys = node.k;
2136
2584
  const values = node.v;
2137
2585
  for (let i = 0; i < len; i++) {
2138
- this.serializeAssignment(sourceID, mainAssignments, keys[i], values[i]);
2586
+ this.serializeAssignment(source, mainAssignments, keys[i], values[i]);
2139
2587
  }
2140
2588
  this.stack.pop();
2141
2589
  return resolveAssignments(mainAssignments);
2142
2590
  }
2143
2591
  return void 0;
2144
2592
  }
2145
- serializeDictionary(i, p, init) {
2146
- if (p) {
2593
+ serializeDictionary(node, init) {
2594
+ if (node.p) {
2147
2595
  if (this.features & 128 /* ObjectAssign */) {
2148
- init = this.serializeWithObjectAssign(p, i, init);
2596
+ init = this.serializeWithObjectAssign(node, node.p, init);
2149
2597
  } else {
2150
- this.markRef(i);
2151
- const assignments = this.serializeAssignments(i, p);
2598
+ this.markRef(node.i);
2599
+ const assignments = this.serializeAssignments(node, node.p);
2152
2600
  if (assignments) {
2153
- return "(" + this.assignIndexedValue(i, init) + "," + assignments + this.getRefParam(i) + ")";
2601
+ return "(" + this.assignIndexedValue(node.i, init) + "," + assignments + this.getRefParam(node.i) + ")";
2154
2602
  }
2155
2603
  }
2156
2604
  }
2157
- return this.assignIndexedValue(i, init);
2605
+ return this.assignIndexedValue(node.i, init);
2158
2606
  }
2159
2607
  serializeNullConstructor(node) {
2160
2608
  this.pushObjectFlag(node.o, node.i);
2161
- return this.serializeDictionary(node.i, node.p, NULL_CONSTRUCTOR);
2609
+ return this.serializeDictionary(node, NULL_CONSTRUCTOR);
2162
2610
  }
2163
2611
  serializeDate(node) {
2164
2612
  return this.assignIndexedValue(node.i, 'new Date("' + node.s + '")');
@@ -2193,7 +2641,7 @@ var BaseSerializerContext = class {
2193
2641
  }
2194
2642
  return this.assignIndexedValue(id, serialized);
2195
2643
  }
2196
- serializeMapEntry(id, key, val) {
2644
+ serializeMapEntry(id, key, val, sentinel) {
2197
2645
  if (this.isIndexedValueInStack(key)) {
2198
2646
  const keyRef = this.getRefParam(key.i);
2199
2647
  this.markRef(id);
@@ -2203,9 +2651,9 @@ var BaseSerializerContext = class {
2203
2651
  return "";
2204
2652
  }
2205
2653
  if (val.t !== 4 /* IndexedValue */ && val.i != null && this.isMarked(val.i)) {
2206
- const serialized = "(" + this.serialize(val) + ",[" + this.getSpecialReference(0 /* Sentinel */) + "," + this.getSpecialReference(0 /* Sentinel */) + "])";
2654
+ const serialized = "(" + this.serialize(val) + ",[" + sentinel + "," + sentinel + "])";
2207
2655
  this.createSetAssignment(id, keyRef, this.getRefParam(val.i));
2208
- this.createDeleteAssignment(id, this.getSpecialReference(0 /* Sentinel */));
2656
+ this.createDeleteAssignment(id, sentinel);
2209
2657
  return serialized;
2210
2658
  }
2211
2659
  const parent = this.stack;
@@ -2218,9 +2666,9 @@ var BaseSerializerContext = class {
2218
2666
  const valueRef = this.getRefParam(val.i);
2219
2667
  this.markRef(id);
2220
2668
  if (key.t !== 4 /* IndexedValue */ && key.i != null && this.isMarked(key.i)) {
2221
- const serialized = "(" + this.serialize(key) + ",[" + this.getSpecialReference(0 /* Sentinel */) + "," + this.getSpecialReference(0 /* Sentinel */) + "])";
2669
+ const serialized = "(" + this.serialize(key) + ",[" + sentinel + "," + sentinel + "])";
2222
2670
  this.createSetAssignment(id, this.getRefParam(key.i), valueRef);
2223
- this.createDeleteAssignment(id, this.getSpecialReference(0 /* Sentinel */));
2671
+ this.createDeleteAssignment(id, sentinel);
2224
2672
  return serialized;
2225
2673
  }
2226
2674
  const parent = this.stack;
@@ -2235,13 +2683,15 @@ var BaseSerializerContext = class {
2235
2683
  let serialized = MAP_CONSTRUCTOR;
2236
2684
  const size = node.e.s;
2237
2685
  const id = node.i;
2686
+ const sentinel = node.f;
2687
+ const sentinelID = this.getRefParam(sentinel.i);
2238
2688
  if (size) {
2239
2689
  const keys = node.e.k;
2240
2690
  const vals = node.e.v;
2241
2691
  this.stack.push(id);
2242
- let result = this.serializeMapEntry(id, keys[0], vals[0]);
2692
+ let result = this.serializeMapEntry(id, keys[0], vals[0], sentinelID);
2243
2693
  for (let i = 1, item = result; i < size; i++) {
2244
- item = this.serializeMapEntry(id, keys[i], vals[i]);
2694
+ item = this.serializeMapEntry(id, keys[i], vals[i], sentinelID);
2245
2695
  result += (item && result && ",") + item;
2246
2696
  }
2247
2697
  this.stack.pop();
@@ -2249,6 +2699,10 @@ var BaseSerializerContext = class {
2249
2699
  serialized += "([" + result + "])";
2250
2700
  }
2251
2701
  }
2702
+ if (sentinel.t === 41 /* MapSentinel */) {
2703
+ this.markRef(sentinel.i);
2704
+ serialized = "(" + this.serialize(sentinel) + "," + serialized + ")";
2705
+ }
2252
2706
  return this.assignIndexedValue(id, serialized);
2253
2707
  }
2254
2708
  serializeArrayBuffer(node) {
@@ -2281,10 +2735,10 @@ var BaseSerializerContext = class {
2281
2735
  this.stack.push(id);
2282
2736
  const serialized = 'new AggregateError([],"' + node.m + '")';
2283
2737
  this.stack.pop();
2284
- return this.serializeDictionary(id, node.p, serialized);
2738
+ return this.serializeDictionary(node, serialized);
2285
2739
  }
2286
2740
  serializeError(node) {
2287
- return this.serializeDictionary(node.i, node.p, "new " + ERROR_CONSTRUCTOR_STRING[node.s] + '("' + node.m + '")');
2741
+ return this.serializeDictionary(node, "new " + ERROR_CONSTRUCTOR_STRING[node.s] + '("' + node.m + '")');
2288
2742
  }
2289
2743
  serializePromise(node) {
2290
2744
  let serialized;
@@ -2293,17 +2747,7 @@ var BaseSerializerContext = class {
2293
2747
  const constructor = node.s ? PROMISE_RESOLVE : PROMISE_REJECT;
2294
2748
  if (this.isIndexedValueInStack(fulfilled)) {
2295
2749
  const ref = this.getRefParam(fulfilled.i);
2296
- if (this.features & 4 /* ArrowFunction */) {
2297
- if (node.s) {
2298
- serialized = constructor + "().then(()=>" + ref + ")";
2299
- } else {
2300
- serialized = constructor + "().catch(()=>{throw " + ref + "})";
2301
- }
2302
- } else if (node.s) {
2303
- serialized = constructor + "().then(function(){return " + ref + "})";
2304
- } else {
2305
- serialized = constructor + "().catch(function(){throw " + ref + "})";
2306
- }
2750
+ serialized = constructor + (node.s ? "().then(" + this.createFunction([], ref) + ")" : "().catch(" + this.createEffectfulFunction([], "throw " + ref) + ")");
2307
2751
  } else {
2308
2752
  this.stack.push(id);
2309
2753
  const result = this.serialize(fulfilled);
@@ -2339,7 +2783,7 @@ var BaseSerializerContext = class {
2339
2783
  serializeHeaders(node) {
2340
2784
  return this.assignIndexedValue(
2341
2785
  node.i,
2342
- "new Headers(" + this.serializeProperties(node.i, node.e) + ")"
2786
+ "new Headers(" + this.serializeProperties(node, node.e) + ")"
2343
2787
  );
2344
2788
  }
2345
2789
  serializeFormDataEntry(id, key, value) {
@@ -2383,35 +2827,104 @@ var BaseSerializerContext = class {
2383
2827
  serializeEvent(node) {
2384
2828
  return this.assignIndexedValue(
2385
2829
  node.i,
2386
- 'new Event("' + node.s + '",' + this.serialize(node.f) + ")"
2830
+ 'new Event("' + node.s + '",' + this.serialize(node.f) + ")"
2831
+ );
2832
+ }
2833
+ serializeCustomEvent(node) {
2834
+ return this.assignIndexedValue(
2835
+ node.i,
2836
+ 'new CustomEvent("' + node.s + '",' + this.serialize(node.f) + ")"
2837
+ );
2838
+ }
2839
+ serializeDOMException(node) {
2840
+ return this.assignIndexedValue(
2841
+ node.i,
2842
+ 'new DOMException("' + node.s + '","' + node.c + '")'
2843
+ );
2844
+ }
2845
+ serializePlugin(node) {
2846
+ const currentPlugins = this.plugins;
2847
+ if (currentPlugins) {
2848
+ for (let i = 0, len = currentPlugins.length; i < len; i++) {
2849
+ const plugin = currentPlugins[i];
2850
+ if (plugin.tag === node.c) {
2851
+ return this.assignIndexedValue(
2852
+ node.i,
2853
+ plugin.serialize(node.s, this, {
2854
+ id: node.i
2855
+ })
2856
+ );
2857
+ }
2858
+ }
2859
+ }
2860
+ throw new Error('Missing plugin for tag "' + node.c + '".');
2861
+ }
2862
+ serializeMapSentinel(node) {
2863
+ return this.assignIndexedValue(
2864
+ node.i,
2865
+ "[]"
2866
+ );
2867
+ }
2868
+ serializeIteratorFactory(node) {
2869
+ return this.assignIndexedValue(
2870
+ node.i,
2871
+ this.createFunction(
2872
+ ["s"],
2873
+ this.createFunction(
2874
+ ["i", "c", "d", "t"],
2875
+ "(i=0,t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction([], "if(i>s.d)return{done:!0,value:void 0};c=i++,d=s.v[c];if(c===s.t)throw d;return{done:c===s.d,value:d}") + "})"
2876
+ )
2877
+ )
2878
+ );
2879
+ }
2880
+ serializeIteratorFactoryInstance(node) {
2881
+ return "(" + this.serialize(node.a[0]) + ")(" + this.serialize(node.a[1]) + ")";
2882
+ }
2883
+ serializeAsyncIteratorFactory(node) {
2884
+ return this.assignIndexedValue(
2885
+ node.i,
2886
+ this.createFunction(
2887
+ ["s"],
2888
+ this.createFunction(
2889
+ ["i", "t"],
2890
+ "(i=0,t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createFunction(
2891
+ [],
2892
+ "Promise.resolve().then(" + this.createEffectfulFunction(
2893
+ ["c", "d"],
2894
+ "if(i>s.d)return{done:!0,value:void 0};c=i++,d=s.v[c];if(c===s.t)throw d;return{done:c===s.d,value:d}"
2895
+ ) + ")"
2896
+ ) + "})"
2897
+ )
2898
+ )
2387
2899
  );
2388
2900
  }
2389
- serializeCustomEvent(node) {
2901
+ serializeAsyncIteratorFactoryInstance(node) {
2902
+ return "(" + this.serialize(node.a[0]) + ")(" + this.serialize(node.a[1]) + ")";
2903
+ }
2904
+ serializeReadableStream(node) {
2905
+ this.stack.push(node.i);
2906
+ const result = "(" + this.serialize(node.a[0]) + ")(" + this.serialize(node.a[1]) + ")";
2907
+ this.stack.pop();
2390
2908
  return this.assignIndexedValue(
2391
2909
  node.i,
2392
- 'new CustomEvent("' + node.s + '",' + this.serialize(node.f) + ")"
2910
+ result
2393
2911
  );
2394
2912
  }
2395
- serializeDOMException(node) {
2913
+ serializeReadableStreamFactory(node) {
2396
2914
  return this.assignIndexedValue(
2397
2915
  node.i,
2398
- 'new DOMException("' + node.s + '","' + node.c + '")'
2916
+ this.createFunction(
2917
+ ["s"],
2918
+ "new ReadableStream({start:" + this.createFunction(
2919
+ ["c"],
2920
+ "Promise.resolve().then(" + this.createEffectfulFunction(
2921
+ ["i", "v"],
2922
+ "for(i=0;i<s.d;i++)c.enqueue(s.v[i]);(s.t===-1)?c.close():c.error(s.v[i])"
2923
+ ) + ")"
2924
+ ) + "})"
2925
+ )
2399
2926
  );
2400
2927
  }
2401
- serializePlugin(node) {
2402
- const currentPlugins = this.plugins;
2403
- if (currentPlugins) {
2404
- for (let i = 0, len = currentPlugins.length; i < len; i++) {
2405
- const plugin = currentPlugins[i];
2406
- if (plugin.tag === node.c) {
2407
- return plugin.serialize(node.s, this, {
2408
- id: node.i
2409
- });
2410
- }
2411
- }
2412
- }
2413
- throw new Error('Missing plugin for tag "' + node.c + '".');
2414
- }
2415
2928
  serialize(node) {
2416
2929
  switch (node.t) {
2417
2930
  case 2 /* Constant */:
@@ -2495,13 +3008,27 @@ var BaseSerializerContext = class {
2495
3008
  return this.serializeDOMException(node);
2496
3009
  case 40 /* Plugin */:
2497
3010
  return this.serializePlugin(node);
3011
+ case 41 /* MapSentinel */:
3012
+ return this.serializeMapSentinel(node);
3013
+ case 42 /* IteratorFactory */:
3014
+ return this.serializeIteratorFactory(node);
3015
+ case 43 /* IteratorFactoryInstance */:
3016
+ return this.serializeIteratorFactoryInstance(node);
3017
+ case 44 /* AsyncIteratorFactory */:
3018
+ return this.serializeAsyncIteratorFactory(node);
3019
+ case 45 /* AsyncIteratorFactoryInstance */:
3020
+ return this.serializeAsyncIteratorFactoryInstance(node);
3021
+ case 46 /* ReadableStream */:
3022
+ return this.serializeReadableStream(node);
3023
+ case 47 /* ReadableStreamFactory */:
3024
+ return this.serializeReadableStreamFactory(node);
2498
3025
  default:
2499
3026
  throw new Error("invariant");
2500
3027
  }
2501
3028
  }
2502
3029
  };
2503
3030
 
2504
- // src/core/get-identifier.ts
3031
+ // src/core/utils/get-identifier.ts
2505
3032
  var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
2506
3033
  var REF_START_CHARS_LEN = REF_START_CHARS.length;
2507
3034
  var REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
@@ -2518,7 +3045,7 @@ function getIdentifier(index) {
2518
3045
  return ref;
2519
3046
  }
2520
3047
 
2521
- // src/core/tree/serialize.ts
3048
+ // src/core/tree/serializer.ts
2522
3049
  var VanillaSerializerContext = class extends BaseSerializerContext {
2523
3050
  constructor() {
2524
3051
  super(...arguments);
@@ -2596,12 +3123,7 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
2596
3123
  body = index + "=" + body;
2597
3124
  }
2598
3125
  }
2599
- let params = this.vars.length > 1 ? this.vars.join(",") : this.vars[0];
2600
- if (this.features & 4 /* ArrowFunction */) {
2601
- params = this.vars.length > 1 || this.vars.length === 0 ? "(" + params + ")" : params;
2602
- return "(" + params + "=>(" + body + "))()";
2603
- }
2604
- return "(function(" + params + "){return " + body + "})()";
3126
+ return "(" + this.createFunction(this.vars, "(" + body + ")") + ")()";
2605
3127
  }
2606
3128
  if (tree.t === 10 /* Object */) {
2607
3129
  return "(" + result + ")";
@@ -2610,70 +3132,56 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
2610
3132
  }
2611
3133
  };
2612
3134
 
2613
- // src/core/base/sync.ts
3135
+ // src/core/context/parser/sync.ts
2614
3136
  var BaseSyncParserContext = class extends BaseParserContext {
2615
3137
  parseItems(current) {
2616
- const size = current.length;
2617
3138
  const nodes = [];
2618
- const deferred = [];
2619
- for (let i = 0, item; i < size; i++) {
3139
+ for (let i = 0, len = current.length; i < len; i++) {
2620
3140
  if (i in current) {
2621
- item = current[i];
2622
- if (this.isIterable(item)) {
2623
- deferred[i] = item;
2624
- } else {
2625
- nodes[i] = this.parse(item);
2626
- }
2627
- }
2628
- }
2629
- for (let i = 0; i < size; i++) {
2630
- if (i in deferred) {
2631
- nodes[i] = this.parse(deferred[i]);
3141
+ nodes[i] = this.parse(current[i]);
2632
3142
  }
2633
3143
  }
2634
3144
  return nodes;
2635
3145
  }
2636
3146
  parseArray(id, current) {
2637
- return {
2638
- t: 9 /* Array */,
2639
- i: id,
2640
- s: void 0,
2641
- l: current.length,
2642
- c: void 0,
2643
- m: void 0,
2644
- p: void 0,
2645
- e: void 0,
2646
- a: this.parseItems(current),
2647
- f: void 0,
2648
- b: void 0,
2649
- o: getObjectFlag(current)
2650
- };
3147
+ return createArrayNode(
3148
+ id,
3149
+ current,
3150
+ this.parseItems(current)
3151
+ );
2651
3152
  }
2652
3153
  parseProperties(properties) {
2653
3154
  const entries = Object.entries(properties);
2654
3155
  const keyNodes = [];
2655
3156
  const valueNodes = [];
2656
- const deferredKeys = [];
2657
- const deferredValues = [];
2658
- for (let i = 0, len = entries.length, key, item; i < len; i++) {
2659
- key = serializeString(entries[i][0]);
2660
- item = entries[i][1];
2661
- if (this.isIterable(item)) {
2662
- deferredKeys.push(key);
2663
- deferredValues.push(item);
2664
- } else {
2665
- keyNodes.push(key);
2666
- valueNodes.push(this.parse(item));
2667
- }
2668
- }
2669
- for (let i = 0, len = deferredKeys.length; i < len; i++) {
2670
- keyNodes.push(deferredKeys[i]);
2671
- valueNodes.push(this.parse(deferredValues[i]));
3157
+ for (let i = 0, len = entries.length; i < len; i++) {
3158
+ keyNodes.push(serializeString(entries[i][0]));
3159
+ valueNodes.push(this.parse(entries[i][1]));
2672
3160
  }
2673
3161
  if (this.features & 1024 /* Symbol */) {
2674
- if (Symbol.iterator in properties) {
2675
- keyNodes.push(0 /* SymbolIterator */);
2676
- valueNodes.push(this.parse(Array.from(properties)));
3162
+ let symbol = Symbol.iterator;
3163
+ if (symbol in properties) {
3164
+ keyNodes.push(
3165
+ this.parseWKSymbol(symbol)
3166
+ );
3167
+ valueNodes.push(
3168
+ createIteratorFactoryInstanceNode(
3169
+ this.parseIteratorFactory(),
3170
+ this.parse(
3171
+ iteratorToSequence(properties)
3172
+ )
3173
+ )
3174
+ );
3175
+ }
3176
+ symbol = Symbol.toStringTag;
3177
+ if (symbol in properties) {
3178
+ keyNodes.push(this.parseWKSymbol(symbol));
3179
+ valueNodes.push(createStringNode(properties[symbol]));
3180
+ }
3181
+ symbol = Symbol.isConcatSpreadable;
3182
+ if (symbol in properties) {
3183
+ keyNodes.push(this.parseWKSymbol(symbol));
3184
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
2677
3185
  }
2678
3186
  }
2679
3187
  return {
@@ -2683,184 +3191,69 @@ var BaseSyncParserContext = class extends BaseParserContext {
2683
3191
  };
2684
3192
  }
2685
3193
  parsePlainObject(id, current, empty) {
2686
- return {
2687
- t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
2688
- i: id,
2689
- s: void 0,
2690
- l: void 0,
2691
- c: void 0,
2692
- m: void 0,
2693
- p: this.parseProperties(current),
2694
- e: void 0,
2695
- a: void 0,
2696
- f: void 0,
2697
- b: void 0,
2698
- o: getObjectFlag(current)
2699
- };
3194
+ return this.createObjectNode(
3195
+ id,
3196
+ current,
3197
+ empty,
3198
+ this.parseProperties(current)
3199
+ );
2700
3200
  }
2701
3201
  parseBoxed(id, current) {
2702
- return {
2703
- t: 27 /* Boxed */,
2704
- i: id,
2705
- s: void 0,
2706
- l: void 0,
2707
- c: void 0,
2708
- m: void 0,
2709
- p: void 0,
2710
- e: void 0,
2711
- a: void 0,
2712
- f: this.parse(current.valueOf()),
2713
- b: void 0,
2714
- o: void 0
2715
- };
3202
+ return createBoxedNode(id, this.parse(current.valueOf()));
2716
3203
  }
2717
3204
  parseTypedArray(id, current) {
2718
- return {
2719
- t: 15 /* TypedArray */,
2720
- i: id,
2721
- s: void 0,
2722
- l: current.length,
2723
- c: current.constructor.name,
2724
- m: void 0,
2725
- p: void 0,
2726
- e: void 0,
2727
- a: void 0,
2728
- f: this.parse(current.buffer),
2729
- b: current.byteOffset,
2730
- o: void 0
2731
- };
3205
+ return createTypedArrayNode(id, current, this.parse(current.buffer));
2732
3206
  }
2733
3207
  parseBigIntTypedArray(id, current) {
2734
- return {
2735
- t: 16 /* BigIntTypedArray */,
2736
- i: id,
2737
- s: void 0,
2738
- l: current.length,
2739
- c: current.constructor.name,
2740
- m: void 0,
2741
- p: void 0,
2742
- e: void 0,
2743
- a: void 0,
2744
- f: this.parse(current.buffer),
2745
- b: current.byteOffset,
2746
- o: void 0
2747
- };
3208
+ return createBigIntTypedArrayNode(id, current, this.parse(current.buffer));
2748
3209
  }
2749
3210
  parseDataView(id, current) {
2750
- return {
2751
- t: 22 /* DataView */,
2752
- i: id,
2753
- s: void 0,
2754
- l: current.byteLength,
2755
- c: void 0,
2756
- m: void 0,
2757
- p: void 0,
2758
- e: void 0,
2759
- a: void 0,
2760
- f: this.parse(current.buffer),
2761
- b: current.byteOffset,
2762
- o: void 0
2763
- };
3211
+ return createDataViewNode(id, current, this.parse(current.buffer));
2764
3212
  }
2765
3213
  parseError(id, current) {
2766
3214
  const options = getErrorOptions(current, this.features);
2767
- const optionsNode = options ? this.parseProperties(options) : void 0;
2768
- return {
2769
- t: 13 /* Error */,
2770
- i: id,
2771
- s: getErrorConstructor(current),
2772
- l: void 0,
2773
- c: void 0,
2774
- m: serializeString(current.message),
2775
- p: optionsNode,
2776
- e: void 0,
2777
- a: void 0,
2778
- f: void 0,
2779
- b: void 0,
2780
- o: void 0
2781
- };
3215
+ return createErrorNode(
3216
+ id,
3217
+ current,
3218
+ options ? this.parseProperties(options) : void 0
3219
+ );
3220
+ }
3221
+ parseAggregateError(id, current) {
3222
+ const options = getErrorOptions(current, this.features);
3223
+ return createAggregateErrorNode(
3224
+ id,
3225
+ current,
3226
+ options ? this.parseProperties(options) : void 0
3227
+ );
2782
3228
  }
2783
3229
  parseMap(id, current) {
2784
3230
  const keyNodes = [];
2785
3231
  const valueNodes = [];
2786
- const deferredKey = [];
2787
- const deferredValue = [];
2788
3232
  for (const [key, value] of current.entries()) {
2789
- if (this.isIterable(key) || this.isIterable(value)) {
2790
- deferredKey.push(key);
2791
- deferredValue.push(value);
2792
- } else {
2793
- keyNodes.push(this.parse(key));
2794
- valueNodes.push(this.parse(value));
2795
- }
2796
- }
2797
- for (let i = 0, len = deferredKey.length; i < len; i++) {
2798
- keyNodes.push(this.parse(deferredKey[i]));
2799
- valueNodes.push(this.parse(deferredValue[i]));
2800
- }
2801
- return {
2802
- t: 8 /* Map */,
2803
- i: id,
2804
- s: void 0,
2805
- l: void 0,
2806
- c: void 0,
2807
- m: void 0,
2808
- p: void 0,
2809
- e: { k: keyNodes, v: valueNodes, s: current.size },
2810
- a: void 0,
2811
- f: void 0,
2812
- b: void 0,
2813
- o: void 0
2814
- };
3233
+ keyNodes.push(this.parse(key));
3234
+ valueNodes.push(this.parse(value));
3235
+ }
3236
+ return this.createMapNode(
3237
+ id,
3238
+ keyNodes,
3239
+ valueNodes,
3240
+ current.size
3241
+ );
2815
3242
  }
2816
3243
  parseSet(id, current) {
2817
- const nodes = [];
2818
- const deferred = [];
3244
+ const items = [];
2819
3245
  for (const item of current.keys()) {
2820
- if (this.isIterable(item)) {
2821
- deferred.push(item);
2822
- } else {
2823
- nodes.push(this.parse(item));
2824
- }
3246
+ items.push(this.parse(item));
2825
3247
  }
2826
- for (let i = 0, len = deferred.length; i < len; i++) {
2827
- nodes.push(this.parse(deferred[i]));
2828
- }
2829
- return {
2830
- t: 7 /* Set */,
2831
- i: id,
2832
- s: void 0,
2833
- l: current.size,
2834
- c: void 0,
2835
- m: void 0,
2836
- p: void 0,
2837
- e: void 0,
2838
- a: nodes,
2839
- f: void 0,
2840
- b: void 0,
2841
- o: void 0
2842
- };
3248
+ return createSetNode(id, current.size, items);
2843
3249
  }
2844
3250
  parsePlainProperties(entries) {
2845
3251
  const size = entries.length;
2846
3252
  const keyNodes = [];
2847
3253
  const valueNodes = [];
2848
- const deferredKeys = [];
2849
- const deferredValues = [];
2850
- for (let i = 0, key, item; i < size; i++) {
2851
- key = serializeString(entries[i][0]);
2852
- item = entries[i][1];
2853
- if (this.isIterable(item)) {
2854
- deferredKeys.push(key);
2855
- deferredValues.push(item);
2856
- } else {
2857
- keyNodes.push(key);
2858
- valueNodes.push(this.parse(item));
2859
- }
2860
- }
2861
- for (let i = 0, len = deferredKeys.length; i < len; i++) {
2862
- keyNodes.push(deferredKeys[i]);
2863
- valueNodes.push(this.parse(deferredValues[i]));
3254
+ for (let i = 0; i < size; i++) {
3255
+ keyNodes.push(serializeString(entries[i][0]));
3256
+ valueNodes.push(this.parse(entries[i][1]));
2864
3257
  }
2865
3258
  return {
2866
3259
  k: keyNodes,
@@ -2909,54 +3302,10 @@ var BaseSyncParserContext = class extends BaseParserContext {
2909
3302
  };
2910
3303
  }
2911
3304
  parseEvent(id, current) {
2912
- return {
2913
- t: 37 /* Event */,
2914
- i: id,
2915
- s: serializeString(current.type),
2916
- l: void 0,
2917
- c: void 0,
2918
- m: void 0,
2919
- p: void 0,
2920
- e: void 0,
2921
- a: void 0,
2922
- f: this.parse(createEventOptions(current)),
2923
- b: void 0,
2924
- o: void 0
2925
- };
3305
+ return createEventNode(id, current.type, this.parse(createEventOptions(current)));
2926
3306
  }
2927
3307
  parseCustomEvent(id, current) {
2928
- return {
2929
- t: 38 /* CustomEvent */,
2930
- i: id,
2931
- s: serializeString(current.type),
2932
- l: void 0,
2933
- c: void 0,
2934
- m: void 0,
2935
- p: void 0,
2936
- e: void 0,
2937
- a: void 0,
2938
- f: this.parse(createCustomEventOptions(current)),
2939
- b: void 0,
2940
- o: void 0
2941
- };
2942
- }
2943
- parseAggregateError(id, current) {
2944
- const options = getErrorOptions(current, this.features);
2945
- const optionsNode = options ? this.parseProperties(options) : void 0;
2946
- return {
2947
- t: 14 /* AggregateError */,
2948
- i: id,
2949
- s: void 0,
2950
- l: void 0,
2951
- c: void 0,
2952
- m: serializeString(current.message),
2953
- p: optionsNode,
2954
- e: void 0,
2955
- a: void 0,
2956
- f: void 0,
2957
- b: void 0,
2958
- o: void 0
2959
- };
3308
+ return createCustomEventNode(id, current.type, this.parse(createCustomEventOptions(current)));
2960
3309
  }
2961
3310
  parsePlugin(id, current) {
2962
3311
  const currentPlugins = this.plugins;
@@ -3214,7 +3563,21 @@ var CrossAsyncParserContext = class extends BaseAsyncParserContext {
3214
3563
  }
3215
3564
  };
3216
3565
 
3217
- // src/core/cross/serialize.ts
3566
+ // src/core/cross/deserializer.ts
3567
+ var CrossDeserializerContext = class extends BaseDeserializerContext {
3568
+ constructor() {
3569
+ super(...arguments);
3570
+ this.mode = "cross";
3571
+ }
3572
+ assignIndexedValue(index, value) {
3573
+ if (!this.refs.has(index)) {
3574
+ this.refs.set(index, value);
3575
+ }
3576
+ return value;
3577
+ }
3578
+ };
3579
+
3580
+ // src/core/cross/serializer.ts
3218
3581
  var CrossSerializerContext = class extends BaseSerializerContext {
3219
3582
  constructor(options) {
3220
3583
  super(options);
@@ -3243,13 +3606,31 @@ var CrossSerializerContext = class extends BaseSerializerContext {
3243
3606
  return this.assignIndexedValue(node.i, GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_CONSTRUCTOR + "()");
3244
3607
  }
3245
3608
  serializeReadableStreamEnqueue(node) {
3246
- return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_EMIT + "(" + this.getRefParam(node.i) + ",0," + this.serialize(node.f) + ")";
3609
+ return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_ENQUEUE + "(" + this.getRefParam(node.i) + "," + this.serialize(node.f) + ")";
3247
3610
  }
3248
3611
  serializeReadableStreamError(node) {
3249
- return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_EMIT + "(" + this.getRefParam(node.i) + ",1," + this.serialize(node.f) + ")";
3612
+ return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_ERROR + "(" + this.getRefParam(node.i) + "," + this.serialize(node.f) + ")";
3250
3613
  }
3251
3614
  serializeReadableStreamClose(node) {
3252
- return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_EMIT + "(" + this.getRefParam(node.i) + ",2)";
3615
+ return GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_CLOSE + "(" + this.getRefParam(node.i) + ")";
3616
+ }
3617
+ serializeAsyncIteratorFactory(node) {
3618
+ return this.assignIndexedValue(
3619
+ node.i,
3620
+ this.createFunction(
3621
+ ["s"],
3622
+ this.createFunction(
3623
+ ["b", "t"],
3624
+ "(b=s.tee(),s=b[0],b=b[1].getReader(),t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createFunction(
3625
+ [],
3626
+ "b.read().then(" + this.createEffectfulFunction(
3627
+ ["d"],
3628
+ "if(d.done)return{done:!0,value:void 0};d=d.value;if(d[0]===1)throw d[1];return{done:d[0]===2,value:d[1]}"
3629
+ ) + ")"
3630
+ ) + "})"
3631
+ )
3632
+ )
3633
+ );
3253
3634
  }
3254
3635
  serializeTop(tree) {
3255
3636
  const result = this.serialize(tree);
@@ -3266,14 +3647,11 @@ var CrossSerializerContext = class extends BaseSerializerContext {
3266
3647
  }
3267
3648
  const args = this.scopeId == null ? "()" : "(" + GLOBAL_CONTEXT_REFERENCES + '["' + serializeString(this.scopeId) + '"])';
3268
3649
  const body = mainBody + (patches ? ref : "");
3269
- if (this.features & 4 /* ArrowFunction */) {
3270
- return "(" + params + "=>(" + body + "))" + args;
3271
- }
3272
- return "(function(" + params + "){return " + body + "})" + args;
3650
+ return "(" + this.createFunction([params], body) + ")" + args;
3273
3651
  }
3274
3652
  };
3275
3653
 
3276
- // src/core/base/stream.ts
3654
+ // src/core/context/parser/stream.ts
3277
3655
  var BaseStreamParserContext = class extends BaseSyncParserContext {
3278
3656
  constructor(options) {
3279
3657
  super(options);
@@ -3314,6 +3692,63 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3314
3692
  this.onDone();
3315
3693
  }
3316
3694
  }
3695
+ parseProperties(properties) {
3696
+ const entries = Object.entries(properties);
3697
+ const keyNodes = [];
3698
+ const valueNodes = [];
3699
+ for (let i = 0, len = entries.length; i < len; i++) {
3700
+ keyNodes.push(serializeString(entries[i][0]));
3701
+ valueNodes.push(this.parse(entries[i][1]));
3702
+ }
3703
+ if (this.features & 1024 /* Symbol */) {
3704
+ let symbol = Symbol.iterator;
3705
+ if (symbol in properties) {
3706
+ keyNodes.push(
3707
+ this.parseWKSymbol(symbol)
3708
+ );
3709
+ valueNodes.push(
3710
+ createIteratorFactoryInstanceNode(
3711
+ this.parseIteratorFactory(),
3712
+ this.parse(
3713
+ iteratorToSequence(properties)
3714
+ )
3715
+ )
3716
+ );
3717
+ }
3718
+ symbol = Symbol.asyncIterator;
3719
+ if (symbol in properties) {
3720
+ keyNodes.push(
3721
+ this.parseWKSymbol(symbol)
3722
+ );
3723
+ valueNodes.push(
3724
+ createAsyncIteratorFactoryInstanceNode(
3725
+ this.parseAsyncIteratorFactory(),
3726
+ this.parse(
3727
+ asyncIteratorToReadableStream(
3728
+ properties,
3729
+ this
3730
+ )
3731
+ )
3732
+ )
3733
+ );
3734
+ }
3735
+ symbol = Symbol.toStringTag;
3736
+ if (symbol in properties) {
3737
+ keyNodes.push(this.parseWKSymbol(symbol));
3738
+ valueNodes.push(createStringNode(properties[symbol]));
3739
+ }
3740
+ symbol = Symbol.isConcatSpreadable;
3741
+ if (symbol in properties) {
3742
+ keyNodes.push(this.parseWKSymbol(symbol));
3743
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
3744
+ }
3745
+ }
3746
+ return {
3747
+ k: keyNodes,
3748
+ v: valueNodes,
3749
+ s: keyNodes.length
3750
+ };
3751
+ }
3317
3752
  pushReadableStreamReader(id, reader) {
3318
3753
  reader.read().then(
3319
3754
  (data) => {
@@ -3634,7 +4069,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3634
4069
  if (current instanceof Error) {
3635
4070
  return this.parseError(id, current);
3636
4071
  }
3637
- if (currentFeatures & 1024 /* Symbol */ && Symbol.iterator in current) {
4072
+ if (currentFeatures & 1024 /* Symbol */ && (Symbol.iterator in current || Symbol.asyncIterator in current)) {
3638
4073
  return this.parsePlainObject(id, current, !!currentClass);
3639
4074
  }
3640
4075
  throw new UnsupportedTypeError(current);
@@ -3720,8 +4155,25 @@ async function crossSerializeAsync(source, options = {}) {
3720
4155
  });
3721
4156
  return serial.serializeTop(tree);
3722
4157
  }
4158
+ function toCrossJSON(source, options = {}) {
4159
+ const ctx = new CrossSyncParserContext({
4160
+ plugins: options.plugins,
4161
+ disabledFeatures: options.disabledFeatures,
4162
+ refs: options.refs
4163
+ });
4164
+ return ctx.parse(source);
4165
+ }
4166
+ async function toCrossJSONAsync(source, options = {}) {
4167
+ const ctx = new CrossAsyncParserContext({
4168
+ plugins: options.plugins,
4169
+ disabledFeatures: options.disabledFeatures,
4170
+ refs: options.refs
4171
+ });
4172
+ return ctx.parse(source);
4173
+ }
3723
4174
  function crossSerializeStream(source, options) {
3724
4175
  const ctx = new CrossStreamParserContext({
4176
+ plugins: options.plugins,
3725
4177
  refs: options.refs,
3726
4178
  disabledFeatures: options.disabledFeatures,
3727
4179
  onParse(node, initial) {
@@ -3753,6 +4205,27 @@ function crossSerializeStream(source, options) {
3753
4205
  ctx.destroy();
3754
4206
  };
3755
4207
  }
4208
+ function toCrossJSONStream(source, options) {
4209
+ const ctx = new CrossStreamParserContext({
4210
+ plugins: options.plugins,
4211
+ refs: options.refs,
4212
+ disabledFeatures: options.disabledFeatures,
4213
+ onParse: options.onParse,
4214
+ onError: options.onError,
4215
+ onDone: options.onDone
4216
+ });
4217
+ ctx.start(source);
4218
+ return () => {
4219
+ ctx.destroy();
4220
+ };
4221
+ }
4222
+ function fromCrossJSON(source, options) {
4223
+ const ctx = new CrossDeserializerContext({
4224
+ plugins: options.plugins,
4225
+ refs: options.refs
4226
+ });
4227
+ return ctx.deserialize(source);
4228
+ }
3756
4229
 
3757
4230
  // src/core/Serializer.ts
3758
4231
  var Serializer = class {
@@ -3772,6 +4245,7 @@ var Serializer = class {
3772
4245
  this.pending++;
3773
4246
  this.keys.add(key);
3774
4247
  this.cleanups.push(crossSerializeStream(value, {
4248
+ plugins: this.options.plugins,
3775
4249
  scopeId: this.options.scopeId,
3776
4250
  refs: this.refs,
3777
4251
  disabledFeatures: this.options.disabledFeatures,