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.
@@ -394,14 +394,24 @@ function getIterableOptions(obj) {
394
394
  return void 0;
395
395
  }
396
396
  function isReferenceInStack(ctx, node) {
397
- return node[0] === 2 /* Reference */ && ctx.stack.includes(node[1]);
397
+ return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
398
398
  }
399
399
  function generateRef(ctx, current) {
400
400
  const ref = ctx.refs.has(current);
401
401
  if (ref) {
402
402
  const refID = ctx.refs.get(current) || 0;
403
403
  markRef(ctx, refID);
404
- return [2 /* Reference */, refID];
404
+ return {
405
+ t: 2 /* Reference */,
406
+ i: refID,
407
+ a: void 0,
408
+ s: void 0,
409
+ l: void 0,
410
+ m: void 0,
411
+ c: void 0,
412
+ d: void 0,
413
+ n: void 0
414
+ };
405
415
  }
406
416
  const id = ctx.refs.size;
407
417
  ctx.refs.set(current, id);
@@ -410,18 +420,58 @@ function generateRef(ctx, current) {
410
420
  function generateSemiPrimitiveValue(ctx, current, id) {
411
421
  if (typeof current === "bigint") {
412
422
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
413
- return [1 /* BigInt */, `${current}n`];
423
+ return {
424
+ t: 1 /* BigInt */,
425
+ i: void 0,
426
+ a: void 0,
427
+ s: `${current}n`,
428
+ l: void 0,
429
+ m: void 0,
430
+ c: void 0,
431
+ d: void 0,
432
+ n: void 0
433
+ };
414
434
  }
415
435
  if (constructorCheck(current, Date)) {
416
- return [3 /* Date */, current.toISOString(), id];
436
+ return {
437
+ t: 3 /* Date */,
438
+ i: id,
439
+ a: void 0,
440
+ s: current.toISOString(),
441
+ l: void 0,
442
+ m: void 0,
443
+ c: void 0,
444
+ d: void 0,
445
+ n: void 0
446
+ };
417
447
  }
418
448
  if (constructorCheck(current, RegExp)) {
419
- return [4 /* RegExp */, String(current), id];
449
+ return {
450
+ t: 4 /* RegExp */,
451
+ i: id,
452
+ a: void 0,
453
+ s: String(current),
454
+ l: void 0,
455
+ m: void 0,
456
+ c: void 0,
457
+ d: void 0,
458
+ n: void 0
459
+ };
420
460
  }
421
461
  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)) {
422
462
  const constructor = current.constructor.name;
423
463
  assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
424
- return [14 /* TypedArray */, [constructor, current.toString(), current.byteOffset], id];
464
+ return {
465
+ t: 14 /* TypedArray */,
466
+ i: id,
467
+ a: void 0,
468
+ s: current.toString(),
469
+ l: current.byteOffset,
470
+ m: void 0,
471
+ c: constructor,
472
+ d: void 0,
473
+ n: void 0
474
+ };
425
475
  }
426
476
  if (constructorCheck(current, BigInt64Array) || constructorCheck(current, BigUint64Array)) {
427
477
  const constructor = current.constructor.name;
@@ -435,11 +485,17 @@ function generateSemiPrimitiveValue(ctx, current, id) {
435
485
  result += `${current[i]}n,`;
436
486
  }
437
487
  result += `"${current[cap]}"`;
438
- return [
439
- 15 /* BigIntTypedArray */,
440
- [constructor, result, current.byteOffset],
441
- id
442
- ];
488
+ return {
489
+ t: 14 /* TypedArray */,
490
+ i: id,
491
+ a: void 0,
492
+ s: result,
493
+ l: current.byteOffset,
494
+ m: void 0,
495
+ c: constructor,
496
+ d: void 0,
497
+ n: void 0
498
+ };
443
499
  }
444
500
  return void 0;
445
501
  }
@@ -496,7 +552,11 @@ async function serializePropertiesAsync(ctx, properties) {
496
552
  keyNodes[nodesSize + i] = deferredKeys[i];
497
553
  valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
498
554
  }
499
- return [keyNodes, valueNodes, size];
555
+ return {
556
+ k: keyNodes,
557
+ v: valueNodes,
558
+ s: size
559
+ };
500
560
  }
501
561
  async function generateSetNode(ctx, current, id) {
502
562
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -515,7 +575,17 @@ async function generateSetNode(ctx, current, id) {
515
575
  for (let i = 0; i < deferredSize; i++) {
516
576
  nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
517
577
  }
518
- return [5 /* Set */, nodes, id];
578
+ return {
579
+ t: 5 /* Set */,
580
+ i: id,
581
+ a: nodes,
582
+ s: void 0,
583
+ l: void 0,
584
+ m: void 0,
585
+ c: void 0,
586
+ d: void 0,
587
+ n: void 0
588
+ };
519
589
  }
520
590
  async function generateMapNode(ctx, current, id) {
521
591
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -541,7 +611,17 @@ async function generateMapNode(ctx, current, id) {
541
611
  keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
542
612
  valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
543
613
  }
544
- return [6 /* Map */, [keyNodes, valueNodes, len], id];
614
+ return {
615
+ t: 6 /* Map */,
616
+ i: id,
617
+ a: void 0,
618
+ s: void 0,
619
+ l: void 0,
620
+ m: void 0,
621
+ c: void 0,
622
+ d: { k: keyNodes, v: valueNodes, s: len },
623
+ n: void 0
624
+ };
545
625
  }
546
626
  async function generateNodeList(ctx, current) {
547
627
  const size = current.length;
@@ -564,42 +644,81 @@ async function generateNodeList(ctx, current) {
564
644
  return nodes;
565
645
  }
566
646
  async function generateArrayNode(ctx, current, id) {
567
- return [7 /* Array */, await generateNodeList(ctx, current), id];
647
+ return {
648
+ t: 7 /* Array */,
649
+ i: id,
650
+ a: await generateNodeList(ctx, current),
651
+ s: void 0,
652
+ l: void 0,
653
+ m: void 0,
654
+ c: void 0,
655
+ d: void 0,
656
+ n: void 0
657
+ };
568
658
  }
569
659
  async function generateAggregateErrorNode(ctx, current, id) {
570
660
  const options = getErrorOptions(current);
571
661
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
572
- const errorsNode = await generateTreeAsync(ctx, current.errors);
573
- return [
574
- 12 /* AggregateError */,
575
- [current.message, optionsNode, errorsNode],
576
- id
577
- ];
662
+ return {
663
+ t: 12 /* AggregateError */,
664
+ i: id,
665
+ a: void 0,
666
+ s: void 0,
667
+ l: void 0,
668
+ m: current.message,
669
+ c: void 0,
670
+ d: optionsNode,
671
+ n: await generateTreeAsync(ctx, current.errors)
672
+ };
578
673
  }
579
674
  async function generateErrorNode(ctx, current, id) {
580
675
  const options = getErrorOptions(current);
581
676
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
582
- return [
583
- 11 /* Error */,
584
- [getErrorConstructor(current), current.message, optionsNode],
585
- id
586
- ];
677
+ return {
678
+ t: 11 /* Error */,
679
+ i: id,
680
+ a: void 0,
681
+ s: void 0,
682
+ l: void 0,
683
+ m: current.message,
684
+ c: getErrorConstructor(current),
685
+ d: optionsNode,
686
+ n: void 0
687
+ };
587
688
  }
588
689
  async function generateIterableNode(ctx, current, id) {
589
690
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
590
691
  const options = getIterableOptions(current);
591
- return [13 /* Iterable */, [
692
+ return {
693
+ t: 13 /* Iterable */,
694
+ i: id,
695
+ s: void 0,
696
+ l: void 0,
697
+ m: void 0,
698
+ c: void 0,
592
699
  // Parse options first before the items
593
- options ? await serializePropertiesAsync(ctx, options) : void 0,
594
- await generateNodeList(ctx, Array.from(current))
595
- ], id];
700
+ d: options ? await serializePropertiesAsync(ctx, options) : void 0,
701
+ a: await generateNodeList(ctx, Array.from(current)),
702
+ n: void 0
703
+ };
596
704
  }
597
705
  async function generateTreeAsync(ctx, current) {
598
706
  if (isPrimitive(current)) {
599
- return [0 /* Primitive */, serializePrimitive(current)];
707
+ return {
708
+ t: 0 /* Primitive */,
709
+ i: void 0,
710
+ s: serializePrimitive(current),
711
+ l: void 0,
712
+ m: void 0,
713
+ c: void 0,
714
+ // Parse options first before the items
715
+ d: void 0,
716
+ a: void 0,
717
+ n: void 0
718
+ };
600
719
  }
601
720
  const id = generateRef(ctx, current);
602
- if (Array.isArray(id)) {
721
+ if (typeof id !== "number") {
603
722
  return id;
604
723
  }
605
724
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -608,11 +727,18 @@ async function generateTreeAsync(ctx, current) {
608
727
  }
609
728
  if (isPromise(current)) {
610
729
  assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
611
- return current.then(async (value) => [
612
- 10 /* Promise */,
613
- await generateTreeAsync(ctx, value),
614
- id
615
- ]);
730
+ return current.then(async (value) => ({
731
+ t: 10 /* Promise */,
732
+ i: id,
733
+ s: void 0,
734
+ l: void 0,
735
+ m: void 0,
736
+ c: void 0,
737
+ // Parse options first before the items
738
+ d: void 0,
739
+ a: void 0,
740
+ n: await generateTreeAsync(ctx, value)
741
+ }));
616
742
  }
617
743
  if (constructorCheck(current, Set)) {
618
744
  return generateSetNode(ctx, current, id);
@@ -634,17 +760,24 @@ async function generateTreeAsync(ctx, current) {
634
760
  }
635
761
  const empty = current.constructor == null;
636
762
  if (current.constructor === Object || empty) {
637
- return [
638
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
639
- await serializePropertiesAsync(ctx, current),
640
- id
641
- ];
763
+ return {
764
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
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: await serializePropertiesAsync(ctx, current),
772
+ a: void 0,
773
+ n: void 0
774
+ };
642
775
  }
643
776
  throw new Error("Unsupported value");
644
777
  }
645
778
  async function parseAsync(ctx, current) {
646
779
  const result = await generateTreeAsync(ctx, current);
647
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
780
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
648
781
  }
649
782
 
650
783
  // src/tree/serialize.ts
@@ -752,15 +885,15 @@ function createObjectAssign(ctx, ref, key, value) {
752
885
  createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
753
886
  }
754
887
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
755
- function serializeAssignments(ctx, targetRef, [keys, values, size]) {
888
+ function serializeAssignments(ctx, targetRef, node) {
756
889
  ctx.stack.push(targetRef);
757
890
  const mainAssignments = [];
758
- for (let i = 0; i < size; i++) {
891
+ for (let i = 0; i < node.s; i++) {
759
892
  const parentStack = ctx.stack;
760
893
  ctx.stack = [];
761
- const refParam = serializeTree(ctx, values[i]);
894
+ const refParam = serializeTree(ctx, node.v[i]);
762
895
  ctx.stack = parentStack;
763
- const key = keys[i];
896
+ const key = node.k[i];
764
897
  const check = Number(key);
765
898
  const parentAssignment = ctx.assignments;
766
899
  ctx.assignments = mainAssignments;
@@ -775,19 +908,19 @@ function serializeAssignments(ctx, targetRef, [keys, values, size]) {
775
908
  ctx.stack.pop();
776
909
  return resolveAssignments(mainAssignments);
777
910
  }
778
- function serializeObject(ctx, sourceID, [keys, values, size]) {
779
- if (size === 0) {
911
+ function serializeObject(ctx, sourceID, node) {
912
+ if (node.s === 0) {
780
913
  return "{}";
781
914
  }
782
915
  let result = "";
783
916
  ctx.stack.push(sourceID);
784
- for (let i = 0; i < size; i++) {
785
- const key = keys[i];
786
- const val = values[i];
917
+ for (let i = 0; i < node.s; i++) {
918
+ const key = node.k[i];
919
+ const val = node.v[i];
787
920
  const check = Number(key);
788
921
  const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
789
922
  if (isReferenceInStack(ctx, val)) {
790
- const refParam = getRefParam(ctx, val[1]);
923
+ const refParam = getRefParam(ctx, val.i);
791
924
  if (isIdentifier && Number.isNaN(check)) {
792
925
  createObjectAssign(ctx, sourceID, key, refParam);
793
926
  } else {
@@ -800,35 +933,35 @@ function serializeObject(ctx, sourceID, [keys, values, size]) {
800
933
  ctx.stack.pop();
801
934
  return `{${result.substring(0, result.length - 1)}}`;
802
935
  }
803
- function serializePromise(ctx, value, id) {
936
+ function serializePromise(ctx, node) {
804
937
  let serialized;
805
- if (isReferenceInStack(ctx, value)) {
806
- serialized = `Promise.resolve().then(()=>${getRefParam(ctx, value[1])})`;
938
+ if (isReferenceInStack(ctx, node.n)) {
939
+ serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
807
940
  } else {
808
- ctx.stack.push(id);
809
- const result = serializeTree(ctx, value);
941
+ ctx.stack.push(node.i);
942
+ const result = serializeTree(ctx, node.n);
810
943
  ctx.stack.pop();
811
944
  serialized = `Promise.resolve(${result})`;
812
945
  }
813
- return assignRef(ctx, id, serialized);
946
+ return assignRef(ctx, node.i, serialized);
814
947
  }
815
- function serializeTypedArray(ctx, constructor, init, byteOffset, id) {
816
- let args = `[${init}]`;
817
- if (byteOffset !== 0) {
818
- args += `,${byteOffset}`;
948
+ function serializeTypedArray(ctx, node) {
949
+ let args = `[${node.s}]`;
950
+ if (node.l !== 0) {
951
+ args += `,${node.l}`;
819
952
  }
820
- return assignRef(ctx, id, `new ${constructor}(${args})`);
953
+ return assignRef(ctx, node.i, `new ${node.c}(${args})`);
821
954
  }
822
- function serializeSet(ctx, value, id) {
955
+ function serializeSet(ctx, node) {
823
956
  let serialized = "new Set";
824
- const size = value.length;
957
+ const size = node.a.length;
825
958
  if (size) {
826
959
  let result = "";
827
- ctx.stack.push(id);
960
+ ctx.stack.push(node.i);
828
961
  for (let i = 0; i < size; i++) {
829
- const item = value[i];
962
+ const item = node.a[i];
830
963
  if (isReferenceInStack(ctx, item)) {
831
- createSetAdd(ctx, id, getRefParam(ctx, item[1]));
964
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
832
965
  } else {
833
966
  result += `${serializeTree(ctx, item)},`;
834
967
  }
@@ -838,32 +971,32 @@ function serializeSet(ctx, value, id) {
838
971
  serialized += `([${result.substring(0, result.length - 1)}])`;
839
972
  }
840
973
  }
841
- return assignRef(ctx, id, serialized);
974
+ return assignRef(ctx, node.i, serialized);
842
975
  }
843
- function serializeMap(ctx, keys, values, size, id) {
976
+ function serializeMap(ctx, node) {
844
977
  let serialized = "new Map";
845
- if (size) {
978
+ if (node.d.s) {
846
979
  let result = "";
847
- ctx.stack.push(id);
848
- for (let i = 0; i < size; i++) {
849
- const key = keys[i];
850
- const val = values[i];
980
+ ctx.stack.push(node.i);
981
+ for (let i = 0; i < node.d.s; i++) {
982
+ const key = node.d.k[i];
983
+ const val = node.d.v[i];
851
984
  if (isReferenceInStack(ctx, key)) {
852
- const keyRef = getRefParam(ctx, key[1]);
985
+ const keyRef = getRefParam(ctx, key.i);
853
986
  if (isReferenceInStack(ctx, val)) {
854
- const valueRef = getRefParam(ctx, val[1]);
855
- createMapSet(ctx, id, keyRef, valueRef);
987
+ const valueRef = getRefParam(ctx, val.i);
988
+ createMapSet(ctx, node.i, keyRef, valueRef);
856
989
  } else {
857
990
  const parent = ctx.stack;
858
991
  ctx.stack = [];
859
- createMapSet(ctx, id, keyRef, serializeTree(ctx, val));
992
+ createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
860
993
  ctx.stack = parent;
861
994
  }
862
995
  } else if (isReferenceInStack(ctx, val)) {
863
- const valueRef = getRefParam(ctx, val[1]);
996
+ const valueRef = getRefParam(ctx, val.i);
864
997
  const parent = ctx.stack;
865
998
  ctx.stack = [];
866
- createMapSet(ctx, id, serializeTree(ctx, key), valueRef);
999
+ createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
867
1000
  ctx.stack = parent;
868
1001
  } else {
869
1002
  result += `[${serializeTree(ctx, key)},${serializeTree(ctx, val)}],`;
@@ -874,16 +1007,16 @@ function serializeMap(ctx, keys, values, size, id) {
874
1007
  serialized += `([${result.substring(0, result.length - 1)}])`;
875
1008
  }
876
1009
  }
877
- return assignRef(ctx, id, serialized);
1010
+ return assignRef(ctx, node.i, serialized);
878
1011
  }
879
- function serializeNodeList(ctx, value, id) {
880
- const size = value.length;
1012
+ function serializeNodeList(ctx, node) {
1013
+ const size = node.a.length;
881
1014
  let values = "";
882
1015
  for (let i = 0; i < size; i++) {
883
- const item = value[i];
1016
+ const item = node.a[i];
884
1017
  if (item) {
885
1018
  if (isReferenceInStack(ctx, item)) {
886
- createArrayAssign(ctx, id, i, getRefParam(ctx, item[1]));
1019
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
887
1020
  values += ",";
888
1021
  } else {
889
1022
  values += serializeTree(ctx, item);
@@ -897,11 +1030,11 @@ function serializeNodeList(ctx, value, id) {
897
1030
  }
898
1031
  return `[${values}]`;
899
1032
  }
900
- function serializeArray(ctx, value, id) {
901
- ctx.stack.push(id);
902
- const result = serializeNodeList(ctx, value, id);
1033
+ function serializeArray(ctx, node) {
1034
+ ctx.stack.push(node.i);
1035
+ const result = serializeNodeList(ctx, node);
903
1036
  ctx.stack.pop();
904
- return assignRef(ctx, id, result);
1037
+ return assignRef(ctx, node.i, result);
905
1038
  }
906
1039
  function serializeWithObjectAssign(ctx, value, id, serialized) {
907
1040
  const fields = serializeObject(ctx, id, value);
@@ -910,44 +1043,44 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
910
1043
  }
911
1044
  return serialized;
912
1045
  }
913
- function serializeAggregateError(ctx, message, options, errors, id) {
914
- ctx.stack.push(id);
915
- let serialized = `new AggregateError(${serializeTree(ctx, errors)},${quote(message)})`;
1046
+ function serializeAggregateError(ctx, node) {
1047
+ ctx.stack.push(node.i);
1048
+ let serialized = `new AggregateError(${serializeTree(ctx, node.n)},${quote(node.m)})`;
916
1049
  ctx.stack.pop();
917
- if (options) {
1050
+ if (node.d) {
918
1051
  if (ctx.features & 64 /* ObjectAssign */) {
919
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1052
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
920
1053
  } else {
921
- markRef(ctx, id);
922
- const assignments = serializeAssignments(ctx, id, options);
1054
+ markRef(ctx, node.i);
1055
+ const assignments = serializeAssignments(ctx, node.i, node.d);
923
1056
  if (assignments) {
924
- const ref = getRefParam(ctx, id);
925
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1057
+ const ref = getRefParam(ctx, node.i);
1058
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
926
1059
  }
927
1060
  }
928
1061
  }
929
- return assignRef(ctx, id, serialized);
1062
+ return assignRef(ctx, node.i, serialized);
930
1063
  }
931
- function serializeError(ctx, constructor, message, options, id) {
932
- let serialized = `new ${constructor}(${quote(message)})`;
933
- if (options) {
1064
+ function serializeError(ctx, node) {
1065
+ let serialized = `new ${node.c}(${quote(node.m)})`;
1066
+ if (node.d) {
934
1067
  if (ctx.features & 64 /* ObjectAssign */) {
935
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1068
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
936
1069
  } else {
937
- markRef(ctx, id);
938
- const assignments = serializeAssignments(ctx, id, options);
1070
+ markRef(ctx, node.i);
1071
+ const assignments = serializeAssignments(ctx, node.i, node.d);
939
1072
  if (assignments) {
940
- const ref = getRefParam(ctx, id);
941
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1073
+ const ref = getRefParam(ctx, node.i);
1074
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
942
1075
  }
943
1076
  }
944
1077
  }
945
- return assignRef(ctx, id, serialized);
1078
+ return assignRef(ctx, node.i, serialized);
946
1079
  }
947
- function serializeIterable(ctx, options, items, id) {
1080
+ function serializeIterable(ctx, node) {
948
1081
  const parent = ctx.stack;
949
1082
  ctx.stack = [];
950
- const values = serializeNodeList(ctx, items, id);
1083
+ const values = serializeNodeList(ctx, node);
951
1084
  ctx.stack = parent;
952
1085
  let serialized;
953
1086
  if (ctx.features & 2 /* ArrayPrototypeValues */) {
@@ -962,67 +1095,67 @@ function serializeIterable(ctx, options, items, id) {
962
1095
  } else {
963
1096
  serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
964
1097
  }
965
- if (options) {
1098
+ if (node.d) {
966
1099
  if (ctx.features & 64 /* ObjectAssign */) {
967
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1100
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
968
1101
  } else {
969
- markRef(ctx, id);
970
- const assignments = serializeAssignments(ctx, id, options);
1102
+ markRef(ctx, node.i);
1103
+ const assignments = serializeAssignments(ctx, node.i, node.d);
971
1104
  if (assignments) {
972
- const ref = getRefParam(ctx, id);
973
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1105
+ const ref = getRefParam(ctx, node.i);
1106
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
974
1107
  }
975
1108
  }
976
1109
  }
977
- return assignRef(ctx, id, serialized);
1110
+ return assignRef(ctx, node.i, serialized);
978
1111
  }
979
- function serializeNullConstructor(ctx, value, id) {
1112
+ function serializeNullConstructor(ctx, node) {
980
1113
  let serialized = "Object.create(null)";
981
1114
  if (ctx.features & 64 /* ObjectAssign */) {
982
- serialized = serializeWithObjectAssign(ctx, value, id, serialized);
1115
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
983
1116
  } else {
984
- markRef(ctx, id);
985
- const assignments = serializeAssignments(ctx, id, value);
1117
+ markRef(ctx, node.i);
1118
+ const assignments = serializeAssignments(ctx, node.i, node.d);
986
1119
  if (assignments) {
987
- const ref = getRefParam(ctx, id);
988
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1120
+ const ref = getRefParam(ctx, node.i);
1121
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
989
1122
  }
990
1123
  }
991
- return assignRef(ctx, id, serialized);
1124
+ return assignRef(ctx, node.i, serialized);
992
1125
  }
993
- function serializeTree(ctx, [type, value, id]) {
994
- switch (type) {
1126
+ function serializeTree(ctx, node) {
1127
+ switch (node.t) {
995
1128
  case 0 /* Primitive */:
996
- return String(value);
1129
+ return String(node.s);
997
1130
  case 2 /* Reference */:
998
- return getRefParam(ctx, value);
1131
+ return getRefParam(ctx, node.i);
999
1132
  case 10 /* Promise */:
1000
- return serializePromise(ctx, value, id);
1133
+ return serializePromise(ctx, node);
1001
1134
  case 1 /* BigInt */:
1002
- return value;
1135
+ return node.s;
1003
1136
  case 3 /* Date */:
1004
- return assignRef(ctx, id, `new Date("${value}")`);
1137
+ return assignRef(ctx, node.i, `new Date("${node.s}")`);
1005
1138
  case 4 /* RegExp */:
1006
- return assignRef(ctx, id, value);
1139
+ return assignRef(ctx, node.i, node.s);
1007
1140
  case 15 /* BigIntTypedArray */:
1008
1141
  case 14 /* TypedArray */:
1009
- return serializeTypedArray(ctx, value[0], value[1], value[2], id);
1142
+ return serializeTypedArray(ctx, node);
1010
1143
  case 5 /* Set */:
1011
- return serializeSet(ctx, value, id);
1144
+ return serializeSet(ctx, node);
1012
1145
  case 6 /* Map */:
1013
- return serializeMap(ctx, value[0], value[1], value[2], id);
1146
+ return serializeMap(ctx, node);
1014
1147
  case 7 /* Array */:
1015
- return serializeArray(ctx, value, id);
1148
+ return serializeArray(ctx, node);
1016
1149
  case 12 /* AggregateError */:
1017
- return serializeAggregateError(ctx, value[0], value[1], value[2], id);
1150
+ return serializeAggregateError(ctx, node);
1018
1151
  case 11 /* Error */:
1019
- return serializeError(ctx, value[0], value[1], value[2], id);
1152
+ return serializeError(ctx, node);
1020
1153
  case 13 /* Iterable */:
1021
- return serializeIterable(ctx, value[0], value[1], id);
1154
+ return serializeIterable(ctx, node);
1022
1155
  case 9 /* NullConstructor */:
1023
- return serializeNullConstructor(ctx, value, id);
1156
+ return serializeNullConstructor(ctx, node);
1024
1157
  case 8 /* Object */:
1025
- return assignRef(ctx, id, serializeObject(ctx, id, value));
1158
+ return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1026
1159
  default:
1027
1160
  throw new Error("Unsupported type");
1028
1161
  }
@@ -1053,7 +1186,11 @@ function serializePropertiesSync(ctx, properties) {
1053
1186
  keyNodes[nodesSize + i] = deferredKeys[i];
1054
1187
  valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
1055
1188
  }
1056
- return [keyNodes, valueNodes, size];
1189
+ return {
1190
+ k: keyNodes,
1191
+ v: valueNodes,
1192
+ s: size
1193
+ };
1057
1194
  }
1058
1195
  function generateSetNode2(ctx, current, id) {
1059
1196
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -1072,7 +1209,17 @@ function generateSetNode2(ctx, current, id) {
1072
1209
  for (let i = 0; i < deferredSize; i++) {
1073
1210
  nodes[nodeSize + i] = generateTreeSync(ctx, deferred[i]);
1074
1211
  }
1075
- return [5 /* Set */, nodes, id];
1212
+ return {
1213
+ t: 5 /* Set */,
1214
+ i: id,
1215
+ a: nodes,
1216
+ s: void 0,
1217
+ l: void 0,
1218
+ m: void 0,
1219
+ c: void 0,
1220
+ d: void 0,
1221
+ n: void 0
1222
+ };
1076
1223
  }
1077
1224
  function generateMapNode2(ctx, current, id) {
1078
1225
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -1098,7 +1245,17 @@ function generateMapNode2(ctx, current, id) {
1098
1245
  keyNodes[nodeSize + i] = generateTreeSync(ctx, deferredKey[i]);
1099
1246
  valueNodes[nodeSize + i] = generateTreeSync(ctx, deferredValue[i]);
1100
1247
  }
1101
- return [6 /* Map */, [keyNodes, valueNodes, len], id];
1248
+ return {
1249
+ t: 6 /* Map */,
1250
+ i: id,
1251
+ a: void 0,
1252
+ s: void 0,
1253
+ l: void 0,
1254
+ m: void 0,
1255
+ c: void 0,
1256
+ d: { k: keyNodes, v: valueNodes, s: len },
1257
+ n: void 0
1258
+ };
1102
1259
  }
1103
1260
  function generateNodeList2(ctx, current) {
1104
1261
  const size = current.length;
@@ -1121,38 +1278,81 @@ function generateNodeList2(ctx, current) {
1121
1278
  return nodes;
1122
1279
  }
1123
1280
  function generateArrayNode2(ctx, current, id) {
1124
- return [7 /* Array */, generateNodeList2(ctx, current), id];
1281
+ return {
1282
+ t: 7 /* Array */,
1283
+ i: id,
1284
+ a: generateNodeList2(ctx, current),
1285
+ s: void 0,
1286
+ l: void 0,
1287
+ m: void 0,
1288
+ c: void 0,
1289
+ d: void 0,
1290
+ n: void 0
1291
+ };
1125
1292
  }
1126
1293
  function generateAggregateErrorNode2(ctx, current, id) {
1127
1294
  const options = getErrorOptions(current);
1128
1295
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1129
- const errorsNode = generateTreeSync(ctx, current.errors);
1130
- return [12 /* AggregateError */, [current.message, optionsNode, errorsNode], id];
1296
+ return {
1297
+ t: 12 /* AggregateError */,
1298
+ i: id,
1299
+ a: void 0,
1300
+ s: void 0,
1301
+ l: void 0,
1302
+ m: current.message,
1303
+ c: void 0,
1304
+ d: optionsNode,
1305
+ n: generateTreeSync(ctx, current.errors)
1306
+ };
1131
1307
  }
1132
1308
  function generateErrorNode2(ctx, current, id) {
1133
1309
  const options = getErrorOptions(current);
1134
1310
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1135
- return [
1136
- 11 /* Error */,
1137
- [getErrorConstructor(current), current.message, optionsNode],
1138
- id
1139
- ];
1311
+ return {
1312
+ t: 11 /* Error */,
1313
+ i: id,
1314
+ a: void 0,
1315
+ s: void 0,
1316
+ l: void 0,
1317
+ m: current.message,
1318
+ c: getErrorConstructor(current),
1319
+ d: optionsNode,
1320
+ n: void 0
1321
+ };
1140
1322
  }
1141
1323
  function generateIterableNode2(ctx, current, id) {
1142
1324
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1143
1325
  const options = getIterableOptions(current);
1144
- return [13 /* Iterable */, [
1326
+ return {
1327
+ t: 13 /* Iterable */,
1328
+ i: id,
1329
+ s: void 0,
1330
+ l: void 0,
1331
+ m: void 0,
1332
+ c: void 0,
1145
1333
  // Parse options first before the items
1146
- options ? serializePropertiesSync(ctx, options) : void 0,
1147
- generateNodeList2(ctx, Array.from(current))
1148
- ], id];
1334
+ d: options ? serializePropertiesSync(ctx, options) : void 0,
1335
+ a: generateNodeList2(ctx, Array.from(current)),
1336
+ n: void 0
1337
+ };
1149
1338
  }
1150
1339
  function generateTreeSync(ctx, current) {
1151
1340
  if (isPrimitive(current)) {
1152
- return [0 /* Primitive */, serializePrimitive(current)];
1341
+ return {
1342
+ t: 0 /* Primitive */,
1343
+ i: void 0,
1344
+ s: serializePrimitive(current),
1345
+ l: void 0,
1346
+ m: void 0,
1347
+ c: void 0,
1348
+ // Parse options first before the items
1349
+ d: void 0,
1350
+ a: void 0,
1351
+ n: void 0
1352
+ };
1153
1353
  }
1154
1354
  const id = generateRef(ctx, current);
1155
- if (Array.isArray(id)) {
1355
+ if (typeof id !== "number") {
1156
1356
  return id;
1157
1357
  }
1158
1358
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -1179,17 +1379,24 @@ function generateTreeSync(ctx, current) {
1179
1379
  }
1180
1380
  const empty = current.constructor == null;
1181
1381
  if (current.constructor === Object || empty) {
1182
- return [
1183
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
1184
- serializePropertiesSync(ctx, current),
1185
- id
1186
- ];
1382
+ return {
1383
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1384
+ i: id,
1385
+ s: void 0,
1386
+ l: void 0,
1387
+ m: void 0,
1388
+ c: void 0,
1389
+ // Parse options first before the items
1390
+ d: serializePropertiesSync(ctx, current),
1391
+ a: void 0,
1392
+ n: void 0
1393
+ };
1187
1394
  }
1188
1395
  throw new Error("Unsupported value");
1189
1396
  }
1190
1397
  function parseSync(ctx, current) {
1191
1398
  const result = generateTreeSync(ctx, current);
1192
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
1399
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
1193
1400
  }
1194
1401
 
1195
1402
  // src/index.ts