seroval 0.4.0-alpha.14 → 0.4.0-alpha.15

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.
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
6
  var __export = (target, all) => {
8
7
  for (var name in all)
9
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,10 +16,6 @@ var __copyProps = (to, from, except, desc) => {
17
16
  return to;
18
17
  };
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
19
 
25
20
  // src/index.ts
26
21
  var src_exports = {};
@@ -218,8 +213,9 @@ var platforms = [
218
213
  "samsung"
219
214
  ];
220
215
  function getPlatform(target) {
216
+ let platform;
221
217
  for (let i = 0, len = platforms.length; i < len; i++) {
222
- const platform = target.substring(0, platforms[i].length);
218
+ platform = target.substring(0, platforms[i].length);
223
219
  if (platform === platforms[i]) {
224
220
  return platform;
225
221
  }
@@ -245,11 +241,14 @@ function getTargetVersions(targets) {
245
241
  function parseTargets(targets) {
246
242
  const parsed = getTargetVersions(targets);
247
243
  let flags = 0;
244
+ let base;
245
+ let flag;
246
+ let baseVersion;
248
247
  for (const key of Object.keys(VERSION_TABLE)) {
249
- const base = VERSION_TABLE[key];
250
- let flag = true;
248
+ base = VERSION_TABLE[key];
249
+ flag = true;
251
250
  for (const [platform, version] of parsed) {
252
- const baseVersion = base[platform];
251
+ baseVersion = base[platform];
253
252
  flag = flag && !!baseVersion && compareVersion(baseVersion, version) <= 0;
254
253
  }
255
254
  if (flag) {
@@ -379,7 +378,7 @@ function quote(str) {
379
378
  } else {
380
379
  result += str.slice(lastPos);
381
380
  }
382
- return `"${result}"`;
381
+ return '"' + result + '"';
383
382
  }
384
383
 
385
384
  // src/tree/primitives.ts
@@ -408,7 +407,7 @@ function createBigIntNode(ctx, current) {
408
407
  return {
409
408
  t: 1 /* BigInt */,
410
409
  i: void 0,
411
- s: `${current}n`,
410
+ s: current.toString() + "n",
412
411
  l: void 0,
413
412
  c: void 0,
414
413
  m: void 0,
@@ -478,11 +477,12 @@ function createBigIntTypedArrayNode(ctx, id, current) {
478
477
  `Unsupported value type "${constructor}"`
479
478
  );
480
479
  let result = "";
481
- const cap = current.length - 1;
482
- for (let i = 0; i < cap; i++) {
483
- result += `${current[i]}n,`;
480
+ for (let i = 0, len = current.length; i < len; i++) {
481
+ if (i !== 0) {
482
+ result += ",";
483
+ }
484
+ result += current[i].toString() + "n";
484
485
  }
485
- result += `"${current[cap]}"`;
486
486
  return {
487
487
  t: 15 /* BigIntTypedArray */,
488
488
  i: id,
@@ -576,11 +576,7 @@ function isIterable(value) {
576
576
 
577
577
  // src/tree/async.ts
578
578
  var AsyncParser = class {
579
- constructor(ctx) {
580
- __publicField(this, "ctx");
581
- this.ctx = ctx;
582
- }
583
- async generateNodeList(current) {
579
+ static async generateNodeList(ctx, current) {
584
580
  const size = current.length;
585
581
  const nodes = new Array(size);
586
582
  const deferred = new Array(size);
@@ -591,18 +587,18 @@ var AsyncParser = class {
591
587
  if (isIterable(item)) {
592
588
  deferred[i] = item;
593
589
  } else {
594
- nodes[i] = await this.parse(item);
590
+ nodes[i] = await this.parse(ctx, item);
595
591
  }
596
592
  }
597
593
  }
598
594
  for (let i = 0; i < size; i++) {
599
595
  if (i in deferred) {
600
- nodes[i] = await this.parse(deferred[i]);
596
+ nodes[i] = await this.parse(ctx, deferred[i]);
601
597
  }
602
598
  }
603
599
  return nodes;
604
600
  }
605
- async generateArrayNode(id, current) {
601
+ static async generateArrayNode(ctx, id, current) {
606
602
  return {
607
603
  t: 7 /* Array */,
608
604
  i: id,
@@ -611,12 +607,12 @@ var AsyncParser = class {
611
607
  c: void 0,
612
608
  m: void 0,
613
609
  d: void 0,
614
- a: await this.generateNodeList(current),
610
+ a: await this.generateNodeList(ctx, current),
615
611
  n: void 0
616
612
  };
617
613
  }
618
- async generateMapNode(id, current) {
619
- assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
614
+ static async generateMapNode(ctx, id, current) {
615
+ assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
620
616
  const len = current.size;
621
617
  const keyNodes = new Array(len);
622
618
  const valueNodes = new Array(len);
@@ -630,14 +626,14 @@ var AsyncParser = class {
630
626
  deferredValue[deferredSize] = value;
631
627
  deferredSize++;
632
628
  } else {
633
- keyNodes[nodeSize] = await this.parse(key);
634
- valueNodes[nodeSize] = await this.parse(value);
629
+ keyNodes[nodeSize] = await this.parse(ctx, key);
630
+ valueNodes[nodeSize] = await this.parse(ctx, value);
635
631
  nodeSize++;
636
632
  }
637
633
  }
638
634
  for (let i = 0; i < deferredSize; i++) {
639
- keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
640
- valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
635
+ keyNodes[nodeSize + i] = await this.parse(ctx, deferredKey[i]);
636
+ valueNodes[nodeSize + i] = await this.parse(ctx, deferredValue[i]);
641
637
  }
642
638
  return {
643
639
  t: 6 /* Map */,
@@ -651,8 +647,8 @@ var AsyncParser = class {
651
647
  n: void 0
652
648
  };
653
649
  }
654
- async generateSetNode(id, current) {
655
- assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
650
+ static async generateSetNode(ctx, id, current) {
651
+ assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
656
652
  const len = current.size;
657
653
  const nodes = new Array(len);
658
654
  const deferred = new Array(len);
@@ -662,11 +658,11 @@ var AsyncParser = class {
662
658
  if (isIterable(item)) {
663
659
  deferred[deferredSize++] = item;
664
660
  } else {
665
- nodes[nodeSize++] = await this.parse(item);
661
+ nodes[nodeSize++] = await this.parse(ctx, item);
666
662
  }
667
663
  }
668
664
  for (let i = 0; i < deferredSize; i++) {
669
- nodes[nodeSize + i] = await this.parse(deferred[i]);
665
+ nodes[nodeSize + i] = await this.parse(ctx, deferred[i]);
670
666
  }
671
667
  return {
672
668
  t: 5 /* Set */,
@@ -680,7 +676,7 @@ var AsyncParser = class {
680
676
  n: void 0
681
677
  };
682
678
  }
683
- async generateProperties(properties) {
679
+ static async generateProperties(ctx, properties) {
684
680
  const keys = Object.keys(properties);
685
681
  const size = keys.length;
686
682
  const keyNodes = new Array(size);
@@ -698,13 +694,13 @@ var AsyncParser = class {
698
694
  deferredSize++;
699
695
  } else {
700
696
  keyNodes[nodesSize] = key;
701
- valueNodes[nodesSize] = await this.parse(item);
697
+ valueNodes[nodesSize] = await this.parse(ctx, item);
702
698
  nodesSize++;
703
699
  }
704
700
  }
705
701
  for (let i = 0; i < deferredSize; i++) {
706
702
  keyNodes[nodesSize + i] = deferredKeys[i];
707
- valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
703
+ valueNodes[nodesSize + i] = await this.parse(ctx, deferredValues[i]);
708
704
  }
709
705
  return {
710
706
  k: keyNodes,
@@ -712,8 +708,8 @@ var AsyncParser = class {
712
708
  s: size
713
709
  };
714
710
  }
715
- async generateIterableNode(id, current) {
716
- assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
711
+ static async generateIterableNode(ctx, id, current) {
712
+ assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
717
713
  const options = getIterableOptions(current);
718
714
  return {
719
715
  t: 13 /* Iterable */,
@@ -723,13 +719,13 @@ var AsyncParser = class {
723
719
  c: void 0,
724
720
  m: void 0,
725
721
  // Parse options first before the items
726
- d: options ? await this.generateProperties(options) : void 0,
727
- a: await this.generateNodeList(Array.from(current)),
722
+ d: options ? await this.generateProperties(ctx, options) : void 0,
723
+ a: await this.generateNodeList(ctx, Array.from(current)),
728
724
  n: void 0
729
725
  };
730
726
  }
731
- async generatePromiseNode(id, current) {
732
- assert(this.ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
727
+ static async generatePromiseNode(ctx, id, current) {
728
+ assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
733
729
  return current.then(async (value) => ({
734
730
  t: 10 /* Promise */,
735
731
  i: id,
@@ -740,15 +736,15 @@ var AsyncParser = class {
740
736
  // Parse options first before the items
741
737
  d: void 0,
742
738
  a: void 0,
743
- n: await this.parse(value)
739
+ n: await this.parse(ctx, value)
744
740
  }));
745
741
  }
746
- async generateObjectNode(id, current, empty) {
742
+ static async generateObjectNode(ctx, id, current, empty) {
747
743
  if (Symbol.iterator in current) {
748
- return this.generateIterableNode(id, current);
744
+ return this.generateIterableNode(ctx, id, current);
749
745
  }
750
746
  if ("then" in current && typeof current.then === "function") {
751
- return this.generatePromiseNode(id, current);
747
+ return this.generatePromiseNode(ctx, id, current);
752
748
  }
753
749
  return {
754
750
  t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
@@ -757,14 +753,14 @@ var AsyncParser = class {
757
753
  l: void 0,
758
754
  c: void 0,
759
755
  m: void 0,
760
- d: await this.generateProperties(current),
756
+ d: await this.generateProperties(ctx, current),
761
757
  a: void 0,
762
758
  n: void 0
763
759
  };
764
760
  }
765
- async generateAggregateErrorNode(id, current) {
761
+ static async generateAggregateErrorNode(ctx, id, current) {
766
762
  const options = getErrorOptions(current);
767
- const optionsNode = options ? await this.generateProperties(options) : void 0;
763
+ const optionsNode = options ? await this.generateProperties(ctx, options) : void 0;
768
764
  return {
769
765
  t: 12 /* AggregateError */,
770
766
  i: id,
@@ -774,12 +770,12 @@ var AsyncParser = class {
774
770
  m: current.message,
775
771
  d: optionsNode,
776
772
  a: void 0,
777
- n: await this.parse(current.errors)
773
+ n: await this.parse(ctx, current.errors)
778
774
  };
779
775
  }
780
- async generateErrorNode(id, current) {
776
+ static async generateErrorNode(ctx, id, current) {
781
777
  const options = getErrorOptions(current);
782
- const optionsNode = options ? await this.generateProperties(options) : void 0;
778
+ const optionsNode = options ? await this.generateProperties(ctx, options) : void 0;
783
779
  return {
784
780
  t: 11 /* Error */,
785
781
  i: id,
@@ -792,7 +788,7 @@ var AsyncParser = class {
792
788
  n: void 0
793
789
  };
794
790
  }
795
- async parse(current) {
791
+ static async parse(ctx, current) {
796
792
  switch (typeof current) {
797
793
  case "boolean":
798
794
  return current ? TRUE_NODE : FALSE_NODE;
@@ -812,17 +808,17 @@ var AsyncParser = class {
812
808
  }
813
809
  return createPrimitiveNode(current);
814
810
  case "bigint":
815
- return createBigIntNode(this.ctx, current);
811
+ return createBigIntNode(ctx, current);
816
812
  case "object": {
817
813
  if (!current) {
818
814
  return NULL_NODE;
819
815
  }
820
- const id = createRef(this.ctx, current, true);
821
- if (this.ctx.markedRefs.has(id)) {
816
+ const id = createRef(ctx, current, true);
817
+ if (ctx.markedRefs.has(id)) {
822
818
  return createReferenceNode(id);
823
819
  }
824
820
  if (Array.isArray(current)) {
825
- return this.generateArrayNode(id, current);
821
+ return this.generateArrayNode(ctx, id, current);
826
822
  }
827
823
  switch (current.constructor) {
828
824
  case Date:
@@ -830,7 +826,7 @@ var AsyncParser = class {
830
826
  case RegExp:
831
827
  return createRegExpNode(id, current);
832
828
  case Promise:
833
- return this.generatePromiseNode(id, current);
829
+ return this.generatePromiseNode(ctx, id, current);
834
830
  case Int8Array:
835
831
  case Int16Array:
836
832
  case Int32Array:
@@ -840,23 +836,41 @@ var AsyncParser = class {
840
836
  case Uint8ClampedArray:
841
837
  case Float32Array:
842
838
  case Float64Array:
843
- return createTypedArrayNode(this.ctx, id, current);
839
+ return createTypedArrayNode(ctx, id, current);
844
840
  case BigInt64Array:
845
841
  case BigUint64Array:
846
- return createBigIntTypedArrayNode(this.ctx, id, current);
842
+ return createBigIntTypedArrayNode(ctx, id, current);
847
843
  case Map:
848
- return this.generateMapNode(id, current);
844
+ return this.generateMapNode(
845
+ ctx,
846
+ id,
847
+ current
848
+ );
849
849
  case Set:
850
- return this.generateSetNode(id, current);
850
+ return this.generateSetNode(
851
+ ctx,
852
+ id,
853
+ current
854
+ );
851
855
  case Object:
852
- return this.generateObjectNode(id, current, false);
856
+ return this.generateObjectNode(
857
+ ctx,
858
+ id,
859
+ current,
860
+ false
861
+ );
853
862
  case void 0:
854
- return this.generateObjectNode(id, current, true);
863
+ return this.generateObjectNode(
864
+ ctx,
865
+ id,
866
+ current,
867
+ true
868
+ );
855
869
  case AggregateError:
856
- if (this.ctx.features & 1 /* AggregateError */) {
857
- return this.generateAggregateErrorNode(id, current);
870
+ if (ctx.features & 1 /* AggregateError */) {
871
+ return this.generateAggregateErrorNode(ctx, id, current);
858
872
  }
859
- return this.generateErrorNode(id, current);
873
+ return this.generateErrorNode(ctx, id, current);
860
874
  case Error:
861
875
  case EvalError:
862
876
  case RangeError:
@@ -864,24 +878,24 @@ var AsyncParser = class {
864
878
  case SyntaxError:
865
879
  case TypeError:
866
880
  case URIError:
867
- return this.generateErrorNode(id, current);
881
+ return this.generateErrorNode(ctx, id, current);
868
882
  default:
869
883
  break;
870
884
  }
871
- if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
872
- return this.generateAggregateErrorNode(id, current);
885
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
886
+ return this.generateAggregateErrorNode(ctx, id, current);
873
887
  }
874
888
  if (current instanceof Error) {
875
- return this.generateErrorNode(id, current);
889
+ return this.generateErrorNode(ctx, id, current);
876
890
  }
877
891
  if (current instanceof Promise) {
878
- return this.generatePromiseNode(id, current);
892
+ return this.generatePromiseNode(ctx, id, current);
879
893
  }
880
894
  if (Symbol.iterator in current) {
881
- return this.generateIterableNode(id, current);
895
+ return this.generateIterableNode(ctx, id, current);
882
896
  }
883
897
  if ("then" in current && typeof current.then === "function") {
884
- return this.generatePromiseNode(id, current);
898
+ return this.generatePromiseNode(ctx, id, current);
885
899
  }
886
900
  throw new Error("Unsupported type");
887
901
  }
@@ -891,7 +905,7 @@ var AsyncParser = class {
891
905
  }
892
906
  };
893
907
  async function parseAsync(ctx, current) {
894
- const result = await new AsyncParser(ctx).parse(current);
908
+ const result = await AsyncParser.parse(ctx, current);
895
909
  const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
896
910
  return [result, createRef(ctx, current, false), isObject];
897
911
  }
@@ -900,11 +914,11 @@ async function parseAsync(ctx, current) {
900
914
  function getAssignmentExpression(assignment) {
901
915
  switch (assignment.t) {
902
916
  case "index":
903
- return `${assignment.s}=${assignment.v}`;
917
+ return assignment.s + "=" + assignment.v;
904
918
  case "map":
905
- return `${assignment.s}.set(${assignment.k},${assignment.v})`;
919
+ return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
906
920
  case "set":
907
- return `${assignment.s}.add(${assignment.v})`;
921
+ return assignment.s + ".add(" + assignment.v + ")";
908
922
  default:
909
923
  return "";
910
924
  }
@@ -913,8 +927,9 @@ function mergeAssignments(assignments) {
913
927
  const newAssignments = [];
914
928
  let current = assignments[0];
915
929
  let prev = current;
930
+ let item;
916
931
  for (let i = 1, len = assignments.length; i < len; i++) {
917
- const item = assignments[i];
932
+ item = assignments[i];
918
933
  if (item.t === prev.t) {
919
934
  if (item.t === "index" && item.v === prev.v) {
920
935
  current = {
@@ -955,7 +970,7 @@ function resolveAssignments(assignments) {
955
970
  let result = "";
956
971
  const merged = mergeAssignments(assignments);
957
972
  for (let i = 0, len = merged.length; i < len; i++) {
958
- result += `${getAssignmentExpression(merged[i])},`;
973
+ result += getAssignmentExpression(merged[i]) + ",";
959
974
  }
960
975
  return result;
961
976
  }
@@ -992,298 +1007,301 @@ function createMapSet(ctx, ref, key, value) {
992
1007
  }
993
1008
  function createArrayAssign(ctx, ref, index, value) {
994
1009
  markRef(ctx, ref);
995
- createAssignment(ctx, `${getRefParam(ctx, ref)}[${index}]`, value);
1010
+ createAssignment(ctx, getRefParam(ctx, ref) + "[" + index.toString() + "]", value);
996
1011
  }
997
1012
  function createObjectAssign(ctx, ref, key, value) {
998
1013
  markRef(ctx, ref);
999
- createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
1014
+ createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
1015
+ }
1016
+ function assignRef(ctx, index, value) {
1017
+ if (ctx.markedRefs.has(index)) {
1018
+ return getRefParam(ctx, index) + "=" + value;
1019
+ }
1020
+ return value;
1021
+ }
1022
+ function isReferenceInStack(ctx, node) {
1023
+ return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
1000
1024
  }
1001
1025
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
1002
1026
  var SerovalSerializer = class {
1003
- constructor(ctx) {
1004
- __publicField(this, "ctx");
1005
- this.ctx = ctx;
1006
- }
1007
- assignRef(index, value) {
1008
- if (this.ctx.markedRefs.has(index)) {
1009
- return `${getRefParam(this.ctx, index)}=${value}`;
1010
- }
1011
- return value;
1012
- }
1013
- isReferenceInStack(node) {
1014
- return node.t === 2 /* Reference */ && this.ctx.stack.includes(node.i);
1015
- }
1016
- serializeNodeList(node) {
1027
+ static serializeNodeList(ctx, node) {
1017
1028
  const size = node.a.length;
1018
1029
  let values = "";
1030
+ let item;
1031
+ let isHoley = false;
1019
1032
  for (let i = 0; i < size; i++) {
1020
- const item = node.a[i];
1033
+ if (i !== 0) {
1034
+ values += ",";
1035
+ }
1036
+ item = node.a[i];
1021
1037
  if (item) {
1022
- if (this.isReferenceInStack(item)) {
1023
- createArrayAssign(this.ctx, node.i, i, getRefParam(this.ctx, item.i));
1024
- values += ",";
1038
+ if (isReferenceInStack(ctx, item)) {
1039
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
1040
+ isHoley = true;
1025
1041
  } else {
1026
- values += this.serialize(item);
1027
- if (i < size - 1) {
1028
- values += ",";
1029
- }
1042
+ values += this.serialize(ctx, item);
1043
+ isHoley = false;
1030
1044
  }
1031
1045
  } else {
1032
- values += ",";
1046
+ isHoley = true;
1033
1047
  }
1034
1048
  }
1035
- return `[${values}]`;
1049
+ if (isHoley) {
1050
+ values += ",";
1051
+ }
1052
+ return "[" + values + "]";
1036
1053
  }
1037
- serializeArray(node) {
1038
- this.ctx.stack.push(node.i);
1039
- const result = this.serializeNodeList(node);
1040
- this.ctx.stack.pop();
1041
- return this.assignRef(node.i, result);
1054
+ static serializeArray(ctx, node) {
1055
+ ctx.stack.push(node.i);
1056
+ const result = this.serializeNodeList(ctx, node);
1057
+ ctx.stack.pop();
1058
+ return assignRef(ctx, node.i, result);
1042
1059
  }
1043
- serializeObject(sourceID, node) {
1060
+ static serializeObject(ctx, sourceID, node) {
1044
1061
  if (node.s === 0) {
1045
1062
  return "{}";
1046
1063
  }
1047
1064
  let result = "";
1048
- this.ctx.stack.push(sourceID);
1065
+ ctx.stack.push(sourceID);
1066
+ let key;
1067
+ let val;
1068
+ let check;
1069
+ let isIdentifier;
1070
+ let refParam;
1071
+ let hasPrev = false;
1049
1072
  for (let i = 0; i < node.s; i++) {
1050
- const key = node.k[i];
1051
- const val = node.v[i];
1052
- const check = Number(key);
1053
- const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1054
- if (this.isReferenceInStack(val)) {
1055
- const refParam = getRefParam(this.ctx, val.i);
1073
+ key = node.k[i];
1074
+ val = node.v[i];
1075
+ check = Number(key);
1076
+ isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1077
+ if (isReferenceInStack(ctx, val)) {
1078
+ refParam = getRefParam(ctx, val.i);
1056
1079
  if (isIdentifier && Number.isNaN(check)) {
1057
- createObjectAssign(this.ctx, sourceID, key, refParam);
1080
+ createObjectAssign(ctx, sourceID, key, refParam);
1058
1081
  } else {
1059
- createArrayAssign(this.ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1082
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1060
1083
  }
1061
1084
  } else {
1062
- result += `${isIdentifier ? key : quote(key)}:${this.serialize(val)},`;
1085
+ if (hasPrev) {
1086
+ result += ",";
1087
+ }
1088
+ result += isIdentifier ? key : quote(key);
1089
+ result += ":" + this.serialize(ctx, val);
1090
+ hasPrev = true;
1063
1091
  }
1064
1092
  }
1065
- this.ctx.stack.pop();
1066
- return `{${result.substring(0, result.length - 1)}}`;
1093
+ ctx.stack.pop();
1094
+ return "{" + result + "}";
1067
1095
  }
1068
- serializeWithObjectAssign(value, id, serialized) {
1069
- const fields = this.serializeObject(id, value);
1096
+ static serializeWithObjectAssign(ctx, value, id, serialized) {
1097
+ const fields = this.serializeObject(ctx, id, value);
1070
1098
  if (fields !== "{}") {
1071
- return `Object.assign(${serialized},${fields})`;
1099
+ return "Object.assign(" + serialized + "," + fields + ")";
1072
1100
  }
1073
1101
  return serialized;
1074
1102
  }
1075
- serializeAssignments(sourceID, node) {
1076
- this.ctx.stack.push(sourceID);
1103
+ static serializeAssignments(ctx, sourceID, node) {
1104
+ ctx.stack.push(sourceID);
1077
1105
  const mainAssignments = [];
1106
+ let parentStack;
1107
+ let refParam;
1108
+ let key;
1109
+ let check;
1110
+ let parentAssignment;
1111
+ let isIdentifier;
1078
1112
  for (let i = 0; i < node.s; i++) {
1079
- const parentStack = this.ctx.stack;
1080
- this.ctx.stack = [];
1081
- const refParam = this.serialize(node.v[i]);
1082
- this.ctx.stack = parentStack;
1083
- const key = node.k[i];
1084
- const check = Number(key);
1085
- const parentAssignment = this.ctx.assignments;
1086
- this.ctx.assignments = mainAssignments;
1087
- const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1113
+ parentStack = ctx.stack;
1114
+ ctx.stack = [];
1115
+ refParam = this.serialize(ctx, node.v[i]);
1116
+ ctx.stack = parentStack;
1117
+ key = node.k[i];
1118
+ check = Number(key);
1119
+ parentAssignment = ctx.assignments;
1120
+ ctx.assignments = mainAssignments;
1121
+ isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1088
1122
  if (isIdentifier && Number.isNaN(check)) {
1089
- createObjectAssign(this.ctx, sourceID, key, refParam);
1123
+ createObjectAssign(ctx, sourceID, key, refParam);
1090
1124
  } else {
1091
- createArrayAssign(this.ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1125
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1092
1126
  }
1093
- this.ctx.assignments = parentAssignment;
1127
+ ctx.assignments = parentAssignment;
1094
1128
  }
1095
- this.ctx.stack.pop();
1129
+ ctx.stack.pop();
1096
1130
  return resolveAssignments(mainAssignments);
1097
1131
  }
1098
- serializeNullConstructor(node) {
1099
- let serialized = "Object.create(null)";
1100
- if (this.ctx.features & 64 /* ObjectAssign */) {
1101
- serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
1102
- } else {
1103
- markRef(this.ctx, node.i);
1104
- const assignments = this.serializeAssignments(node.i, node.d);
1105
- if (assignments) {
1106
- const ref = getRefParam(this.ctx, node.i);
1107
- return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
1132
+ static serializeDictionary(ctx, i, d, init) {
1133
+ if (d) {
1134
+ if (ctx.features & 64 /* ObjectAssign */) {
1135
+ init = this.serializeWithObjectAssign(ctx, d, i, init);
1136
+ } else {
1137
+ markRef(ctx, i);
1138
+ const assignments = this.serializeAssignments(ctx, i, d);
1139
+ if (assignments) {
1140
+ const ref = getRefParam(ctx, i);
1141
+ return "(" + assignRef(ctx, i, init) + "," + assignments + ref + ")";
1142
+ }
1108
1143
  }
1109
1144
  }
1110
- return this.assignRef(node.i, serialized);
1145
+ return assignRef(ctx, i, init);
1111
1146
  }
1112
- serializeSet(node) {
1147
+ static serializeNullConstructor(ctx, node) {
1148
+ return this.serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
1149
+ }
1150
+ static serializeSet(ctx, node) {
1113
1151
  let serialized = "new Set";
1114
1152
  const size = node.a.length;
1115
1153
  if (size) {
1116
1154
  let result = "";
1117
- this.ctx.stack.push(node.i);
1155
+ ctx.stack.push(node.i);
1156
+ let item;
1157
+ let hasPrev = false;
1118
1158
  for (let i = 0; i < size; i++) {
1119
- const item = node.a[i];
1120
- if (this.isReferenceInStack(item)) {
1121
- createSetAdd(this.ctx, node.i, getRefParam(this.ctx, item.i));
1159
+ item = node.a[i];
1160
+ if (isReferenceInStack(ctx, item)) {
1161
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
1122
1162
  } else {
1123
- result += `${this.serialize(item)},`;
1163
+ if (hasPrev) {
1164
+ result += ",";
1165
+ }
1166
+ result += this.serialize(ctx, item);
1167
+ hasPrev = true;
1124
1168
  }
1125
1169
  }
1126
- this.ctx.stack.pop();
1170
+ ctx.stack.pop();
1127
1171
  if (result) {
1128
- serialized += `([${result.substring(0, result.length - 1)}])`;
1172
+ serialized += "([" + result + "])";
1129
1173
  }
1130
1174
  }
1131
- return this.assignRef(node.i, serialized);
1175
+ return assignRef(ctx, node.i, serialized);
1132
1176
  }
1133
- serializeMap(node) {
1177
+ static serializeMap(ctx, node) {
1134
1178
  let serialized = "new Map";
1135
1179
  if (node.d.s) {
1136
1180
  let result = "";
1137
- this.ctx.stack.push(node.i);
1181
+ ctx.stack.push(node.i);
1182
+ let key;
1183
+ let val;
1184
+ let keyRef;
1185
+ let valueRef;
1186
+ let parent;
1187
+ let hasPrev = false;
1138
1188
  for (let i = 0; i < node.d.s; i++) {
1139
- const key = node.d.k[i];
1140
- const val = node.d.v[i];
1141
- if (this.isReferenceInStack(key)) {
1142
- const keyRef = getRefParam(this.ctx, key.i);
1143
- if (this.isReferenceInStack(val)) {
1144
- const valueRef = getRefParam(this.ctx, val.i);
1145
- createMapSet(this.ctx, node.i, keyRef, valueRef);
1189
+ key = node.d.k[i];
1190
+ val = node.d.v[i];
1191
+ if (isReferenceInStack(ctx, key)) {
1192
+ keyRef = getRefParam(ctx, key.i);
1193
+ if (isReferenceInStack(ctx, val)) {
1194
+ valueRef = getRefParam(ctx, val.i);
1195
+ createMapSet(ctx, node.i, keyRef, valueRef);
1146
1196
  } else {
1147
- const parent = this.ctx.stack;
1148
- this.ctx.stack = [];
1149
- createMapSet(this.ctx, node.i, keyRef, this.serialize(val));
1150
- this.ctx.stack = parent;
1197
+ parent = ctx.stack;
1198
+ ctx.stack = [];
1199
+ createMapSet(ctx, node.i, keyRef, this.serialize(ctx, val));
1200
+ ctx.stack = parent;
1151
1201
  }
1152
- } else if (this.isReferenceInStack(val)) {
1153
- const valueRef = getRefParam(this.ctx, val.i);
1154
- const parent = this.ctx.stack;
1155
- this.ctx.stack = [];
1156
- createMapSet(this.ctx, node.i, this.serialize(key), valueRef);
1157
- this.ctx.stack = parent;
1202
+ } else if (isReferenceInStack(ctx, val)) {
1203
+ valueRef = getRefParam(ctx, val.i);
1204
+ parent = ctx.stack;
1205
+ ctx.stack = [];
1206
+ createMapSet(ctx, node.i, this.serialize(ctx, key), valueRef);
1207
+ ctx.stack = parent;
1158
1208
  } else {
1159
- result += `[${this.serialize(key)},${this.serialize(val)}],`;
1209
+ if (hasPrev) {
1210
+ result += ",";
1211
+ }
1212
+ result += "[" + this.serialize(ctx, key) + "," + this.serialize(ctx, val) + "]";
1213
+ hasPrev = true;
1160
1214
  }
1161
1215
  }
1162
- this.ctx.stack.pop();
1216
+ ctx.stack.pop();
1163
1217
  if (result) {
1164
- serialized += `([${result.substring(0, result.length - 1)}])`;
1165
- }
1166
- }
1167
- return this.assignRef(node.i, serialized);
1168
- }
1169
- serializeAggregateError(node) {
1170
- this.ctx.stack.push(node.i);
1171
- let serialized = `new AggregateError(${this.serialize(node.n)},${quote(node.m)})`;
1172
- this.ctx.stack.pop();
1173
- if (node.d) {
1174
- if (this.ctx.features & 64 /* ObjectAssign */) {
1175
- serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
1176
- } else {
1177
- markRef(this.ctx, node.i);
1178
- const assignments = this.serializeAssignments(node.i, node.d);
1179
- if (assignments) {
1180
- const ref = getRefParam(this.ctx, node.i);
1181
- return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
1182
- }
1218
+ serialized += "([" + result + "])";
1183
1219
  }
1184
1220
  }
1185
- return this.assignRef(node.i, serialized);
1221
+ return assignRef(ctx, node.i, serialized);
1186
1222
  }
1187
- serializeError(node) {
1188
- let serialized = `new ${node.c}(${quote(node.m)})`;
1189
- if (node.d) {
1190
- if (this.ctx.features & 64 /* ObjectAssign */) {
1191
- serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
1192
- } else {
1193
- markRef(this.ctx, node.i);
1194
- const assignments = this.serializeAssignments(node.i, node.d);
1195
- if (assignments) {
1196
- const ref = getRefParam(this.ctx, node.i);
1197
- return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
1198
- }
1199
- }
1200
- }
1201
- return this.assignRef(node.i, serialized);
1223
+ static serializeAggregateError(ctx, node) {
1224
+ ctx.stack.push(node.i);
1225
+ const serialized = "new AggregateError(" + this.serialize(ctx, node.n) + "," + quote(node.m) + ")";
1226
+ ctx.stack.pop();
1227
+ return this.serializeDictionary(ctx, node.i, node.d, serialized);
1228
+ }
1229
+ static serializeError(ctx, node) {
1230
+ const serialized = "new " + node.c + "(" + quote(node.m) + ")";
1231
+ return this.serializeDictionary(ctx, node.i, node.d, serialized);
1202
1232
  }
1203
- serializePromise(node) {
1233
+ static serializePromise(ctx, node) {
1204
1234
  let serialized;
1205
- if (this.isReferenceInStack(node.n)) {
1206
- serialized = `Promise.resolve().then(()=>${getRefParam(this.ctx, node.n.i)})`;
1235
+ if (isReferenceInStack(ctx, node.n)) {
1236
+ serialized = "Promise.resolve().then(()=>" + getRefParam(ctx, node.n.i) + ")";
1207
1237
  } else {
1208
- this.ctx.stack.push(node.i);
1209
- const result = this.serialize(node.n);
1210
- this.ctx.stack.pop();
1211
- serialized = `Promise.resolve(${result})`;
1238
+ ctx.stack.push(node.i);
1239
+ const result = this.serialize(ctx, node.n);
1240
+ ctx.stack.pop();
1241
+ serialized = "Promise.resolve(" + result + ")";
1212
1242
  }
1213
- return this.assignRef(node.i, serialized);
1243
+ return assignRef(ctx, node.i, serialized);
1214
1244
  }
1215
- serializeTypedArray(node) {
1216
- let args = `[${node.s}]`;
1245
+ static serializeTypedArray(ctx, node) {
1246
+ let args = "[" + node.s + "]";
1217
1247
  if (node.l !== 0) {
1218
- args += `,${node.l}`;
1248
+ args += "," + node.l.toString();
1219
1249
  }
1220
- return this.assignRef(node.i, `new ${node.c}(${args})`);
1221
- }
1222
- serializeIterable(node) {
1223
- const parent = this.ctx.stack;
1224
- this.ctx.stack = [];
1225
- const values = this.serializeNodeList(node);
1226
- this.ctx.stack = parent;
1227
- let serialized;
1228
- if (this.ctx.features & 2 /* ArrayPrototypeValues */) {
1229
- serialized = `${values}.values()`;
1250
+ return assignRef(ctx, node.i, "new " + node.c + "(" + args + ")");
1251
+ }
1252
+ static serializeIterable(ctx, node) {
1253
+ const parent = ctx.stack;
1254
+ ctx.stack = [];
1255
+ const values = this.serializeNodeList(ctx, node);
1256
+ ctx.stack = parent;
1257
+ let serialized = values;
1258
+ if (ctx.features & 2 /* ArrayPrototypeValues */) {
1259
+ serialized += ".values()";
1230
1260
  } else {
1231
- serialized = `${values}[Symbol.iterator]()`;
1261
+ serialized += "[Symbol.iterator]()";
1232
1262
  }
1233
- if (this.ctx.features & 4 /* ArrowFunction */) {
1234
- serialized = `{[Symbol.iterator]:()=>${serialized}}`;
1235
- } else if (this.ctx.features & 32 /* MethodShorthand */) {
1236
- serialized = `{[Symbol.iterator](){return ${serialized}}}`;
1263
+ if (ctx.features & 4 /* ArrowFunction */) {
1264
+ serialized = "{[Symbol.iterator]:()=>" + serialized + "}";
1265
+ } else if (ctx.features & 32 /* MethodShorthand */) {
1266
+ serialized = "{[Symbol.iterator](){return " + serialized + "}}";
1237
1267
  } else {
1238
- serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
1239
- }
1240
- if (node.d) {
1241
- if (this.ctx.features & 64 /* ObjectAssign */) {
1242
- serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
1243
- } else {
1244
- markRef(this.ctx, node.i);
1245
- const assignments = this.serializeAssignments(node.i, node.d);
1246
- if (assignments) {
1247
- const ref = getRefParam(this.ctx, node.i);
1248
- return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
1249
- }
1250
- }
1268
+ serialized = "{[Symbol.iterator]:function(){return " + serialized + "}}";
1251
1269
  }
1252
- return this.assignRef(node.i, serialized);
1270
+ return this.serializeDictionary(ctx, node.i, node.d, serialized);
1253
1271
  }
1254
- serialize(node) {
1272
+ static serialize(ctx, node) {
1255
1273
  switch (node.t) {
1256
1274
  case 0 /* Primitive */:
1257
1275
  return String(node.s);
1258
1276
  case 1 /* BigInt */:
1259
1277
  return node.s;
1260
1278
  case 2 /* Reference */:
1261
- return getRefParam(this.ctx, node.i);
1279
+ return getRefParam(ctx, node.i);
1262
1280
  case 7 /* Array */:
1263
- return this.serializeArray(node);
1281
+ return this.serializeArray(ctx, node);
1264
1282
  case 8 /* Object */:
1265
- return this.assignRef(node.i, this.serializeObject(node.i, node.d));
1283
+ return assignRef(ctx, node.i, this.serializeObject(ctx, node.i, node.d));
1266
1284
  case 9 /* NullConstructor */:
1267
- return this.serializeNullConstructor(node);
1285
+ return this.serializeNullConstructor(ctx, node);
1268
1286
  case 3 /* Date */:
1269
- return this.assignRef(node.i, `new Date("${node.s}")`);
1287
+ return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
1270
1288
  case 4 /* RegExp */:
1271
- return this.assignRef(node.i, node.s);
1289
+ return assignRef(ctx, node.i, node.s);
1272
1290
  case 5 /* Set */:
1273
- return this.serializeSet(node);
1291
+ return this.serializeSet(ctx, node);
1274
1292
  case 6 /* Map */:
1275
- return this.serializeMap(node);
1293
+ return this.serializeMap(ctx, node);
1276
1294
  case 15 /* BigIntTypedArray */:
1277
1295
  case 14 /* TypedArray */:
1278
- return this.serializeTypedArray(node);
1296
+ return this.serializeTypedArray(ctx, node);
1279
1297
  case 12 /* AggregateError */:
1280
- return this.serializeAggregateError(node);
1298
+ return this.serializeAggregateError(ctx, node);
1281
1299
  case 11 /* Error */:
1282
- return this.serializeError(node);
1300
+ return this.serializeError(ctx, node);
1283
1301
  case 13 /* Iterable */:
1284
- return this.serializeIterable(node);
1302
+ return this.serializeIterable(ctx, node);
1285
1303
  case 10 /* Promise */:
1286
- return this.serializePromise(node);
1304
+ return this.serializePromise(ctx, node);
1287
1305
  default:
1288
1306
  throw new Error("Unsupported type");
1289
1307
  }
@@ -1292,11 +1310,7 @@ var SerovalSerializer = class {
1292
1310
 
1293
1311
  // src/tree/sync.ts
1294
1312
  var SyncParser = class {
1295
- constructor(ctx) {
1296
- __publicField(this, "ctx");
1297
- this.ctx = ctx;
1298
- }
1299
- generateNodeList(current) {
1313
+ static generateNodeList(ctx, current) {
1300
1314
  const size = current.length;
1301
1315
  const nodes = new Array(size);
1302
1316
  const deferred = new Array(size);
@@ -1307,18 +1321,18 @@ var SyncParser = class {
1307
1321
  if (isIterable(item)) {
1308
1322
  deferred[i] = item;
1309
1323
  } else {
1310
- nodes[i] = this.parse(item);
1324
+ nodes[i] = this.parse(ctx, item);
1311
1325
  }
1312
1326
  }
1313
1327
  }
1314
1328
  for (let i = 0; i < size; i++) {
1315
1329
  if (i in deferred) {
1316
- nodes[i] = this.parse(deferred[i]);
1330
+ nodes[i] = this.parse(ctx, deferred[i]);
1317
1331
  }
1318
1332
  }
1319
1333
  return nodes;
1320
1334
  }
1321
- generateArrayNode(id, current) {
1335
+ static generateArrayNode(ctx, id, current) {
1322
1336
  return {
1323
1337
  t: 7 /* Array */,
1324
1338
  i: id,
@@ -1327,12 +1341,12 @@ var SyncParser = class {
1327
1341
  c: void 0,
1328
1342
  m: void 0,
1329
1343
  d: void 0,
1330
- a: this.generateNodeList(current),
1344
+ a: this.generateNodeList(ctx, current),
1331
1345
  n: void 0
1332
1346
  };
1333
1347
  }
1334
- generateMapNode(id, current) {
1335
- assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
1348
+ static generateMapNode(ctx, id, current) {
1349
+ assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
1336
1350
  const len = current.size;
1337
1351
  const keyNodes = new Array(len);
1338
1352
  const valueNodes = new Array(len);
@@ -1346,14 +1360,14 @@ var SyncParser = class {
1346
1360
  deferredValue[deferredSize] = value;
1347
1361
  deferredSize++;
1348
1362
  } else {
1349
- keyNodes[nodeSize] = this.parse(key);
1350
- valueNodes[nodeSize] = this.parse(value);
1363
+ keyNodes[nodeSize] = this.parse(ctx, key);
1364
+ valueNodes[nodeSize] = this.parse(ctx, value);
1351
1365
  nodeSize++;
1352
1366
  }
1353
1367
  }
1354
1368
  for (let i = 0; i < deferredSize; i++) {
1355
- keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
1356
- valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
1369
+ keyNodes[nodeSize + i] = this.parse(ctx, deferredKey[i]);
1370
+ valueNodes[nodeSize + i] = this.parse(ctx, deferredValue[i]);
1357
1371
  }
1358
1372
  return {
1359
1373
  t: 6 /* Map */,
@@ -1367,8 +1381,8 @@ var SyncParser = class {
1367
1381
  n: void 0
1368
1382
  };
1369
1383
  }
1370
- generateSetNode(id, current) {
1371
- assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
1384
+ static generateSetNode(ctx, id, current) {
1385
+ assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
1372
1386
  const len = current.size;
1373
1387
  const nodes = new Array(len);
1374
1388
  const deferred = new Array(len);
@@ -1378,11 +1392,11 @@ var SyncParser = class {
1378
1392
  if (isIterable(item)) {
1379
1393
  deferred[deferredSize++] = item;
1380
1394
  } else {
1381
- nodes[nodeSize++] = this.parse(item);
1395
+ nodes[nodeSize++] = this.parse(ctx, item);
1382
1396
  }
1383
1397
  }
1384
1398
  for (let i = 0; i < deferredSize; i++) {
1385
- nodes[nodeSize + i] = this.parse(deferred[i]);
1399
+ nodes[nodeSize + i] = this.parse(ctx, deferred[i]);
1386
1400
  }
1387
1401
  return {
1388
1402
  t: 5 /* Set */,
@@ -1396,7 +1410,7 @@ var SyncParser = class {
1396
1410
  n: void 0
1397
1411
  };
1398
1412
  }
1399
- generateProperties(properties) {
1413
+ static generateProperties(ctx, properties) {
1400
1414
  const keys = Object.keys(properties);
1401
1415
  const size = keys.length;
1402
1416
  const keyNodes = new Array(size);
@@ -1414,13 +1428,13 @@ var SyncParser = class {
1414
1428
  deferredSize++;
1415
1429
  } else {
1416
1430
  keyNodes[nodesSize] = key;
1417
- valueNodes[nodesSize] = this.parse(item);
1431
+ valueNodes[nodesSize] = this.parse(ctx, item);
1418
1432
  nodesSize++;
1419
1433
  }
1420
1434
  }
1421
1435
  for (let i = 0; i < deferredSize; i++) {
1422
1436
  keyNodes[nodesSize + i] = deferredKeys[i];
1423
- valueNodes[nodesSize + i] = this.parse(deferredValues[i]);
1437
+ valueNodes[nodesSize + i] = this.parse(ctx, deferredValues[i]);
1424
1438
  }
1425
1439
  return {
1426
1440
  k: keyNodes,
@@ -1428,8 +1442,8 @@ var SyncParser = class {
1428
1442
  s: size
1429
1443
  };
1430
1444
  }
1431
- generateIterableNode(id, current) {
1432
- assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1445
+ static generateIterableNode(ctx, id, current) {
1446
+ assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1433
1447
  const options = getIterableOptions(current);
1434
1448
  return {
1435
1449
  t: 13 /* Iterable */,
@@ -1439,14 +1453,14 @@ var SyncParser = class {
1439
1453
  c: void 0,
1440
1454
  m: void 0,
1441
1455
  // Parse options first before the items
1442
- d: options ? this.generateProperties(options) : void 0,
1443
- a: this.generateNodeList(Array.from(current)),
1456
+ d: options ? this.generateProperties(ctx, options) : void 0,
1457
+ a: this.generateNodeList(ctx, Array.from(current)),
1444
1458
  n: void 0
1445
1459
  };
1446
1460
  }
1447
- generateObjectNode(id, current, empty) {
1461
+ static generateObjectNode(ctx, id, current, empty) {
1448
1462
  if (Symbol.iterator in current) {
1449
- return this.generateIterableNode(id, current);
1463
+ return this.generateIterableNode(ctx, id, current);
1450
1464
  }
1451
1465
  return {
1452
1466
  t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
@@ -1455,14 +1469,14 @@ var SyncParser = class {
1455
1469
  l: void 0,
1456
1470
  c: void 0,
1457
1471
  m: void 0,
1458
- d: this.generateProperties(current),
1472
+ d: this.generateProperties(ctx, current),
1459
1473
  a: void 0,
1460
1474
  n: void 0
1461
1475
  };
1462
1476
  }
1463
- generateAggregateErrorNode(id, current) {
1477
+ static generateAggregateErrorNode(ctx, id, current) {
1464
1478
  const options = getErrorOptions(current);
1465
- const optionsNode = options ? this.generateProperties(options) : void 0;
1479
+ const optionsNode = options ? this.generateProperties(ctx, options) : void 0;
1466
1480
  return {
1467
1481
  t: 12 /* AggregateError */,
1468
1482
  i: id,
@@ -1472,12 +1486,12 @@ var SyncParser = class {
1472
1486
  m: current.message,
1473
1487
  d: optionsNode,
1474
1488
  a: void 0,
1475
- n: this.parse(current.errors)
1489
+ n: this.parse(ctx, current.errors)
1476
1490
  };
1477
1491
  }
1478
- generateErrorNode(id, current) {
1492
+ static generateErrorNode(ctx, id, current) {
1479
1493
  const options = getErrorOptions(current);
1480
- const optionsNode = options ? this.generateProperties(options) : void 0;
1494
+ const optionsNode = options ? this.generateProperties(ctx, options) : void 0;
1481
1495
  return {
1482
1496
  t: 11 /* Error */,
1483
1497
  i: id,
@@ -1490,7 +1504,7 @@ var SyncParser = class {
1490
1504
  n: void 0
1491
1505
  };
1492
1506
  }
1493
- parse(current) {
1507
+ static parse(ctx, current) {
1494
1508
  switch (typeof current) {
1495
1509
  case "boolean":
1496
1510
  return current ? TRUE_NODE : FALSE_NODE;
@@ -1510,17 +1524,17 @@ var SyncParser = class {
1510
1524
  }
1511
1525
  return createPrimitiveNode(current);
1512
1526
  case "bigint":
1513
- return createBigIntNode(this.ctx, current);
1527
+ return createBigIntNode(ctx, current);
1514
1528
  case "object": {
1515
1529
  if (!current) {
1516
1530
  return NULL_NODE;
1517
1531
  }
1518
- const id = createRef(this.ctx, current, true);
1519
- if (this.ctx.markedRefs.has(id)) {
1532
+ const id = createRef(ctx, current, true);
1533
+ if (ctx.markedRefs.has(id)) {
1520
1534
  return createReferenceNode(id);
1521
1535
  }
1522
1536
  if (Array.isArray(current)) {
1523
- return this.generateArrayNode(id, current);
1537
+ return this.generateArrayNode(ctx, id, current);
1524
1538
  }
1525
1539
  switch (current.constructor) {
1526
1540
  case Date:
@@ -1536,23 +1550,23 @@ var SyncParser = class {
1536
1550
  case Uint8ClampedArray:
1537
1551
  case Float32Array:
1538
1552
  case Float64Array:
1539
- return createTypedArrayNode(this.ctx, id, current);
1553
+ return createTypedArrayNode(ctx, id, current);
1540
1554
  case BigInt64Array:
1541
1555
  case BigUint64Array:
1542
- return createBigIntTypedArrayNode(this.ctx, id, current);
1556
+ return createBigIntTypedArrayNode(ctx, id, current);
1543
1557
  case Map:
1544
- return this.generateMapNode(id, current);
1558
+ return this.generateMapNode(ctx, id, current);
1545
1559
  case Set:
1546
- return this.generateSetNode(id, current);
1560
+ return this.generateSetNode(ctx, id, current);
1547
1561
  case Object:
1548
- return this.generateObjectNode(id, current, false);
1562
+ return this.generateObjectNode(ctx, id, current, false);
1549
1563
  case void 0:
1550
- return this.generateObjectNode(id, current, true);
1564
+ return this.generateObjectNode(ctx, id, current, true);
1551
1565
  case AggregateError:
1552
- if (this.ctx.features & 1 /* AggregateError */) {
1553
- return this.generateAggregateErrorNode(id, current);
1566
+ if (ctx.features & 1 /* AggregateError */) {
1567
+ return this.generateAggregateErrorNode(ctx, id, current);
1554
1568
  }
1555
- return this.generateErrorNode(id, current);
1569
+ return this.generateErrorNode(ctx, id, current);
1556
1570
  case Error:
1557
1571
  case EvalError:
1558
1572
  case RangeError:
@@ -1560,18 +1574,18 @@ var SyncParser = class {
1560
1574
  case SyntaxError:
1561
1575
  case TypeError:
1562
1576
  case URIError:
1563
- return this.generateErrorNode(id, current);
1577
+ return this.generateErrorNode(ctx, id, current);
1564
1578
  default:
1565
1579
  break;
1566
1580
  }
1567
- if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
1568
- return this.generateAggregateErrorNode(id, current);
1581
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1582
+ return this.generateAggregateErrorNode(ctx, id, current);
1569
1583
  }
1570
1584
  if (current instanceof Error) {
1571
- return this.generateErrorNode(id, current);
1585
+ return this.generateErrorNode(ctx, id, current);
1572
1586
  }
1573
1587
  if (Symbol.iterator in current) {
1574
- return this.generateIterableNode(id, current);
1588
+ return this.generateIterableNode(ctx, id, current);
1575
1589
  }
1576
1590
  throw new Error("Unsupported type");
1577
1591
  }
@@ -1581,7 +1595,7 @@ var SyncParser = class {
1581
1595
  }
1582
1596
  };
1583
1597
  function parseSync(ctx, current) {
1584
- const result = new SyncParser(ctx).parse(current);
1598
+ const result = SyncParser.parse(ctx, current);
1585
1599
  const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
1586
1600
  return [result, createRef(ctx, current, false), isObject];
1587
1601
  }
@@ -1593,21 +1607,20 @@ function finalize(ctx, rootID, isObject, result) {
1593
1607
  let body = result;
1594
1608
  if (patches) {
1595
1609
  const index = getRefParam(ctx, rootID);
1596
- if (result.startsWith(`${index}=`)) {
1597
- body = `${result},${patches}${index}`;
1598
- } else {
1599
- body = `${index}=${result},${patches}${index}`;
1610
+ body = result + "," + patches + index;
1611
+ if (!result.startsWith(index + "=")) {
1612
+ body = index + "=" + body;
1600
1613
  }
1601
1614
  }
1602
1615
  let params = ctx.vars.length > 1 ? ctx.vars.join(",") : ctx.vars[0];
1603
1616
  if (ctx.features & 4 /* ArrowFunction */) {
1604
- params = ctx.vars.length > 1 || ctx.vars.length === 0 ? `(${params})` : params;
1605
- return `(${params}=>(${body}))()`;
1617
+ params = ctx.vars.length > 1 || ctx.vars.length === 0 ? "(" + params + ")" : params;
1618
+ return "(" + params + "=>(" + body + "))()";
1606
1619
  }
1607
- return `(function(${params}){return ${body}})()`;
1620
+ return "(function(" + params + "){return " + body + "})()";
1608
1621
  }
1609
1622
  if (isObject) {
1610
- return `(${result})`;
1623
+ return "(" + result + ")";
1611
1624
  }
1612
1625
  return result;
1613
1626
  }
@@ -1615,14 +1628,14 @@ function serialize(source, options) {
1615
1628
  const ctx = createParserContext(options);
1616
1629
  const [tree, rootID, isObject] = parseSync(ctx, source);
1617
1630
  const serial = createSerializationContext(ctx);
1618
- const result = new SerovalSerializer(serial).serialize(tree);
1631
+ const result = SerovalSerializer.serialize(serial, tree);
1619
1632
  return finalize(serial, rootID, isObject, result);
1620
1633
  }
1621
1634
  async function serializeAsync(source, options) {
1622
1635
  const ctx = createParserContext(options);
1623
1636
  const [tree, rootID, isObject] = await parseAsync(ctx, source);
1624
1637
  const serial = createSerializationContext(ctx);
1625
- const result = new SerovalSerializer(serial).serialize(tree);
1638
+ const result = SerovalSerializer.serialize(serial, tree);
1626
1639
  return finalize(serial, rootID, isObject, result);
1627
1640
  }
1628
1641
  function deserialize(source) {
@@ -1656,7 +1669,7 @@ function compileJSON(source) {
1656
1669
  features: parsed.f,
1657
1670
  markedRefs: parsed.m
1658
1671
  });
1659
- const result = new SerovalSerializer(serial).serialize(parsed.t);
1672
+ const result = SerovalSerializer.serialize(serial, parsed.t);
1660
1673
  return finalize(serial, parsed.r, parsed.i, result);
1661
1674
  }
1662
1675
  function fromJSON(source) {