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.
@@ -254,7 +254,7 @@ var DEFAULT_OPTIONS = {
254
254
  function createParserContext(options = {}) {
255
255
  const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
256
256
  return {
257
- markedRefs: /* @__PURE__ */ new Set(),
257
+ markedRefs: {},
258
258
  refs: /* @__PURE__ */ new Map(),
259
259
  features: parseTargets(result.target)
260
260
  };
@@ -264,22 +264,23 @@ function createSerializationContext(options) {
264
264
  stack: [],
265
265
  vars: [],
266
266
  assignments: [],
267
- validRefs: /* @__PURE__ */ new Map(),
267
+ validRefs: [],
268
+ refSize: 0,
268
269
  features: options.features,
269
- markedRefs: new Set(options.markedRefs)
270
+ markedRefs: options.markedRefs
270
271
  };
271
272
  }
272
273
  function markRef(ctx, current) {
273
- ctx.markedRefs.add(current);
274
+ ctx.markedRefs[current] = 1;
274
275
  }
275
276
  function createValidRef(ctx, index) {
276
- const current = ctx.validRefs.get(index);
277
- if (current != null) {
278
- return current;
277
+ const current = ctx.validRefs[index];
278
+ if (current == null) {
279
+ const value = ctx.refSize++;
280
+ ctx.validRefs[index] = value;
281
+ return value;
279
282
  }
280
- const id = ctx.validRefs.size;
281
- ctx.validRefs.set(index, id);
282
- return id;
283
+ return current;
283
284
  }
284
285
  function getRefParam(ctx, index) {
285
286
  const actualIndex = createValidRef(ctx, index);
@@ -393,14 +394,24 @@ function getIterableOptions(obj) {
393
394
  return void 0;
394
395
  }
395
396
  function isReferenceInStack(ctx, node) {
396
- return node[0] === 2 /* Reference */ && ctx.stack.includes(node[1]);
397
+ return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
397
398
  }
398
399
  function generateRef(ctx, current) {
399
400
  const ref = ctx.refs.has(current);
400
401
  if (ref) {
401
402
  const refID = ctx.refs.get(current) || 0;
402
403
  markRef(ctx, refID);
403
- 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
+ };
404
415
  }
405
416
  const id = ctx.refs.size;
406
417
  ctx.refs.set(current, id);
@@ -409,18 +420,58 @@ function generateRef(ctx, current) {
409
420
  function generateSemiPrimitiveValue(ctx, current, id) {
410
421
  if (typeof current === "bigint") {
411
422
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
412
- 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
+ };
413
434
  }
414
435
  if (constructorCheck(current, Date)) {
415
- 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
+ };
416
447
  }
417
448
  if (constructorCheck(current, RegExp)) {
418
- 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
+ };
419
460
  }
420
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)) {
421
462
  const constructor = current.constructor.name;
422
463
  assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
423
- 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
+ };
424
475
  }
425
476
  if (constructorCheck(current, BigInt64Array) || constructorCheck(current, BigUint64Array)) {
426
477
  const constructor = current.constructor.name;
@@ -434,11 +485,17 @@ function generateSemiPrimitiveValue(ctx, current, id) {
434
485
  result += `${current[i]}n,`;
435
486
  }
436
487
  result += `"${current[cap]}"`;
437
- return [
438
- 15 /* BigIntTypedArray */,
439
- [constructor, result, current.byteOffset],
440
- id
441
- ];
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
+ };
442
499
  }
443
500
  return void 0;
444
501
  }
@@ -495,7 +552,11 @@ async function serializePropertiesAsync(ctx, properties) {
495
552
  keyNodes[nodesSize + i] = deferredKeys[i];
496
553
  valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
497
554
  }
498
- return [keyNodes, valueNodes, size];
555
+ return {
556
+ k: keyNodes,
557
+ v: valueNodes,
558
+ s: size
559
+ };
499
560
  }
500
561
  async function generateSetNode(ctx, current, id) {
501
562
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -514,7 +575,17 @@ async function generateSetNode(ctx, current, id) {
514
575
  for (let i = 0; i < deferredSize; i++) {
515
576
  nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
516
577
  }
517
- 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
+ };
518
589
  }
519
590
  async function generateMapNode(ctx, current, id) {
520
591
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -540,7 +611,17 @@ async function generateMapNode(ctx, current, id) {
540
611
  keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
541
612
  valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
542
613
  }
543
- 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
+ };
544
625
  }
545
626
  async function generateNodeList(ctx, current) {
546
627
  const size = current.length;
@@ -563,42 +644,81 @@ async function generateNodeList(ctx, current) {
563
644
  return nodes;
564
645
  }
565
646
  async function generateArrayNode(ctx, current, id) {
566
- 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
+ };
567
658
  }
568
659
  async function generateAggregateErrorNode(ctx, current, id) {
569
660
  const options = getErrorOptions(current);
570
661
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
571
- const errorsNode = await generateTreeAsync(ctx, current.errors);
572
- return [
573
- 12 /* AggregateError */,
574
- [current.message, optionsNode, errorsNode],
575
- id
576
- ];
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
+ };
577
673
  }
578
674
  async function generateErrorNode(ctx, current, id) {
579
675
  const options = getErrorOptions(current);
580
676
  const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
581
- return [
582
- 11 /* Error */,
583
- [getErrorConstructor(current), current.message, optionsNode],
584
- id
585
- ];
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
+ };
586
688
  }
587
689
  async function generateIterableNode(ctx, current, id) {
588
690
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
589
691
  const options = getIterableOptions(current);
590
- 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,
591
699
  // Parse options first before the items
592
- options ? await serializePropertiesAsync(ctx, options) : void 0,
593
- await generateNodeList(ctx, Array.from(current))
594
- ], id];
700
+ d: options ? await serializePropertiesAsync(ctx, options) : void 0,
701
+ a: await generateNodeList(ctx, Array.from(current)),
702
+ n: void 0
703
+ };
595
704
  }
596
705
  async function generateTreeAsync(ctx, current) {
597
706
  if (isPrimitive(current)) {
598
- 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
+ };
599
719
  }
600
720
  const id = generateRef(ctx, current);
601
- if (Array.isArray(id)) {
721
+ if (typeof id !== "number") {
602
722
  return id;
603
723
  }
604
724
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -607,11 +727,18 @@ async function generateTreeAsync(ctx, current) {
607
727
  }
608
728
  if (isPromise(current)) {
609
729
  assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
610
- return current.then(async (value) => [
611
- 10 /* Promise */,
612
- await generateTreeAsync(ctx, value),
613
- id
614
- ]);
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
+ }));
615
742
  }
616
743
  if (constructorCheck(current, Set)) {
617
744
  return generateSetNode(ctx, current, id);
@@ -633,17 +760,24 @@ async function generateTreeAsync(ctx, current) {
633
760
  }
634
761
  const empty = current.constructor == null;
635
762
  if (current.constructor === Object || empty) {
636
- return [
637
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
638
- await serializePropertiesAsync(ctx, current),
639
- id
640
- ];
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
+ };
641
775
  }
642
776
  throw new Error("Unsupported value");
643
777
  }
644
778
  async function parseAsync(ctx, current) {
645
779
  const result = await generateTreeAsync(ctx, current);
646
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
780
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
647
781
  }
648
782
 
649
783
  // src/tree/serialize.ts
@@ -713,7 +847,7 @@ function resolvePatches(ctx) {
713
847
  return resolveAssignments(ctx.assignments);
714
848
  }
715
849
  function assignRef(ctx, index, value) {
716
- if (ctx.markedRefs.has(index)) {
850
+ if (ctx.markedRefs[index]) {
717
851
  return `${getRefParam(ctx, index)}=${value}`;
718
852
  }
719
853
  return value;
@@ -751,15 +885,15 @@ function createObjectAssign(ctx, ref, key, value) {
751
885
  createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
752
886
  }
753
887
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
754
- function serializeAssignments(ctx, targetRef, [keys, values, size]) {
888
+ function serializeAssignments(ctx, targetRef, node) {
755
889
  ctx.stack.push(targetRef);
756
890
  const mainAssignments = [];
757
- for (let i = 0; i < size; i++) {
891
+ for (let i = 0; i < node.s; i++) {
758
892
  const parentStack = ctx.stack;
759
893
  ctx.stack = [];
760
- const refParam = serializeTree(ctx, values[i]);
894
+ const refParam = serializeTree(ctx, node.v[i]);
761
895
  ctx.stack = parentStack;
762
- const key = keys[i];
896
+ const key = node.k[i];
763
897
  const check = Number(key);
764
898
  const parentAssignment = ctx.assignments;
765
899
  ctx.assignments = mainAssignments;
@@ -774,19 +908,19 @@ function serializeAssignments(ctx, targetRef, [keys, values, size]) {
774
908
  ctx.stack.pop();
775
909
  return resolveAssignments(mainAssignments);
776
910
  }
777
- function serializeObject(ctx, sourceID, [keys, values, size]) {
778
- if (size === 0) {
911
+ function serializeObject(ctx, sourceID, node) {
912
+ if (node.s === 0) {
779
913
  return "{}";
780
914
  }
781
915
  let result = "";
782
916
  ctx.stack.push(sourceID);
783
- for (let i = 0; i < size; i++) {
784
- const key = keys[i];
785
- 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];
786
920
  const check = Number(key);
787
921
  const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
788
922
  if (isReferenceInStack(ctx, val)) {
789
- const refParam = getRefParam(ctx, val[1]);
923
+ const refParam = getRefParam(ctx, val.i);
790
924
  if (isIdentifier && Number.isNaN(check)) {
791
925
  createObjectAssign(ctx, sourceID, key, refParam);
792
926
  } else {
@@ -799,35 +933,35 @@ function serializeObject(ctx, sourceID, [keys, values, size]) {
799
933
  ctx.stack.pop();
800
934
  return `{${result.substring(0, result.length - 1)}}`;
801
935
  }
802
- function serializePromise(ctx, value, id) {
936
+ function serializePromise(ctx, node) {
803
937
  let serialized;
804
- if (isReferenceInStack(ctx, value)) {
805
- serialized = `Promise.resolve().then(()=>${getRefParam(ctx, value[1])})`;
938
+ if (isReferenceInStack(ctx, node.n)) {
939
+ serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
806
940
  } else {
807
- ctx.stack.push(id);
808
- const result = serializeTree(ctx, value);
941
+ ctx.stack.push(node.i);
942
+ const result = serializeTree(ctx, node.n);
809
943
  ctx.stack.pop();
810
944
  serialized = `Promise.resolve(${result})`;
811
945
  }
812
- return assignRef(ctx, id, serialized);
946
+ return assignRef(ctx, node.i, serialized);
813
947
  }
814
- function serializeTypedArray(ctx, constructor, init, byteOffset, id) {
815
- let args = `[${init}]`;
816
- if (byteOffset !== 0) {
817
- args += `,${byteOffset}`;
948
+ function serializeTypedArray(ctx, node) {
949
+ let args = `[${node.s}]`;
950
+ if (node.l !== 0) {
951
+ args += `,${node.l}`;
818
952
  }
819
- return assignRef(ctx, id, `new ${constructor}(${args})`);
953
+ return assignRef(ctx, node.i, `new ${node.c}(${args})`);
820
954
  }
821
- function serializeSet(ctx, value, id) {
955
+ function serializeSet(ctx, node) {
822
956
  let serialized = "new Set";
823
- const size = value.length;
957
+ const size = node.a.length;
824
958
  if (size) {
825
959
  let result = "";
826
- ctx.stack.push(id);
960
+ ctx.stack.push(node.i);
827
961
  for (let i = 0; i < size; i++) {
828
- const item = value[i];
962
+ const item = node.a[i];
829
963
  if (isReferenceInStack(ctx, item)) {
830
- createSetAdd(ctx, id, getRefParam(ctx, item[1]));
964
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
831
965
  } else {
832
966
  result += `${serializeTree(ctx, item)},`;
833
967
  }
@@ -837,32 +971,32 @@ function serializeSet(ctx, value, id) {
837
971
  serialized += `([${result.substring(0, result.length - 1)}])`;
838
972
  }
839
973
  }
840
- return assignRef(ctx, id, serialized);
974
+ return assignRef(ctx, node.i, serialized);
841
975
  }
842
- function serializeMap(ctx, keys, values, size, id) {
976
+ function serializeMap(ctx, node) {
843
977
  let serialized = "new Map";
844
- if (size) {
978
+ if (node.d.s) {
845
979
  let result = "";
846
- ctx.stack.push(id);
847
- for (let i = 0; i < size; i++) {
848
- const key = keys[i];
849
- 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];
850
984
  if (isReferenceInStack(ctx, key)) {
851
- const keyRef = getRefParam(ctx, key[1]);
985
+ const keyRef = getRefParam(ctx, key.i);
852
986
  if (isReferenceInStack(ctx, val)) {
853
- const valueRef = getRefParam(ctx, val[1]);
854
- createMapSet(ctx, id, keyRef, valueRef);
987
+ const valueRef = getRefParam(ctx, val.i);
988
+ createMapSet(ctx, node.i, keyRef, valueRef);
855
989
  } else {
856
990
  const parent = ctx.stack;
857
991
  ctx.stack = [];
858
- createMapSet(ctx, id, keyRef, serializeTree(ctx, val));
992
+ createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
859
993
  ctx.stack = parent;
860
994
  }
861
995
  } else if (isReferenceInStack(ctx, val)) {
862
- const valueRef = getRefParam(ctx, val[1]);
996
+ const valueRef = getRefParam(ctx, val.i);
863
997
  const parent = ctx.stack;
864
998
  ctx.stack = [];
865
- createMapSet(ctx, id, serializeTree(ctx, key), valueRef);
999
+ createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
866
1000
  ctx.stack = parent;
867
1001
  } else {
868
1002
  result += `[${serializeTree(ctx, key)},${serializeTree(ctx, val)}],`;
@@ -873,16 +1007,16 @@ function serializeMap(ctx, keys, values, size, id) {
873
1007
  serialized += `([${result.substring(0, result.length - 1)}])`;
874
1008
  }
875
1009
  }
876
- return assignRef(ctx, id, serialized);
1010
+ return assignRef(ctx, node.i, serialized);
877
1011
  }
878
- function serializeNodeList(ctx, value, id) {
879
- const size = value.length;
1012
+ function serializeNodeList(ctx, node) {
1013
+ const size = node.a.length;
880
1014
  let values = "";
881
1015
  for (let i = 0; i < size; i++) {
882
- const item = value[i];
1016
+ const item = node.a[i];
883
1017
  if (item) {
884
1018
  if (isReferenceInStack(ctx, item)) {
885
- createArrayAssign(ctx, id, i, getRefParam(ctx, item[1]));
1019
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
886
1020
  values += ",";
887
1021
  } else {
888
1022
  values += serializeTree(ctx, item);
@@ -896,11 +1030,11 @@ function serializeNodeList(ctx, value, id) {
896
1030
  }
897
1031
  return `[${values}]`;
898
1032
  }
899
- function serializeArray(ctx, value, id) {
900
- ctx.stack.push(id);
901
- const result = serializeNodeList(ctx, value, id);
1033
+ function serializeArray(ctx, node) {
1034
+ ctx.stack.push(node.i);
1035
+ const result = serializeNodeList(ctx, node);
902
1036
  ctx.stack.pop();
903
- return assignRef(ctx, id, result);
1037
+ return assignRef(ctx, node.i, result);
904
1038
  }
905
1039
  function serializeWithObjectAssign(ctx, value, id, serialized) {
906
1040
  const fields = serializeObject(ctx, id, value);
@@ -909,44 +1043,44 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
909
1043
  }
910
1044
  return serialized;
911
1045
  }
912
- function serializeAggregateError(ctx, message, options, errors, id) {
913
- ctx.stack.push(id);
914
- 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)})`;
915
1049
  ctx.stack.pop();
916
- if (options) {
1050
+ if (node.d) {
917
1051
  if (ctx.features & 64 /* ObjectAssign */) {
918
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1052
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
919
1053
  } else {
920
- markRef(ctx, id);
921
- const assignments = serializeAssignments(ctx, id, options);
1054
+ markRef(ctx, node.i);
1055
+ const assignments = serializeAssignments(ctx, node.i, node.d);
922
1056
  if (assignments) {
923
- const ref = getRefParam(ctx, id);
924
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1057
+ const ref = getRefParam(ctx, node.i);
1058
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
925
1059
  }
926
1060
  }
927
1061
  }
928
- return assignRef(ctx, id, serialized);
1062
+ return assignRef(ctx, node.i, serialized);
929
1063
  }
930
- function serializeError(ctx, constructor, message, options, id) {
931
- let serialized = `new ${constructor}(${quote(message)})`;
932
- if (options) {
1064
+ function serializeError(ctx, node) {
1065
+ let serialized = `new ${node.c}(${quote(node.m)})`;
1066
+ if (node.d) {
933
1067
  if (ctx.features & 64 /* ObjectAssign */) {
934
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1068
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
935
1069
  } else {
936
- markRef(ctx, id);
937
- const assignments = serializeAssignments(ctx, id, options);
1070
+ markRef(ctx, node.i);
1071
+ const assignments = serializeAssignments(ctx, node.i, node.d);
938
1072
  if (assignments) {
939
- const ref = getRefParam(ctx, id);
940
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1073
+ const ref = getRefParam(ctx, node.i);
1074
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
941
1075
  }
942
1076
  }
943
1077
  }
944
- return assignRef(ctx, id, serialized);
1078
+ return assignRef(ctx, node.i, serialized);
945
1079
  }
946
- function serializeIterable(ctx, options, items, id) {
1080
+ function serializeIterable(ctx, node) {
947
1081
  const parent = ctx.stack;
948
1082
  ctx.stack = [];
949
- const values = serializeNodeList(ctx, items, id);
1083
+ const values = serializeNodeList(ctx, node);
950
1084
  ctx.stack = parent;
951
1085
  let serialized;
952
1086
  if (ctx.features & 2 /* ArrayPrototypeValues */) {
@@ -961,67 +1095,67 @@ function serializeIterable(ctx, options, items, id) {
961
1095
  } else {
962
1096
  serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
963
1097
  }
964
- if (options) {
1098
+ if (node.d) {
965
1099
  if (ctx.features & 64 /* ObjectAssign */) {
966
- serialized = serializeWithObjectAssign(ctx, options, id, serialized);
1100
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
967
1101
  } else {
968
- markRef(ctx, id);
969
- const assignments = serializeAssignments(ctx, id, options);
1102
+ markRef(ctx, node.i);
1103
+ const assignments = serializeAssignments(ctx, node.i, node.d);
970
1104
  if (assignments) {
971
- const ref = getRefParam(ctx, id);
972
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1105
+ const ref = getRefParam(ctx, node.i);
1106
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
973
1107
  }
974
1108
  }
975
1109
  }
976
- return assignRef(ctx, id, serialized);
1110
+ return assignRef(ctx, node.i, serialized);
977
1111
  }
978
- function serializeNullConstructor(ctx, value, id) {
1112
+ function serializeNullConstructor(ctx, node) {
979
1113
  let serialized = "Object.create(null)";
980
1114
  if (ctx.features & 64 /* ObjectAssign */) {
981
- serialized = serializeWithObjectAssign(ctx, value, id, serialized);
1115
+ serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
982
1116
  } else {
983
- markRef(ctx, id);
984
- const assignments = serializeAssignments(ctx, id, value);
1117
+ markRef(ctx, node.i);
1118
+ const assignments = serializeAssignments(ctx, node.i, node.d);
985
1119
  if (assignments) {
986
- const ref = getRefParam(ctx, id);
987
- return `(${assignRef(ctx, id, serialized)},${assignments}${ref})`;
1120
+ const ref = getRefParam(ctx, node.i);
1121
+ return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
988
1122
  }
989
1123
  }
990
- return assignRef(ctx, id, serialized);
1124
+ return assignRef(ctx, node.i, serialized);
991
1125
  }
992
- function serializeTree(ctx, [type, value, id]) {
993
- switch (type) {
1126
+ function serializeTree(ctx, node) {
1127
+ switch (node.t) {
994
1128
  case 0 /* Primitive */:
995
- return String(value);
1129
+ return String(node.s);
996
1130
  case 2 /* Reference */:
997
- return getRefParam(ctx, value);
1131
+ return getRefParam(ctx, node.i);
998
1132
  case 10 /* Promise */:
999
- return serializePromise(ctx, value, id);
1133
+ return serializePromise(ctx, node);
1000
1134
  case 1 /* BigInt */:
1001
- return value;
1135
+ return node.s;
1002
1136
  case 3 /* Date */:
1003
- return assignRef(ctx, id, `new Date("${value}")`);
1137
+ return assignRef(ctx, node.i, `new Date("${node.s}")`);
1004
1138
  case 4 /* RegExp */:
1005
- return assignRef(ctx, id, value);
1139
+ return assignRef(ctx, node.i, node.s);
1006
1140
  case 15 /* BigIntTypedArray */:
1007
1141
  case 14 /* TypedArray */:
1008
- return serializeTypedArray(ctx, value[0], value[1], value[2], id);
1142
+ return serializeTypedArray(ctx, node);
1009
1143
  case 5 /* Set */:
1010
- return serializeSet(ctx, value, id);
1144
+ return serializeSet(ctx, node);
1011
1145
  case 6 /* Map */:
1012
- return serializeMap(ctx, value[0], value[1], value[2], id);
1146
+ return serializeMap(ctx, node);
1013
1147
  case 7 /* Array */:
1014
- return serializeArray(ctx, value, id);
1148
+ return serializeArray(ctx, node);
1015
1149
  case 12 /* AggregateError */:
1016
- return serializeAggregateError(ctx, value[0], value[1], value[2], id);
1150
+ return serializeAggregateError(ctx, node);
1017
1151
  case 11 /* Error */:
1018
- return serializeError(ctx, value[0], value[1], value[2], id);
1152
+ return serializeError(ctx, node);
1019
1153
  case 13 /* Iterable */:
1020
- return serializeIterable(ctx, value[0], value[1], id);
1154
+ return serializeIterable(ctx, node);
1021
1155
  case 9 /* NullConstructor */:
1022
- return serializeNullConstructor(ctx, value, id);
1156
+ return serializeNullConstructor(ctx, node);
1023
1157
  case 8 /* Object */:
1024
- return assignRef(ctx, id, serializeObject(ctx, id, value));
1158
+ return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1025
1159
  default:
1026
1160
  throw new Error("Unsupported type");
1027
1161
  }
@@ -1052,7 +1186,11 @@ function serializePropertiesSync(ctx, properties) {
1052
1186
  keyNodes[nodesSize + i] = deferredKeys[i];
1053
1187
  valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
1054
1188
  }
1055
- return [keyNodes, valueNodes, size];
1189
+ return {
1190
+ k: keyNodes,
1191
+ v: valueNodes,
1192
+ s: size
1193
+ };
1056
1194
  }
1057
1195
  function generateSetNode2(ctx, current, id) {
1058
1196
  assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -1071,7 +1209,17 @@ function generateSetNode2(ctx, current, id) {
1071
1209
  for (let i = 0; i < deferredSize; i++) {
1072
1210
  nodes[nodeSize + i] = generateTreeSync(ctx, deferred[i]);
1073
1211
  }
1074
- 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
+ };
1075
1223
  }
1076
1224
  function generateMapNode2(ctx, current, id) {
1077
1225
  assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -1097,7 +1245,17 @@ function generateMapNode2(ctx, current, id) {
1097
1245
  keyNodes[nodeSize + i] = generateTreeSync(ctx, deferredKey[i]);
1098
1246
  valueNodes[nodeSize + i] = generateTreeSync(ctx, deferredValue[i]);
1099
1247
  }
1100
- 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
+ };
1101
1259
  }
1102
1260
  function generateNodeList2(ctx, current) {
1103
1261
  const size = current.length;
@@ -1120,38 +1278,81 @@ function generateNodeList2(ctx, current) {
1120
1278
  return nodes;
1121
1279
  }
1122
1280
  function generateArrayNode2(ctx, current, id) {
1123
- 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
+ };
1124
1292
  }
1125
1293
  function generateAggregateErrorNode2(ctx, current, id) {
1126
1294
  const options = getErrorOptions(current);
1127
1295
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1128
- const errorsNode = generateTreeSync(ctx, current.errors);
1129
- 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
+ };
1130
1307
  }
1131
1308
  function generateErrorNode2(ctx, current, id) {
1132
1309
  const options = getErrorOptions(current);
1133
1310
  const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
1134
- return [
1135
- 11 /* Error */,
1136
- [getErrorConstructor(current), current.message, optionsNode],
1137
- id
1138
- ];
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
+ };
1139
1322
  }
1140
1323
  function generateIterableNode2(ctx, current, id) {
1141
1324
  assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1142
1325
  const options = getIterableOptions(current);
1143
- 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,
1144
1333
  // Parse options first before the items
1145
- options ? serializePropertiesSync(ctx, options) : void 0,
1146
- generateNodeList2(ctx, Array.from(current))
1147
- ], id];
1334
+ d: options ? serializePropertiesSync(ctx, options) : void 0,
1335
+ a: generateNodeList2(ctx, Array.from(current)),
1336
+ n: void 0
1337
+ };
1148
1338
  }
1149
1339
  function generateTreeSync(ctx, current) {
1150
1340
  if (isPrimitive(current)) {
1151
- 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
+ };
1152
1353
  }
1153
1354
  const id = generateRef(ctx, current);
1154
- if (Array.isArray(id)) {
1355
+ if (typeof id !== "number") {
1155
1356
  return id;
1156
1357
  }
1157
1358
  const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
@@ -1178,17 +1379,24 @@ function generateTreeSync(ctx, current) {
1178
1379
  }
1179
1380
  const empty = current.constructor == null;
1180
1381
  if (current.constructor === Object || empty) {
1181
- return [
1182
- empty ? 9 /* NullConstructor */ : 8 /* Object */,
1183
- serializePropertiesSync(ctx, current),
1184
- id
1185
- ];
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
+ };
1186
1394
  }
1187
1395
  throw new Error("Unsupported value");
1188
1396
  }
1189
1397
  function parseSync(ctx, current) {
1190
1398
  const result = generateTreeSync(ctx, current);
1191
- return [result, createRef(ctx, current), result[0] === 8 /* Object */];
1399
+ return [result, createRef(ctx, current), result.t === 8 /* Object */];
1192
1400
  }
1193
1401
 
1194
1402
  // src/index.ts
@@ -1247,7 +1455,7 @@ function toJSON(source, options) {
1247
1455
  root,
1248
1456
  isObject,
1249
1457
  ctx.features,
1250
- [...ctx.markedRefs]
1458
+ ctx.markedRefs
1251
1459
  ]);
1252
1460
  }
1253
1461
  async function toJSONAsync(source, options) {
@@ -1258,7 +1466,7 @@ async function toJSONAsync(source, options) {
1258
1466
  root,
1259
1467
  isObject,
1260
1468
  ctx.features,
1261
- [...ctx.markedRefs]
1469
+ ctx.markedRefs
1262
1470
  ]);
1263
1471
  }
1264
1472
  function compileJSON(source) {