seroval 0.4.0-alpha.7 → 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.
@@ -287,7 +287,7 @@ var DEFAULT_OPTIONS = {
287
287
  function createParserContext(options = {}) {
288
288
  const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
289
289
  return {
290
- markedRefs: /* @__PURE__ */ new Set(),
290
+ markedRefs: {},
291
291
  refs: /* @__PURE__ */ new Map(),
292
292
  features: parseTargets(result.target)
293
293
  };
@@ -297,22 +297,23 @@ function createSerializationContext(options) {
297
297
  stack: [],
298
298
  vars: [],
299
299
  assignments: [],
300
- validRefs: /* @__PURE__ */ new Map(),
300
+ validRefs: [],
301
+ refSize: 0,
301
302
  features: options.features,
302
- markedRefs: new Set(options.markedRefs)
303
+ markedRefs: options.markedRefs
303
304
  };
304
305
  }
305
306
  function markRef(ctx, current) {
306
- ctx.markedRefs.add(current);
307
+ ctx.markedRefs[current] = 1;
307
308
  }
308
309
  function createValidRef(ctx, index) {
309
- const current = ctx.validRefs.get(index);
310
- if (current != null) {
311
- return current;
310
+ const current = ctx.validRefs[index];
311
+ if (current == null) {
312
+ const value = ctx.refSize++;
313
+ ctx.validRefs[index] = value;
314
+ return value;
312
315
  }
313
- const id = ctx.validRefs.size;
314
- ctx.validRefs.set(index, id);
315
- return id;
316
+ return current;
316
317
  }
317
318
  function getRefParam(ctx, index) {
318
319
  const actualIndex = createValidRef(ctx, index);
@@ -426,14 +427,24 @@ function getIterableOptions(obj) {
426
427
  return void 0;
427
428
  }
428
429
  function isReferenceInStack(ctx, node) {
429
- return node[0] === 2 /* Reference */ && ctx.stack.includes(node[1]);
430
+ return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
430
431
  }
431
432
  function generateRef(ctx, current) {
432
433
  const ref = ctx.refs.has(current);
433
434
  if (ref) {
434
435
  const refID = ctx.refs.get(current) || 0;
435
436
  markRef(ctx, refID);
436
- 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
+ };
437
448
  }
438
449
  const id = ctx.refs.size;
439
450
  ctx.refs.set(current, id);
@@ -442,18 +453,58 @@ function generateRef(ctx, current) {
442
453
  function generateSemiPrimitiveValue(ctx, current, id) {
443
454
  if (typeof current === "bigint") {
444
455
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
445
- 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
+ };
446
467
  }
447
468
  if (constructorCheck(current, Date)) {
448
- 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
+ };
449
480
  }
450
481
  if (constructorCheck(current, RegExp)) {
451
- 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
+ };
452
493
  }
453
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)) {
454
495
  const constructor = current.constructor.name;
455
496
  assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
456
- 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
+ };
457
508
  }
458
509
  if (constructorCheck(current, BigInt64Array) || constructorCheck(current, BigUint64Array)) {
459
510
  const constructor = current.constructor.name;
@@ -467,11 +518,17 @@ function generateSemiPrimitiveValue(ctx, current, id) {
467
518
  result += `${current[i]}n,`;
468
519
  }
469
520
  result += `"${current[cap]}"`;
470
- return [
471
- 15 /* BigIntTypedArray */,
472
- [constructor, result, current.byteOffset],
473
- id
474
- ];
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
+ };
475
532
  }
476
533
  return void 0;
477
534
  }
@@ -528,7 +585,11 @@ async function serializePropertiesAsync(ctx, properties) {
528
585
  keyNodes[nodesSize + i] = deferredKeys[i];
529
586
  valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
530
587
  }
531
- return [keyNodes, valueNodes, size];
588
+ return {
589
+ k: keyNodes,
590
+ v: valueNodes,
591
+ s: size
592
+ };
532
593
  }
533
594
  async function generateSetNode(ctx, current, id) {
534
595
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -547,7 +608,17 @@ async function generateSetNode(ctx, current, id) {
547
608
  for (let i = 0; i < deferredSize; i++) {
548
609
  nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
549
610
  }
550
- 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
+ };
551
622
  }
552
623
  async function generateMapNode(ctx, current, id) {
553
624
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -573,7 +644,17 @@ async function generateMapNode(ctx, current, id) {
573
644
  keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
574
645
  valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
575
646
  }
576
- 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
+ };
577
658
  }
578
659
  async function generateNodeList(ctx, current) {
579
660
  const size = current.length;
@@ -596,42 +677,81 @@ async function generateNodeList(ctx, current) {
596
677
  return nodes;
597
678
  }
598
679
  async function generateArrayNode(ctx, current, id) {
599
- 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
+ };
600
691
  }
601
692
  async function generateAggregateErrorNode(ctx, current, id) {
602
693
  const options = getErrorOptions(current);
603
694
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
604
- const errorsNode = await generateTreeAsync(ctx, current.errors);
605
- return [
606
- 12 /* AggregateError */,
607
- [current.message, optionsNode, errorsNode],
608
- id
609
- ];
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
+ };
610
706
  }
611
707
  async function generateErrorNode(ctx, current, id) {
612
708
  const options = getErrorOptions(current);
613
709
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
614
- return [
615
- 11 /* Error */,
616
- [getErrorConstructor(current), current.message, optionsNode],
617
- id
618
- ];
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
+ };
619
721
  }
620
722
  async function generateIterableNode(ctx, current, id) {
621
723
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
622
724
  const options = getIterableOptions(current);
623
- 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,
624
732
  // Parse options first before the items
625
- options ? await serializePropertiesAsync(ctx, options) : void 0,
626
- await generateNodeList(ctx, Array.from(current))
627
- ], id];
733
+ d: options ? await serializePropertiesAsync(ctx, options) : void 0,
734
+ a: await generateNodeList(ctx, Array.from(current)),
735
+ n: void 0
736
+ };
628
737
  }
629
738
  async function generateTreeAsync(ctx, current) {
630
739
  if (isPrimitive(current)) {
631
- 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
+ };
632
752
  }
633
753
  const id = generateRef(ctx, current);
634
- if (Array.isArray(id)) {
754
+ if (typeof id !== "number") {
635
755
  return id;
636
756
  }
637
757
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -640,11 +760,18 @@ async function generateTreeAsync(ctx, current) {
640
760
  }
641
761
  if (isPromise(current)) {
642
762
  assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
643
- return current.then(async (value) => [
644
- 10 /* Promise */,
645
- await generateTreeAsync(ctx, value),
646
- id
647
- ]);
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
+ }));
648
775
  }
649
776
  if (constructorCheck(current, Set)) {
650
777
  return generateSetNode(ctx, current, id);
@@ -666,17 +793,24 @@ async function generateTreeAsync(ctx, current) {
666
793
  }
667
794
  const empty = current.constructor == null;
668
795
  if (current.constructor === Object || empty) {
669
- return [
670
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
671
- await serializePropertiesAsync(ctx, current),
672
- id
673
- ];
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
+ };
674
808
  }
675
809
  throw new Error("Unsupported value");
676
810
  }
677
811
  async function parseAsync(ctx, current) {
678
812
  const result = await generateTreeAsync(ctx, current);
679
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
813
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
680
814
  }
681
815
 
682
816
  // src/tree/serialize.ts
@@ -746,7 +880,7 @@ function resolvePatches(ctx) {
746
880
  return resolveAssignments(ctx.assignments);
747
881
  }
748
882
  function assignRef(ctx, index, value) {
749
- if (ctx.markedRefs.has(index)) {
883
+ if (ctx.markedRefs[index]) {
750
884
  return `${getRefParam(ctx, index)}=${value}`;
751
885
  }
752
886
  return value;
@@ -784,15 +918,15 @@ function createObjectAssign(ctx, ref, key, value) {
784
918
  createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
785
919
  }
786
920
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
787
- function serializeAssignments(ctx, targetRef, [keys, values, size]) {
921
+ function serializeAssignments(ctx, targetRef, node) {
788
922
  ctx.stack.push(targetRef);
789
923
  const mainAssignments = [];
790
- for (let i = 0; i < size; i++) {
924
+ for (let i = 0; i < node.s; i++) {
791
925
  const parentStack = ctx.stack;
792
926
  ctx.stack = [];
793
- const refParam = serializeTree(ctx, values[i]);
927
+ const refParam = serializeTree(ctx, node.v[i]);
794
928
  ctx.stack = parentStack;
795
- const key = keys[i];
929
+ const key = node.k[i];
796
930
  const check = Number(key);
797
931
  const parentAssignment = ctx.assignments;
798
932
  ctx.assignments = mainAssignments;
@@ -807,19 +941,19 @@ function serializeAssignments(ctx, targetRef, [keys, values, size]) {
807
941
  ctx.stack.pop();
808
942
  return resolveAssignments(mainAssignments);
809
943
  }
810
- function serializeObject(ctx, sourceID, [keys, values, size]) {
811
- if (size === 0) {
944
+ function serializeObject(ctx, sourceID, node) {
945
+ if (node.s === 0) {
812
946
  return "{}";
813
947
  }
814
948
  let result = "";
815
949
  ctx.stack.push(sourceID);
816
- for (let i = 0; i < size; i++) {
817
- const key = keys[i];
818
- 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];
819
953
  const check = Number(key);
820
954
  const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
821
955
  if (isReferenceInStack(ctx, val)) {
822
- const refParam = getRefParam(ctx, val[1]);
956
+ const refParam = getRefParam(ctx, val.i);
823
957
  if (isIdentifier && Number.isNaN(check)) {
824
958
  createObjectAssign(ctx, sourceID, key, refParam);
825
959
  } else {
@@ -832,35 +966,35 @@ function serializeObject(ctx, sourceID, [keys, values, size]) {
832
966
  ctx.stack.pop();
833
967
  return `{${result.substring(0, result.length - 1)}}`;
834
968
  }
835
- function serializePromise(ctx, value, id) {
969
+ function serializePromise(ctx, node) {
836
970
  let serialized;
837
- if (isReferenceInStack(ctx, value)) {
838
- serialized = `Promise.resolve().then(()=>${getRefParam(ctx, value[1])})`;
971
+ if (isReferenceInStack(ctx, node.n)) {
972
+ serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
839
973
  } else {
840
- ctx.stack.push(id);
841
- const result = serializeTree(ctx, value);
974
+ ctx.stack.push(node.i);
975
+ const result = serializeTree(ctx, node.n);
842
976
  ctx.stack.pop();
843
977
  serialized = `Promise.resolve(${result})`;
844
978
  }
845
- return assignRef(ctx, id, serialized);
979
+ return assignRef(ctx, node.i, serialized);
846
980
  }
847
- function serializeTypedArray(ctx, constructor, init, byteOffset, id) {
848
- let args = `[${init}]`;
849
- if (byteOffset !== 0) {
850
- args += `,${byteOffset}`;
981
+ function serializeTypedArray(ctx, node) {
982
+ let args = `[${node.s}]`;
983
+ if (node.l !== 0) {
984
+ args += `,${node.l}`;
851
985
  }
852
- return assignRef(ctx, id, `new ${constructor}(${args})`);
986
+ return assignRef(ctx, node.i, `new ${node.c}(${args})`);
853
987
  }
854
- function serializeSet(ctx, value, id) {
988
+ function serializeSet(ctx, node) {
855
989
  let serialized = "new Set";
856
- const size = value.length;
990
+ const size = node.a.length;
857
991
  if (size) {
858
992
  let result = "";
859
- ctx.stack.push(id);
993
+ ctx.stack.push(node.i);
860
994
  for (let i = 0; i < size; i++) {
861
- const item = value[i];
995
+ const item = node.a[i];
862
996
  if (isReferenceInStack(ctx, item)) {
863
- createSetAdd(ctx, id, getRefParam(ctx, item[1]));
997
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
864
998
  } else {
865
999
  result += `${serializeTree(ctx, item)},`;
866
1000
  }
@@ -870,32 +1004,32 @@ function serializeSet(ctx, value, id) {
870
1004
  serialized += `([${result.substring(0, result.length - 1)}])`;
871
1005
  }
872
1006
  }
873
- return assignRef(ctx, id, serialized);
1007
+ return assignRef(ctx, node.i, serialized);
874
1008
  }
875
- function serializeMap(ctx, keys, values, size, id) {
1009
+ function serializeMap(ctx, node) {
876
1010
  let serialized = "new Map";
877
- if (size) {
1011
+ if (node.d.s) {
878
1012
  let result = "";
879
- ctx.stack.push(id);
880
- for (let i = 0; i < size; i++) {
881
- const key = keys[i];
882
- 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];
883
1017
  if (isReferenceInStack(ctx, key)) {
884
- const keyRef = getRefParam(ctx, key[1]);
1018
+ const keyRef = getRefParam(ctx, key.i);
885
1019
  if (isReferenceInStack(ctx, val)) {
886
- const valueRef = getRefParam(ctx, val[1]);
887
- createMapSet(ctx, id, keyRef, valueRef);
1020
+ const valueRef = getRefParam(ctx, val.i);
1021
+ createMapSet(ctx, node.i, keyRef, valueRef);
888
1022
  } else {
889
1023
  const parent = ctx.stack;
890
1024
  ctx.stack = [];
891
- createMapSet(ctx, id, keyRef, serializeTree(ctx, val));
1025
+ createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
892
1026
  ctx.stack = parent;
893
1027
  }
894
1028
  } else if (isReferenceInStack(ctx, val)) {
895
- const valueRef = getRefParam(ctx, val[1]);
1029
+ const valueRef = getRefParam(ctx, val.i);
896
1030
  const parent = ctx.stack;
897
1031
  ctx.stack = [];
898
- createMapSet(ctx, id, serializeTree(ctx, key), valueRef);
1032
+ createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
899
1033
  ctx.stack = parent;
900
1034
  } else {
901
1035
  result += `[${serializeTree(ctx, key)},${serializeTree(ctx, val)}],`;
@@ -906,16 +1040,16 @@ function serializeMap(ctx, keys, values, size, id) {
906
1040
  serialized += `([${result.substring(0, result.length - 1)}])`;
907
1041
  }
908
1042
  }
909
- return assignRef(ctx, id, serialized);
1043
+ return assignRef(ctx, node.i, serialized);
910
1044
  }
911
- function serializeNodeList(ctx, value, id) {
912
- const size = value.length;
1045
+ function serializeNodeList(ctx, node) {
1046
+ const size = node.a.length;
913
1047
  let values = "";
914
1048
  for (let i = 0; i < size; i++) {
915
- const item = value[i];
1049
+ const item = node.a[i];
916
1050
  if (item) {
917
1051
  if (isReferenceInStack(ctx, item)) {
918
- createArrayAssign(ctx, id, i, getRefParam(ctx, item[1]));
1052
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
919
1053
  values += ",";
920
1054
  } else {
921
1055
  values += serializeTree(ctx, item);
@@ -929,11 +1063,11 @@ function serializeNodeList(ctx, value, id) {
929
1063
  }
930
1064
  return `[${values}]`;
931
1065
  }
932
- function serializeArray(ctx, value, id) {
933
- ctx.stack.push(id);
934
- const result = serializeNodeList(ctx, value, id);
1066
+ function serializeArray(ctx, node) {
1067
+ ctx.stack.push(node.i);
1068
+ const result = serializeNodeList(ctx, node);
935
1069
  ctx.stack.pop();
936
- return assignRef(ctx, id, result);
1070
+ return assignRef(ctx, node.i, result);
937
1071
  }
938
1072
  function serializeWithObjectAssign(ctx, value, id, serialized) {
939
1073
  const fields = serializeObject(ctx, id, value);
@@ -942,44 +1076,44 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
942
1076
  }
943
1077
  return serialized;
944
1078
  }
945
- function serializeAggregateError(ctx, message, options, errors, id) {
946
- ctx.stack.push(id);
947
- 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)})`;
948
1082
  ctx.stack.pop();
949
- if (options) {
1083
+ if (node.d) {
950
1084
  if (ctx.features & 64 /* ObjectAssign */) {
951
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1085
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
952
1086
  } else {
953
- markRef(ctx, id);
954
- const assignments = serializeAssignments(ctx, id, options);
1087
+ markRef(ctx, node.i);
1088
+ const assignments = serializeAssignments(ctx, node.i, node.d);
955
1089
  if (assignments) {
956
- const ref = getRefParam(ctx, id);
957
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1090
+ const ref = getRefParam(ctx, node.i);
1091
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
958
1092
  }
959
1093
  }
960
1094
  }
961
- return assignRef(ctx, id, serialized);
1095
+ return assignRef(ctx, node.i, serialized);
962
1096
  }
963
- function serializeError(ctx, constructor, message, options, id) {
964
- let serialized = `new ${constructor}(${quote(message)})`;
965
- if (options) {
1097
+ function serializeError(ctx, node) {
1098
+ let serialized = `new ${node.c}(${quote(node.m)})`;
1099
+ if (node.d) {
966
1100
  if (ctx.features & 64 /* ObjectAssign */) {
967
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1101
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
968
1102
  } else {
969
- markRef(ctx, id);
970
- const assignments = serializeAssignments(ctx, id, options);
1103
+ markRef(ctx, node.i);
1104
+ const assignments = serializeAssignments(ctx, node.i, node.d);
971
1105
  if (assignments) {
972
- const ref = getRefParam(ctx, id);
973
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1106
+ const ref = getRefParam(ctx, node.i);
1107
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
974
1108
  }
975
1109
  }
976
1110
  }
977
- return assignRef(ctx, id, serialized);
1111
+ return assignRef(ctx, node.i, serialized);
978
1112
  }
979
- function serializeIterable(ctx, options, items, id) {
1113
+ function serializeIterable(ctx, node) {
980
1114
  const parent = ctx.stack;
981
1115
  ctx.stack = [];
982
- const values = serializeNodeList(ctx, items, id);
1116
+ const values = serializeNodeList(ctx, node);
983
1117
  ctx.stack = parent;
984
1118
  let serialized;
985
1119
  if (ctx.features & 2 /* ArrayPrototypeValues */) {
@@ -994,67 +1128,67 @@ function serializeIterable(ctx, options, items, id) {
994
1128
  } else {
995
1129
  serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
996
1130
  }
997
- if (options) {
1131
+ if (node.d) {
998
1132
  if (ctx.features & 64 /* ObjectAssign */) {
999
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1133
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
1000
1134
  } else {
1001
- markRef(ctx, id);
1002
- const assignments = serializeAssignments(ctx, id, options);
1135
+ markRef(ctx, node.i);
1136
+ const assignments = serializeAssignments(ctx, node.i, node.d);
1003
1137
  if (assignments) {
1004
- const ref = getRefParam(ctx, id);
1005
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1138
+ const ref = getRefParam(ctx, node.i);
1139
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
1006
1140
  }
1007
1141
  }
1008
1142
  }
1009
- return assignRef(ctx, id, serialized);
1143
+ return assignRef(ctx, node.i, serialized);
1010
1144
  }
1011
- function serializeNullConstructor(ctx, value, id) {
1145
+ function serializeNullConstructor(ctx, node) {
1012
1146
  let serialized = "Object.create(null)";
1013
1147
  if (ctx.features & 64 /* ObjectAssign */) {
1014
- serialized = serializeWithObjectAssign(ctx, value, id, serialized);
1148
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
1015
1149
  } else {
1016
- markRef(ctx, id);
1017
- const assignments = serializeAssignments(ctx, id, value);
1150
+ markRef(ctx, node.i);
1151
+ const assignments = serializeAssignments(ctx, node.i, node.d);
1018
1152
  if (assignments) {
1019
- const ref = getRefParam(ctx, id);
1020
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1153
+ const ref = getRefParam(ctx, node.i);
1154
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
1021
1155
  }
1022
1156
  }
1023
- return assignRef(ctx, id, serialized);
1157
+ return assignRef(ctx, node.i, serialized);
1024
1158
  }
1025
- function serializeTree(ctx, [type, value, id]) {
1026
- switch (type) {
1159
+ function serializeTree(ctx, node) {
1160
+ switch (node.t) {
1027
1161
  case 0 /* Primitive */:
1028
- return String(value);
1162
+ return String(node.s);
1029
1163
  case 2 /* Reference */:
1030
- return getRefParam(ctx, value);
1164
+ return getRefParam(ctx, node.i);
1031
1165
  case 10 /* Promise */:
1032
- return serializePromise(ctx, value, id);
1166
+ return serializePromise(ctx, node);
1033
1167
  case 1 /* BigInt */:
1034
- return value;
1168
+ return node.s;
1035
1169
  case 3 /* Date */:
1036
- return assignRef(ctx, id, `new Date("${value}")`);
1170
+ return assignRef(ctx, node.i, `new Date("${node.s}")`);
1037
1171
  case 4 /* RegExp */:
1038
- return assignRef(ctx, id, value);
1172
+ return assignRef(ctx, node.i, node.s);
1039
1173
  case 15 /* BigIntTypedArray */:
1040
1174
  case 14 /* TypedArray */:
1041
- return serializeTypedArray(ctx, value[0], value[1], value[2], id);
1175
+ return serializeTypedArray(ctx, node);
1042
1176
  case 5 /* Set */:
1043
- return serializeSet(ctx, value, id);
1177
+ return serializeSet(ctx, node);
1044
1178
  case 6 /* Map */:
1045
- return serializeMap(ctx, value[0], value[1], value[2], id);
1179
+ return serializeMap(ctx, node);
1046
1180
  case 7 /* Array */:
1047
- return serializeArray(ctx, value, id);
1181
+ return serializeArray(ctx, node);
1048
1182
  case 12 /* AggregateError */:
1049
- return serializeAggregateError(ctx, value[0], value[1], value[2], id);
1183
+ return serializeAggregateError(ctx, node);
1050
1184
  case 11 /* Error */:
1051
- return serializeError(ctx, value[0], value[1], value[2], id);
1185
+ return serializeError(ctx, node);
1052
1186
  case 13 /* Iterable */:
1053
- return serializeIterable(ctx, value[0], value[1], id);
1187
+ return serializeIterable(ctx, node);
1054
1188
  case 9 /* NullConstructor */:
1055
- return serializeNullConstructor(ctx, value, id);
1189
+ return serializeNullConstructor(ctx, node);
1056
1190
  case 8 /* Object */:
1057
- return assignRef(ctx, id, serializeObject(ctx, id, value));
1191
+ return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1058
1192
  default:
1059
1193
  throw new Error("Unsupported type");
1060
1194
  }
@@ -1085,7 +1219,11 @@ function serializePropertiesSync(ctx, properties) {
1085
1219
  keyNodes[nodesSize + i] = deferredKeys[i];
1086
1220
  valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
1087
1221
  }
1088
- return [keyNodes, valueNodes, size];
1222
+ return {
1223
+ k: keyNodes,
1224
+ v: valueNodes,
1225
+ s: size
1226
+ };
1089
1227
  }
1090
1228
  function generateSetNode2(ctx, current, id) {
1091
1229
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -1104,7 +1242,17 @@ function generateSetNode2(ctx, current, id) {
1104
1242
  for (let i = 0; i < deferredSize; i++) {
1105
1243
  nodes[nodeSize + i] = generateTreeSync(ctx, deferred[i]);
1106
1244
  }
1107
- 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
+ };
1108
1256
  }
1109
1257
  function generateMapNode2(ctx, current, id) {
1110
1258
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -1130,7 +1278,17 @@ function generateMapNode2(ctx, current, id) {
1130
1278
  keyNodes[nodeSize + i] = generateTreeSync(ctx, deferredKey[i]);
1131
1279
  valueNodes[nodeSize + i] = generateTreeSync(ctx, deferredValue[i]);
1132
1280
  }
1133
- 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
+ };
1134
1292
  }
1135
1293
  function generateNodeList2(ctx, current) {
1136
1294
  const size = current.length;
@@ -1153,38 +1311,81 @@ function generateNodeList2(ctx, current) {
1153
1311
  return nodes;
1154
1312
  }
1155
1313
  function generateArrayNode2(ctx, current, id) {
1156
- 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
+ };
1157
1325
  }
1158
1326
  function generateAggregateErrorNode2(ctx, current, id) {
1159
1327
  const options = getErrorOptions(current);
1160
1328
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1161
- const errorsNode = generateTreeSync(ctx, current.errors);
1162
- 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
+ };
1163
1340
  }
1164
1341
  function generateErrorNode2(ctx, current, id) {
1165
1342
  const options = getErrorOptions(current);
1166
1343
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1167
- return [
1168
- 11 /* Error */,
1169
- [getErrorConstructor(current), current.message, optionsNode],
1170
- id
1171
- ];
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
+ };
1172
1355
  }
1173
1356
  function generateIterableNode2(ctx, current, id) {
1174
1357
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1175
1358
  const options = getIterableOptions(current);
1176
- 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,
1177
1366
  // Parse options first before the items
1178
- options ? serializePropertiesSync(ctx, options) : void 0,
1179
- generateNodeList2(ctx, Array.from(current))
1180
- ], id];
1367
+ d: options ? serializePropertiesSync(ctx, options) : void 0,
1368
+ a: generateNodeList2(ctx, Array.from(current)),
1369
+ n: void 0
1370
+ };
1181
1371
  }
1182
1372
  function generateTreeSync(ctx, current) {
1183
1373
  if (isPrimitive(current)) {
1184
- 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
+ };
1185
1386
  }
1186
1387
  const id = generateRef(ctx, current);
1187
- if (Array.isArray(id)) {
1388
+ if (typeof id !== "number") {
1188
1389
  return id;
1189
1390
  }
1190
1391
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -1211,17 +1412,24 @@ function generateTreeSync(ctx, current) {
1211
1412
  }
1212
1413
  const empty = current.constructor == null;
1213
1414
  if (current.constructor === Object || empty) {
1214
- return [
1215
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
1216
- serializePropertiesSync(ctx, current),
1217
- id
1218
- ];
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
+ };
1219
1427
  }
1220
1428
  throw new Error("Unsupported value");
1221
1429
  }
1222
1430
  function parseSync(ctx, current) {
1223
1431
  const result = generateTreeSync(ctx, current);
1224
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
1432
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
1225
1433
  }
1226
1434
 
1227
1435
  // src/index.ts
@@ -1280,7 +1488,7 @@ function toJSON(source, options) {
1280
1488
  root,
1281
1489
  isObject,
1282
1490
  ctx.features,
1283
- [...ctx.markedRefs]
1491
+ ctx.markedRefs
1284
1492
  ]);
1285
1493
  }
1286
1494
  async function toJSONAsync(source, options) {
@@ -1291,7 +1499,7 @@ async function toJSONAsync(source, options) {
1291
1499
  root,
1292
1500
  isObject,
1293
1501
  ctx.features,
1294
- [...ctx.markedRefs]
1502
+ ctx.markedRefs
1295
1503
  ]);
1296
1504
  }
1297
1505
  function compileJSON(source) {