seroval 0.4.0-alpha.8 → 0.4.0-alpha.9

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.
@@ -427,14 +427,24 @@ function getIterableOptions(obj) {
427
427
  return void 0;
428
428
  }
429
429
  function isReferenceInStack(ctx, node) {
430
- return node[0] === 2 /* Reference */ && ctx.stack.includes(node[1]);
430
+ return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
431
431
  }
432
432
  function generateRef(ctx, current) {
433
433
  const ref = ctx.refs.has(current);
434
434
  if (ref) {
435
435
  const refID = ctx.refs.get(current) || 0;
436
436
  markRef(ctx, refID);
437
- return [2 /* Reference */, refID];
437
+ return {
438
+ t: 2 /* Reference */,
439
+ i: refID,
440
+ a: void 0,
441
+ s: void 0,
442
+ l: void 0,
443
+ m: void 0,
444
+ c: void 0,
445
+ d: void 0,
446
+ n: void 0
447
+ };
438
448
  }
439
449
  const id = ctx.refs.size;
440
450
  ctx.refs.set(current, id);
@@ -443,18 +453,58 @@ function generateRef(ctx, current) {
443
453
  function generateSemiPrimitiveValue(ctx, current, id) {
444
454
  if (typeof current === "bigint") {
445
455
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
446
- return [1 /* BigInt */, `${current}n`];
456
+ return {
457
+ t: 1 /* BigInt */,
458
+ i: void 0,
459
+ a: void 0,
460
+ s: `${current}n`,
461
+ l: void 0,
462
+ m: void 0,
463
+ c: void 0,
464
+ d: void 0,
465
+ n: void 0
466
+ };
447
467
  }
448
468
  if (constructorCheck(current, Date)) {
449
- return [3 /* Date */, current.toISOString(), id];
469
+ return {
470
+ t: 3 /* Date */,
471
+ i: id,
472
+ a: void 0,
473
+ s: current.toISOString(),
474
+ l: void 0,
475
+ m: void 0,
476
+ c: void 0,
477
+ d: void 0,
478
+ n: void 0
479
+ };
450
480
  }
451
481
  if (constructorCheck(current, RegExp)) {
452
- return [4 /* RegExp */, String(current), id];
482
+ return {
483
+ t: 4 /* RegExp */,
484
+ i: id,
485
+ a: void 0,
486
+ s: String(current),
487
+ l: void 0,
488
+ m: void 0,
489
+ c: void 0,
490
+ d: void 0,
491
+ n: void 0
492
+ };
453
493
  }
454
494
  if (constructorCheck(current, Int8Array) || constructorCheck(current, Int16Array) || constructorCheck(current, Int32Array) || constructorCheck(current, Uint8Array) || constructorCheck(current, Uint16Array) || constructorCheck(current, Uint32Array) || constructorCheck(current, Uint8ClampedArray) || constructorCheck(current, Float32Array) || constructorCheck(current, Float64Array)) {
455
495
  const constructor = current.constructor.name;
456
496
  assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
457
- return [14 /* TypedArray */, [constructor, current.toString(), current.byteOffset], id];
497
+ return {
498
+ t: 14 /* TypedArray */,
499
+ i: id,
500
+ a: void 0,
501
+ s: current.toString(),
502
+ l: current.byteOffset,
503
+ m: void 0,
504
+ c: constructor,
505
+ d: void 0,
506
+ n: void 0
507
+ };
458
508
  }
459
509
  if (constructorCheck(current, BigInt64Array) || constructorCheck(current, BigUint64Array)) {
460
510
  const constructor = current.constructor.name;
@@ -468,11 +518,17 @@ function generateSemiPrimitiveValue(ctx, current, id) {
468
518
  result += `${current[i]}n,`;
469
519
  }
470
520
  result += `"${current[cap]}"`;
471
- return [
472
- 15 /* BigIntTypedArray */,
473
- [constructor, result, current.byteOffset],
474
- id
475
- ];
521
+ return {
522
+ t: 14 /* TypedArray */,
523
+ i: id,
524
+ a: void 0,
525
+ s: result,
526
+ l: current.byteOffset,
527
+ m: void 0,
528
+ c: constructor,
529
+ d: void 0,
530
+ n: void 0
531
+ };
476
532
  }
477
533
  return void 0;
478
534
  }
@@ -529,7 +585,11 @@ async function serializePropertiesAsync(ctx, properties) {
529
585
  keyNodes[nodesSize + i] = deferredKeys[i];
530
586
  valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
531
587
  }
532
- return [keyNodes, valueNodes, size];
588
+ return {
589
+ k: keyNodes,
590
+ v: valueNodes,
591
+ s: size
592
+ };
533
593
  }
534
594
  async function generateSetNode(ctx, current, id) {
535
595
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -548,7 +608,17 @@ async function generateSetNode(ctx, current, id) {
548
608
  for (let i = 0; i < deferredSize; i++) {
549
609
  nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
550
610
  }
551
- return [5 /* Set */, nodes, id];
611
+ return {
612
+ t: 5 /* Set */,
613
+ i: id,
614
+ a: nodes,
615
+ s: void 0,
616
+ l: void 0,
617
+ m: void 0,
618
+ c: void 0,
619
+ d: void 0,
620
+ n: void 0
621
+ };
552
622
  }
553
623
  async function generateMapNode(ctx, current, id) {
554
624
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -574,7 +644,17 @@ async function generateMapNode(ctx, current, id) {
574
644
  keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
575
645
  valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
576
646
  }
577
- return [6 /* Map */, [keyNodes, valueNodes, len], id];
647
+ return {
648
+ t: 6 /* Map */,
649
+ i: id,
650
+ a: void 0,
651
+ s: void 0,
652
+ l: void 0,
653
+ m: void 0,
654
+ c: void 0,
655
+ d: { k: keyNodes, v: valueNodes, s: len },
656
+ n: void 0
657
+ };
578
658
  }
579
659
  async function generateNodeList(ctx, current) {
580
660
  const size = current.length;
@@ -597,42 +677,81 @@ async function generateNodeList(ctx, current) {
597
677
  return nodes;
598
678
  }
599
679
  async function generateArrayNode(ctx, current, id) {
600
- return [7 /* Array */, await generateNodeList(ctx, current), id];
680
+ return {
681
+ t: 7 /* Array */,
682
+ i: id,
683
+ a: await generateNodeList(ctx, current),
684
+ s: void 0,
685
+ l: void 0,
686
+ m: void 0,
687
+ c: void 0,
688
+ d: void 0,
689
+ n: void 0
690
+ };
601
691
  }
602
692
  async function generateAggregateErrorNode(ctx, current, id) {
603
693
  const options = getErrorOptions(current);
604
694
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
605
- const errorsNode = await generateTreeAsync(ctx, current.errors);
606
- return [
607
- 12 /* AggregateError */,
608
- [current.message, optionsNode, errorsNode],
609
- id
610
- ];
695
+ return {
696
+ t: 12 /* AggregateError */,
697
+ i: id,
698
+ a: void 0,
699
+ s: void 0,
700
+ l: void 0,
701
+ m: current.message,
702
+ c: void 0,
703
+ d: optionsNode,
704
+ n: await generateTreeAsync(ctx, current.errors)
705
+ };
611
706
  }
612
707
  async function generateErrorNode(ctx, current, id) {
613
708
  const options = getErrorOptions(current);
614
709
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
615
- return [
616
- 11 /* Error */,
617
- [getErrorConstructor(current), current.message, optionsNode],
618
- id
619
- ];
710
+ return {
711
+ t: 11 /* Error */,
712
+ i: id,
713
+ a: void 0,
714
+ s: void 0,
715
+ l: void 0,
716
+ m: current.message,
717
+ c: getErrorConstructor(current),
718
+ d: optionsNode,
719
+ n: void 0
720
+ };
620
721
  }
621
722
  async function generateIterableNode(ctx, current, id) {
622
723
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
623
724
  const options = getIterableOptions(current);
624
- return [13 /* Iterable */, [
725
+ return {
726
+ t: 13 /* Iterable */,
727
+ i: id,
728
+ s: void 0,
729
+ l: void 0,
730
+ m: void 0,
731
+ c: void 0,
625
732
  // Parse options first before the items
626
- options ? await serializePropertiesAsync(ctx, options) : void 0,
627
- await generateNodeList(ctx, Array.from(current))
628
- ], id];
733
+ d: options ? await serializePropertiesAsync(ctx, options) : void 0,
734
+ a: await generateNodeList(ctx, Array.from(current)),
735
+ n: void 0
736
+ };
629
737
  }
630
738
  async function generateTreeAsync(ctx, current) {
631
739
  if (isPrimitive(current)) {
632
- return [0 /* Primitive */, serializePrimitive(current)];
740
+ return {
741
+ t: 0 /* Primitive */,
742
+ i: void 0,
743
+ s: serializePrimitive(current),
744
+ l: void 0,
745
+ m: void 0,
746
+ c: void 0,
747
+ // Parse options first before the items
748
+ d: void 0,
749
+ a: void 0,
750
+ n: void 0
751
+ };
633
752
  }
634
753
  const id = generateRef(ctx, current);
635
- if (Array.isArray(id)) {
754
+ if (typeof id !== "number") {
636
755
  return id;
637
756
  }
638
757
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -641,11 +760,18 @@ async function generateTreeAsync(ctx, current) {
641
760
  }
642
761
  if (isPromise(current)) {
643
762
  assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
644
- return current.then(async (value) => [
645
- 10 /* Promise */,
646
- await generateTreeAsync(ctx, value),
647
- id
648
- ]);
763
+ return current.then(async (value) => ({
764
+ t: 10 /* Promise */,
765
+ i: id,
766
+ s: void 0,
767
+ l: void 0,
768
+ m: void 0,
769
+ c: void 0,
770
+ // Parse options first before the items
771
+ d: void 0,
772
+ a: void 0,
773
+ n: await generateTreeAsync(ctx, value)
774
+ }));
649
775
  }
650
776
  if (constructorCheck(current, Set)) {
651
777
  return generateSetNode(ctx, current, id);
@@ -667,17 +793,24 @@ async function generateTreeAsync(ctx, current) {
667
793
  }
668
794
  const empty = current.constructor == null;
669
795
  if (current.constructor === Object || empty) {
670
- return [
671
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
672
- await serializePropertiesAsync(ctx, current),
673
- id
674
- ];
796
+ return {
797
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
798
+ i: id,
799
+ s: void 0,
800
+ l: void 0,
801
+ m: void 0,
802
+ c: void 0,
803
+ // Parse options first before the items
804
+ d: await serializePropertiesAsync(ctx, current),
805
+ a: void 0,
806
+ n: void 0
807
+ };
675
808
  }
676
809
  throw new Error("Unsupported value");
677
810
  }
678
811
  async function parseAsync(ctx, current) {
679
812
  const result = await generateTreeAsync(ctx, current);
680
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
813
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
681
814
  }
682
815
 
683
816
  // src/tree/serialize.ts
@@ -785,15 +918,15 @@ function createObjectAssign(ctx, ref, key, value) {
785
918
  createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
786
919
  }
787
920
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
788
- function serializeAssignments(ctx, targetRef, [keys, values, size]) {
921
+ function serializeAssignments(ctx, targetRef, node) {
789
922
  ctx.stack.push(targetRef);
790
923
  const mainAssignments = [];
791
- for (let i = 0; i < size; i++) {
924
+ for (let i = 0; i < node.s; i++) {
792
925
  const parentStack = ctx.stack;
793
926
  ctx.stack = [];
794
- const refParam = serializeTree(ctx, values[i]);
927
+ const refParam = serializeTree(ctx, node.v[i]);
795
928
  ctx.stack = parentStack;
796
- const key = keys[i];
929
+ const key = node.k[i];
797
930
  const check = Number(key);
798
931
  const parentAssignment = ctx.assignments;
799
932
  ctx.assignments = mainAssignments;
@@ -808,19 +941,19 @@ function serializeAssignments(ctx, targetRef, [keys, values, size]) {
808
941
  ctx.stack.pop();
809
942
  return resolveAssignments(mainAssignments);
810
943
  }
811
- function serializeObject(ctx, sourceID, [keys, values, size]) {
812
- if (size === 0) {
944
+ function serializeObject(ctx, sourceID, node) {
945
+ if (node.s === 0) {
813
946
  return "{}";
814
947
  }
815
948
  let result = "";
816
949
  ctx.stack.push(sourceID);
817
- for (let i = 0; i < size; i++) {
818
- const key = keys[i];
819
- const val = values[i];
950
+ for (let i = 0; i < node.s; i++) {
951
+ const key = node.k[i];
952
+ const val = node.v[i];
820
953
  const check = Number(key);
821
954
  const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
822
955
  if (isReferenceInStack(ctx, val)) {
823
- const refParam = getRefParam(ctx, val[1]);
956
+ const refParam = getRefParam(ctx, val.i);
824
957
  if (isIdentifier && Number.isNaN(check)) {
825
958
  createObjectAssign(ctx, sourceID, key, refParam);
826
959
  } else {
@@ -833,35 +966,35 @@ function serializeObject(ctx, sourceID, [keys, values, size]) {
833
966
  ctx.stack.pop();
834
967
  return `{${result.substring(0, result.length - 1)}}`;
835
968
  }
836
- function serializePromise(ctx, value, id) {
969
+ function serializePromise(ctx, node) {
837
970
  let serialized;
838
- if (isReferenceInStack(ctx, value)) {
839
- serialized = `Promise.resolve().then(()=>${getRefParam(ctx, value[1])})`;
971
+ if (isReferenceInStack(ctx, node.n)) {
972
+ serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
840
973
  } else {
841
- ctx.stack.push(id);
842
- const result = serializeTree(ctx, value);
974
+ ctx.stack.push(node.i);
975
+ const result = serializeTree(ctx, node.n);
843
976
  ctx.stack.pop();
844
977
  serialized = `Promise.resolve(${result})`;
845
978
  }
846
- return assignRef(ctx, id, serialized);
979
+ return assignRef(ctx, node.i, serialized);
847
980
  }
848
- function serializeTypedArray(ctx, constructor, init, byteOffset, id) {
849
- let args = `[${init}]`;
850
- if (byteOffset !== 0) {
851
- args += `,${byteOffset}`;
981
+ function serializeTypedArray(ctx, node) {
982
+ let args = `[${node.s}]`;
983
+ if (node.l !== 0) {
984
+ args += `,${node.l}`;
852
985
  }
853
- return assignRef(ctx, id, `new ${constructor}(${args})`);
986
+ return assignRef(ctx, node.i, `new ${node.c}(${args})`);
854
987
  }
855
- function serializeSet(ctx, value, id) {
988
+ function serializeSet(ctx, node) {
856
989
  let serialized = "new Set";
857
- const size = value.length;
990
+ const size = node.a.length;
858
991
  if (size) {
859
992
  let result = "";
860
- ctx.stack.push(id);
993
+ ctx.stack.push(node.i);
861
994
  for (let i = 0; i < size; i++) {
862
- const item = value[i];
995
+ const item = node.a[i];
863
996
  if (isReferenceInStack(ctx, item)) {
864
- createSetAdd(ctx, id, getRefParam(ctx, item[1]));
997
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
865
998
  } else {
866
999
  result += `${serializeTree(ctx, item)},`;
867
1000
  }
@@ -871,32 +1004,32 @@ function serializeSet(ctx, value, id) {
871
1004
  serialized += `([${result.substring(0, result.length - 1)}])`;
872
1005
  }
873
1006
  }
874
- return assignRef(ctx, id, serialized);
1007
+ return assignRef(ctx, node.i, serialized);
875
1008
  }
876
- function serializeMap(ctx, keys, values, size, id) {
1009
+ function serializeMap(ctx, node) {
877
1010
  let serialized = "new Map";
878
- if (size) {
1011
+ if (node.d.s) {
879
1012
  let result = "";
880
- ctx.stack.push(id);
881
- for (let i = 0; i < size; i++) {
882
- const key = keys[i];
883
- const val = values[i];
1013
+ ctx.stack.push(node.i);
1014
+ for (let i = 0; i < node.d.s; i++) {
1015
+ const key = node.d.k[i];
1016
+ const val = node.d.v[i];
884
1017
  if (isReferenceInStack(ctx, key)) {
885
- const keyRef = getRefParam(ctx, key[1]);
1018
+ const keyRef = getRefParam(ctx, key.i);
886
1019
  if (isReferenceInStack(ctx, val)) {
887
- const valueRef = getRefParam(ctx, val[1]);
888
- createMapSet(ctx, id, keyRef, valueRef);
1020
+ const valueRef = getRefParam(ctx, val.i);
1021
+ createMapSet(ctx, node.i, keyRef, valueRef);
889
1022
  } else {
890
1023
  const parent = ctx.stack;
891
1024
  ctx.stack = [];
892
- createMapSet(ctx, id, keyRef, serializeTree(ctx, val));
1025
+ createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
893
1026
  ctx.stack = parent;
894
1027
  }
895
1028
  } else if (isReferenceInStack(ctx, val)) {
896
- const valueRef = getRefParam(ctx, val[1]);
1029
+ const valueRef = getRefParam(ctx, val.i);
897
1030
  const parent = ctx.stack;
898
1031
  ctx.stack = [];
899
- createMapSet(ctx, id, serializeTree(ctx, key), valueRef);
1032
+ createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
900
1033
  ctx.stack = parent;
901
1034
  } else {
902
1035
  result += `[${serializeTree(ctx, key)},${serializeTree(ctx, val)}],`;
@@ -907,16 +1040,16 @@ function serializeMap(ctx, keys, values, size, id) {
907
1040
  serialized += `([${result.substring(0, result.length - 1)}])`;
908
1041
  }
909
1042
  }
910
- return assignRef(ctx, id, serialized);
1043
+ return assignRef(ctx, node.i, serialized);
911
1044
  }
912
- function serializeNodeList(ctx, value, id) {
913
- const size = value.length;
1045
+ function serializeNodeList(ctx, node) {
1046
+ const size = node.a.length;
914
1047
  let values = "";
915
1048
  for (let i = 0; i < size; i++) {
916
- const item = value[i];
1049
+ const item = node.a[i];
917
1050
  if (item) {
918
1051
  if (isReferenceInStack(ctx, item)) {
919
- createArrayAssign(ctx, id, i, getRefParam(ctx, item[1]));
1052
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
920
1053
  values += ",";
921
1054
  } else {
922
1055
  values += serializeTree(ctx, item);
@@ -930,11 +1063,11 @@ function serializeNodeList(ctx, value, id) {
930
1063
  }
931
1064
  return `[${values}]`;
932
1065
  }
933
- function serializeArray(ctx, value, id) {
934
- ctx.stack.push(id);
935
- const result = serializeNodeList(ctx, value, id);
1066
+ function serializeArray(ctx, node) {
1067
+ ctx.stack.push(node.i);
1068
+ const result = serializeNodeList(ctx, node);
936
1069
  ctx.stack.pop();
937
- return assignRef(ctx, id, result);
1070
+ return assignRef(ctx, node.i, result);
938
1071
  }
939
1072
  function serializeWithObjectAssign(ctx, value, id, serialized) {
940
1073
  const fields = serializeObject(ctx, id, value);
@@ -943,44 +1076,44 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
943
1076
  }
944
1077
  return serialized;
945
1078
  }
946
- function serializeAggregateError(ctx, message, options, errors, id) {
947
- ctx.stack.push(id);
948
- let serialized = `new AggregateError(${serializeTree(ctx, errors)},${quote(message)})`;
1079
+ function serializeAggregateError(ctx, node) {
1080
+ ctx.stack.push(node.i);
1081
+ let serialized = `new AggregateError(${serializeTree(ctx, node.n)},${quote(node.m)})`;
949
1082
  ctx.stack.pop();
950
- if (options) {
1083
+ if (node.d) {
951
1084
  if (ctx.features & 64 /* ObjectAssign */) {
952
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1085
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
953
1086
  } else {
954
- markRef(ctx, id);
955
- const assignments = serializeAssignments(ctx, id, options);
1087
+ markRef(ctx, node.i);
1088
+ const assignments = serializeAssignments(ctx, node.i, node.d);
956
1089
  if (assignments) {
957
- const ref = getRefParam(ctx, id);
958
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1090
+ const ref = getRefParam(ctx, node.i);
1091
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
959
1092
  }
960
1093
  }
961
1094
  }
962
- return assignRef(ctx, id, serialized);
1095
+ return assignRef(ctx, node.i, serialized);
963
1096
  }
964
- function serializeError(ctx, constructor, message, options, id) {
965
- let serialized = `new ${constructor}(${quote(message)})`;
966
- if (options) {
1097
+ function serializeError(ctx, node) {
1098
+ let serialized = `new ${node.c}(${quote(node.m)})`;
1099
+ if (node.d) {
967
1100
  if (ctx.features & 64 /* ObjectAssign */) {
968
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1101
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
969
1102
  } else {
970
- markRef(ctx, id);
971
- const assignments = serializeAssignments(ctx, id, options);
1103
+ markRef(ctx, node.i);
1104
+ const assignments = serializeAssignments(ctx, node.i, node.d);
972
1105
  if (assignments) {
973
- const ref = getRefParam(ctx, id);
974
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1106
+ const ref = getRefParam(ctx, node.i);
1107
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
975
1108
  }
976
1109
  }
977
1110
  }
978
- return assignRef(ctx, id, serialized);
1111
+ return assignRef(ctx, node.i, serialized);
979
1112
  }
980
- function serializeIterable(ctx, options, items, id) {
1113
+ function serializeIterable(ctx, node) {
981
1114
  const parent = ctx.stack;
982
1115
  ctx.stack = [];
983
- const values = serializeNodeList(ctx, items, id);
1116
+ const values = serializeNodeList(ctx, node);
984
1117
  ctx.stack = parent;
985
1118
  let serialized;
986
1119
  if (ctx.features & 2 /* ArrayPrototypeValues */) {
@@ -995,67 +1128,67 @@ function serializeIterable(ctx, options, items, id) {
995
1128
  } else {
996
1129
  serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
997
1130
  }
998
- if (options) {
1131
+ if (node.d) {
999
1132
  if (ctx.features & 64 /* ObjectAssign */) {
1000
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1133
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
1001
1134
  } else {
1002
- markRef(ctx, id);
1003
- const assignments = serializeAssignments(ctx, id, options);
1135
+ markRef(ctx, node.i);
1136
+ const assignments = serializeAssignments(ctx, node.i, node.d);
1004
1137
  if (assignments) {
1005
- const ref = getRefParam(ctx, id);
1006
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1138
+ const ref = getRefParam(ctx, node.i);
1139
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
1007
1140
  }
1008
1141
  }
1009
1142
  }
1010
- return assignRef(ctx, id, serialized);
1143
+ return assignRef(ctx, node.i, serialized);
1011
1144
  }
1012
- function serializeNullConstructor(ctx, value, id) {
1145
+ function serializeNullConstructor(ctx, node) {
1013
1146
  let serialized = "Object.create(null)";
1014
1147
  if (ctx.features & 64 /* ObjectAssign */) {
1015
- serialized = serializeWithObjectAssign(ctx, value, id, serialized);
1148
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
1016
1149
  } else {
1017
- markRef(ctx, id);
1018
- const assignments = serializeAssignments(ctx, id, value);
1150
+ markRef(ctx, node.i);
1151
+ const assignments = serializeAssignments(ctx, node.i, node.d);
1019
1152
  if (assignments) {
1020
- const ref = getRefParam(ctx, id);
1021
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1153
+ const ref = getRefParam(ctx, node.i);
1154
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
1022
1155
  }
1023
1156
  }
1024
- return assignRef(ctx, id, serialized);
1157
+ return assignRef(ctx, node.i, serialized);
1025
1158
  }
1026
- function serializeTree(ctx, [type, value, id]) {
1027
- switch (type) {
1159
+ function serializeTree(ctx, node) {
1160
+ switch (node.t) {
1028
1161
  case 0 /* Primitive */:
1029
- return String(value);
1162
+ return String(node.s);
1030
1163
  case 2 /* Reference */:
1031
- return getRefParam(ctx, value);
1164
+ return getRefParam(ctx, node.i);
1032
1165
  case 10 /* Promise */:
1033
- return serializePromise(ctx, value, id);
1166
+ return serializePromise(ctx, node);
1034
1167
  case 1 /* BigInt */:
1035
- return value;
1168
+ return node.s;
1036
1169
  case 3 /* Date */:
1037
- return assignRef(ctx, id, `new Date("${value}")`);
1170
+ return assignRef(ctx, node.i, `new Date("${node.s}")`);
1038
1171
  case 4 /* RegExp */:
1039
- return assignRef(ctx, id, value);
1172
+ return assignRef(ctx, node.i, node.s);
1040
1173
  case 15 /* BigIntTypedArray */:
1041
1174
  case 14 /* TypedArray */:
1042
- return serializeTypedArray(ctx, value[0], value[1], value[2], id);
1175
+ return serializeTypedArray(ctx, node);
1043
1176
  case 5 /* Set */:
1044
- return serializeSet(ctx, value, id);
1177
+ return serializeSet(ctx, node);
1045
1178
  case 6 /* Map */:
1046
- return serializeMap(ctx, value[0], value[1], value[2], id);
1179
+ return serializeMap(ctx, node);
1047
1180
  case 7 /* Array */:
1048
- return serializeArray(ctx, value, id);
1181
+ return serializeArray(ctx, node);
1049
1182
  case 12 /* AggregateError */:
1050
- return serializeAggregateError(ctx, value[0], value[1], value[2], id);
1183
+ return serializeAggregateError(ctx, node);
1051
1184
  case 11 /* Error */:
1052
- return serializeError(ctx, value[0], value[1], value[2], id);
1185
+ return serializeError(ctx, node);
1053
1186
  case 13 /* Iterable */:
1054
- return serializeIterable(ctx, value[0], value[1], id);
1187
+ return serializeIterable(ctx, node);
1055
1188
  case 9 /* NullConstructor */:
1056
- return serializeNullConstructor(ctx, value, id);
1189
+ return serializeNullConstructor(ctx, node);
1057
1190
  case 8 /* Object */:
1058
- return assignRef(ctx, id, serializeObject(ctx, id, value));
1191
+ return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1059
1192
  default:
1060
1193
  throw new Error("Unsupported type");
1061
1194
  }
@@ -1086,7 +1219,11 @@ function serializePropertiesSync(ctx, properties) {
1086
1219
  keyNodes[nodesSize + i] = deferredKeys[i];
1087
1220
  valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
1088
1221
  }
1089
- return [keyNodes, valueNodes, size];
1222
+ return {
1223
+ k: keyNodes,
1224
+ v: valueNodes,
1225
+ s: size
1226
+ };
1090
1227
  }
1091
1228
  function generateSetNode2(ctx, current, id) {
1092
1229
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -1105,7 +1242,17 @@ function generateSetNode2(ctx, current, id) {
1105
1242
  for (let i = 0; i < deferredSize; i++) {
1106
1243
  nodes[nodeSize + i] = generateTreeSync(ctx, deferred[i]);
1107
1244
  }
1108
- return [5 /* Set */, nodes, id];
1245
+ return {
1246
+ t: 5 /* Set */,
1247
+ i: id,
1248
+ a: nodes,
1249
+ s: void 0,
1250
+ l: void 0,
1251
+ m: void 0,
1252
+ c: void 0,
1253
+ d: void 0,
1254
+ n: void 0
1255
+ };
1109
1256
  }
1110
1257
  function generateMapNode2(ctx, current, id) {
1111
1258
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -1131,7 +1278,17 @@ function generateMapNode2(ctx, current, id) {
1131
1278
  keyNodes[nodeSize + i] = generateTreeSync(ctx, deferredKey[i]);
1132
1279
  valueNodes[nodeSize + i] = generateTreeSync(ctx, deferredValue[i]);
1133
1280
  }
1134
- return [6 /* Map */, [keyNodes, valueNodes, len], id];
1281
+ return {
1282
+ t: 6 /* Map */,
1283
+ i: id,
1284
+ a: void 0,
1285
+ s: void 0,
1286
+ l: void 0,
1287
+ m: void 0,
1288
+ c: void 0,
1289
+ d: { k: keyNodes, v: valueNodes, s: len },
1290
+ n: void 0
1291
+ };
1135
1292
  }
1136
1293
  function generateNodeList2(ctx, current) {
1137
1294
  const size = current.length;
@@ -1154,38 +1311,81 @@ function generateNodeList2(ctx, current) {
1154
1311
  return nodes;
1155
1312
  }
1156
1313
  function generateArrayNode2(ctx, current, id) {
1157
- return [7 /* Array */, generateNodeList2(ctx, current), id];
1314
+ return {
1315
+ t: 7 /* Array */,
1316
+ i: id,
1317
+ a: generateNodeList2(ctx, current),
1318
+ s: void 0,
1319
+ l: void 0,
1320
+ m: void 0,
1321
+ c: void 0,
1322
+ d: void 0,
1323
+ n: void 0
1324
+ };
1158
1325
  }
1159
1326
  function generateAggregateErrorNode2(ctx, current, id) {
1160
1327
  const options = getErrorOptions(current);
1161
1328
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1162
- const errorsNode = generateTreeSync(ctx, current.errors);
1163
- return [12 /* AggregateError */, [current.message, optionsNode, errorsNode], id];
1329
+ return {
1330
+ t: 12 /* AggregateError */,
1331
+ i: id,
1332
+ a: void 0,
1333
+ s: void 0,
1334
+ l: void 0,
1335
+ m: current.message,
1336
+ c: void 0,
1337
+ d: optionsNode,
1338
+ n: generateTreeSync(ctx, current.errors)
1339
+ };
1164
1340
  }
1165
1341
  function generateErrorNode2(ctx, current, id) {
1166
1342
  const options = getErrorOptions(current);
1167
1343
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1168
- return [
1169
- 11 /* Error */,
1170
- [getErrorConstructor(current), current.message, optionsNode],
1171
- id
1172
- ];
1344
+ return {
1345
+ t: 11 /* Error */,
1346
+ i: id,
1347
+ a: void 0,
1348
+ s: void 0,
1349
+ l: void 0,
1350
+ m: current.message,
1351
+ c: getErrorConstructor(current),
1352
+ d: optionsNode,
1353
+ n: void 0
1354
+ };
1173
1355
  }
1174
1356
  function generateIterableNode2(ctx, current, id) {
1175
1357
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1176
1358
  const options = getIterableOptions(current);
1177
- return [13 /* Iterable */, [
1359
+ return {
1360
+ t: 13 /* Iterable */,
1361
+ i: id,
1362
+ s: void 0,
1363
+ l: void 0,
1364
+ m: void 0,
1365
+ c: void 0,
1178
1366
  // Parse options first before the items
1179
- options ? serializePropertiesSync(ctx, options) : void 0,
1180
- generateNodeList2(ctx, Array.from(current))
1181
- ], id];
1367
+ d: options ? serializePropertiesSync(ctx, options) : void 0,
1368
+ a: generateNodeList2(ctx, Array.from(current)),
1369
+ n: void 0
1370
+ };
1182
1371
  }
1183
1372
  function generateTreeSync(ctx, current) {
1184
1373
  if (isPrimitive(current)) {
1185
- return [0 /* Primitive */, serializePrimitive(current)];
1374
+ return {
1375
+ t: 0 /* Primitive */,
1376
+ i: void 0,
1377
+ s: serializePrimitive(current),
1378
+ l: void 0,
1379
+ m: void 0,
1380
+ c: void 0,
1381
+ // Parse options first before the items
1382
+ d: void 0,
1383
+ a: void 0,
1384
+ n: void 0
1385
+ };
1186
1386
  }
1187
1387
  const id = generateRef(ctx, current);
1188
- if (Array.isArray(id)) {
1388
+ if (typeof id !== "number") {
1189
1389
  return id;
1190
1390
  }
1191
1391
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -1212,17 +1412,24 @@ function generateTreeSync(ctx, current) {
1212
1412
  }
1213
1413
  const empty = current.constructor == null;
1214
1414
  if (current.constructor === Object || empty) {
1215
- return [
1216
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
1217
- serializePropertiesSync(ctx, current),
1218
- id
1219
- ];
1415
+ return {
1416
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1417
+ i: id,
1418
+ s: void 0,
1419
+ l: void 0,
1420
+ m: void 0,
1421
+ c: void 0,
1422
+ // Parse options first before the items
1423
+ d: serializePropertiesSync(ctx, current),
1424
+ a: void 0,
1425
+ n: void 0
1426
+ };
1220
1427
  }
1221
1428
  throw new Error("Unsupported value");
1222
1429
  }
1223
1430
  function parseSync(ctx, current) {
1224
1431
  const result = generateTreeSync(ctx, current);
1225
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
1432
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
1226
1433
  }
1227
1434
 
1228
1435
  // src/index.ts