seroval 0.4.0-alpha.12 → 0.4.0-alpha.13

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.
@@ -280,25 +280,33 @@ function getIdentifier(index) {
280
280
  var DEFAULT_OPTIONS = {
281
281
  target: "es2023"
282
282
  };
283
- function createParserContext(options = {}) {
284
- const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
285
- return {
286
- markedRefs: {},
287
- refs: /* @__PURE__ */ new Map(),
288
- features: parseTargets(result.target)
289
- };
290
- }
291
- function createSerializationContext(options) {
292
- return {
293
- stack: [],
294
- vars: [],
295
- assignments: [],
296
- validRefs: [],
297
- refSize: 0,
298
- features: options.features,
299
- markedRefs: options.markedRefs
300
- };
301
- }
283
+ var ParserContext = class {
284
+ constructor(options = {}) {
285
+ __publicField(this, "refs", /* @__PURE__ */ new Map());
286
+ __publicField(this, "markedRefs", {});
287
+ __publicField(this, "features");
288
+ const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
289
+ this.features = parseTargets(result.target);
290
+ }
291
+ };
292
+ var SerializationContext = class {
293
+ constructor(options) {
294
+ __publicField(this, "stack", []);
295
+ // Map tree refs to actual refs
296
+ __publicField(this, "validRefs", []);
297
+ __publicField(this, "refSize", 0);
298
+ // Variables
299
+ __publicField(this, "vars", []);
300
+ // Array of assignments to be done (used for recursion)
301
+ __publicField(this, "assignments", []);
302
+ // Supported features
303
+ __publicField(this, "features");
304
+ // Refs that are...referenced
305
+ __publicField(this, "markedRefs");
306
+ this.features = options.features;
307
+ this.markedRefs = options.markedRefs;
308
+ }
309
+ };
302
310
  function markRef(ctx, current) {
303
311
  ctx.markedRefs[current] = 1;
304
312
  }
@@ -382,119 +390,198 @@ function quote(str) {
382
390
  return `"${result}"`;
383
391
  }
384
392
 
393
+ // src/tree/types.ts
394
+ var SerovalObjectRecordNode = class {
395
+ constructor(k, v, s) {
396
+ __publicField(this, "k");
397
+ __publicField(this, "v");
398
+ __publicField(this, "s");
399
+ this.k = k;
400
+ this.v = v;
401
+ this.s = s;
402
+ }
403
+ };
404
+ var SerovalMapRecordNode = class {
405
+ constructor(k, v, s) {
406
+ __publicField(this, "k");
407
+ __publicField(this, "v");
408
+ __publicField(this, "s");
409
+ this.k = k;
410
+ this.v = v;
411
+ this.s = s;
412
+ }
413
+ };
414
+ var SerovalPrimitiveNode = class {
415
+ constructor(current) {
416
+ __publicField(this, "t", 0 /* Primitive */);
417
+ __publicField(this, "s");
418
+ this.s = current;
419
+ }
420
+ };
421
+ var SerovalReferenceNode = class {
422
+ constructor(id) {
423
+ __publicField(this, "t", 2 /* Reference */);
424
+ __publicField(this, "i");
425
+ this.i = id;
426
+ }
427
+ };
428
+ var SerovalBigIntNode = class {
429
+ constructor(current) {
430
+ __publicField(this, "t", 1 /* BigInt */);
431
+ __publicField(this, "s");
432
+ this.s = `${current}n`;
433
+ }
434
+ };
435
+ var SerovalDateNode = class {
436
+ constructor(id, current) {
437
+ __publicField(this, "t", 3 /* Date */);
438
+ __publicField(this, "i");
439
+ __publicField(this, "s");
440
+ this.i = id;
441
+ this.s = current.toISOString();
442
+ }
443
+ };
444
+ var SerovalRegExpNode = class {
445
+ constructor(id, current) {
446
+ __publicField(this, "t", 4 /* RegExp */);
447
+ __publicField(this, "i");
448
+ __publicField(this, "s");
449
+ this.i = id;
450
+ this.s = String(current);
451
+ }
452
+ };
453
+ var SerovalTypedArrayNode = class {
454
+ constructor(id, current) {
455
+ __publicField(this, "t", 14 /* TypedArray */);
456
+ __publicField(this, "i");
457
+ __publicField(this, "s");
458
+ __publicField(this, "l");
459
+ __publicField(this, "c");
460
+ this.i = id;
461
+ this.s = current.toString();
462
+ this.l = current.byteOffset;
463
+ this.c = current.constructor.name;
464
+ }
465
+ };
466
+ var SerovalBigIntTypedArrayNode = class {
467
+ constructor(id, current) {
468
+ __publicField(this, "t", 15 /* BigIntTypedArray */);
469
+ __publicField(this, "i");
470
+ __publicField(this, "s");
471
+ __publicField(this, "l");
472
+ __publicField(this, "c");
473
+ let result = "";
474
+ const cap = current.length - 1;
475
+ for (let i = 0; i < cap; i++) {
476
+ result += `${current[i]}n,`;
477
+ }
478
+ result += `"${current[cap]}"`;
479
+ this.i = id;
480
+ this.s = result;
481
+ this.l = current.byteOffset;
482
+ this.c = current.constructor.name;
483
+ }
484
+ };
485
+ var SerovalSetNode = class {
486
+ constructor(id, a) {
487
+ __publicField(this, "t", 5 /* Set */);
488
+ __publicField(this, "i");
489
+ __publicField(this, "a");
490
+ this.i = id;
491
+ this.a = a;
492
+ }
493
+ };
494
+ var SerovalMapNode = class {
495
+ constructor(id, d) {
496
+ __publicField(this, "t", 6 /* Map */);
497
+ __publicField(this, "i");
498
+ __publicField(this, "d");
499
+ this.i = id;
500
+ this.d = d;
501
+ }
502
+ };
503
+ var SerovalArrayNode = class {
504
+ constructor(id, a) {
505
+ __publicField(this, "t", 7 /* Array */);
506
+ __publicField(this, "i");
507
+ __publicField(this, "a");
508
+ this.i = id;
509
+ this.a = a;
510
+ }
511
+ };
512
+ var SerovalObjectNode = class {
513
+ constructor(id, d) {
514
+ __publicField(this, "t", 8 /* Object */);
515
+ __publicField(this, "i");
516
+ __publicField(this, "d");
517
+ this.i = id;
518
+ this.d = d;
519
+ }
520
+ };
521
+ var SerovalNullConstructorNode = class {
522
+ constructor(id, d) {
523
+ __publicField(this, "t", 9 /* NullConstructor */);
524
+ __publicField(this, "i");
525
+ __publicField(this, "d");
526
+ this.i = id;
527
+ this.d = d;
528
+ }
529
+ };
530
+ var SerovalPromiseNode = class {
531
+ constructor(id, n) {
532
+ __publicField(this, "t", 10 /* Promise */);
533
+ __publicField(this, "i");
534
+ __publicField(this, "n");
535
+ this.i = id;
536
+ this.n = n;
537
+ }
538
+ };
539
+ var SerovalErrorNode = class {
540
+ constructor(id, c, m, d) {
541
+ __publicField(this, "t", 11 /* Error */);
542
+ __publicField(this, "i");
543
+ __publicField(this, "c");
544
+ __publicField(this, "m");
545
+ __publicField(this, "d");
546
+ this.i = id;
547
+ this.c = c;
548
+ this.m = m;
549
+ this.d = d;
550
+ }
551
+ };
552
+ var SerovalAggregateErrorNode = class {
553
+ constructor(id, m, d, n) {
554
+ __publicField(this, "t", 12 /* AggregateError */);
555
+ __publicField(this, "i");
556
+ __publicField(this, "m");
557
+ __publicField(this, "d");
558
+ __publicField(this, "n");
559
+ this.i = id;
560
+ this.m = m;
561
+ this.d = d;
562
+ this.n = n;
563
+ }
564
+ };
565
+ var SerovalIterableNode = class {
566
+ constructor(id, d, a) {
567
+ __publicField(this, "t", 13 /* Iterable */);
568
+ __publicField(this, "i");
569
+ __publicField(this, "d");
570
+ __publicField(this, "a");
571
+ this.i = id;
572
+ this.d = d;
573
+ this.a = a;
574
+ }
575
+ };
576
+
385
577
  // src/tree/primitives.ts
386
- function createPrimitiveNode(value) {
387
- return {
388
- t: 0 /* Primitive */,
389
- i: void 0,
390
- s: value,
391
- l: void 0,
392
- m: void 0,
393
- c: void 0,
394
- d: void 0,
395
- a: void 0,
396
- n: void 0
397
- };
398
- }
399
- var TRUE_NODE = createPrimitiveNode("!0");
400
- var FALSE_NODE = createPrimitiveNode("!1");
401
- var UNDEFINED_NODE = createPrimitiveNode("void 0");
402
- var NULL_NODE = createPrimitiveNode(null);
403
- var NEG_ZERO_NODE = createPrimitiveNode("-0");
404
- var INFINITY_NODE = createPrimitiveNode("1/0");
405
- var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
406
- function createBigIntNode(ctx, current) {
407
- assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
408
- return {
409
- t: 1 /* BigInt */,
410
- i: void 0,
411
- a: void 0,
412
- s: `${current}n`,
413
- l: void 0,
414
- m: void 0,
415
- c: void 0,
416
- d: void 0,
417
- n: void 0
418
- };
419
- }
420
- function createReferenceNode(id) {
421
- return {
422
- t: 2 /* Reference */,
423
- i: id,
424
- a: void 0,
425
- s: void 0,
426
- l: void 0,
427
- m: void 0,
428
- c: void 0,
429
- d: void 0,
430
- n: void 0
431
- };
432
- }
433
- function createDateNode(id, current) {
434
- return {
435
- t: 3 /* Date */,
436
- i: id,
437
- a: void 0,
438
- s: current.toISOString(),
439
- l: void 0,
440
- m: void 0,
441
- c: void 0,
442
- d: void 0,
443
- n: void 0
444
- };
445
- }
446
- function createRegExpNode(id, current) {
447
- return {
448
- t: 4 /* RegExp */,
449
- i: id,
450
- a: void 0,
451
- s: String(current),
452
- l: void 0,
453
- m: void 0,
454
- c: void 0,
455
- d: void 0,
456
- n: void 0
457
- };
458
- }
459
- function createTypedArrayNode(ctx, id, current) {
460
- const constructor = current.constructor.name;
461
- assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
462
- return {
463
- t: 14 /* TypedArray */,
464
- i: id,
465
- a: void 0,
466
- s: current.toString(),
467
- l: current.byteOffset,
468
- m: void 0,
469
- c: constructor,
470
- d: void 0,
471
- n: void 0
472
- };
473
- }
474
- function createBigIntTypedArrayNode(ctx, id, current) {
475
- const constructor = current.constructor.name;
476
- assert(
477
- ctx.features & 2048 /* BigIntTypedArray */,
478
- `Unsupported value type "${constructor}"`
479
- );
480
- let result = "";
481
- const cap = current.length - 1;
482
- for (let i = 0; i < cap; i++) {
483
- result += `${current[i]}n,`;
484
- }
485
- result += `"${current[cap]}"`;
486
- return {
487
- t: 15 /* BigIntTypedArray */,
488
- i: id,
489
- a: void 0,
490
- s: result,
491
- l: current.byteOffset,
492
- m: void 0,
493
- c: constructor,
494
- d: void 0,
495
- n: void 0
496
- };
497
- }
578
+ var TRUE_NODE = new SerovalPrimitiveNode("!0");
579
+ var FALSE_NODE = new SerovalPrimitiveNode("!1");
580
+ var UNDEFINED_NODE = new SerovalPrimitiveNode("void 0");
581
+ var NULL_NODE = new SerovalPrimitiveNode(null);
582
+ var NEG_ZERO_NODE = new SerovalPrimitiveNode("-0");
583
+ var INFINITY_NODE = new SerovalPrimitiveNode("1/0");
584
+ var NEG_INFINITY_NODE = new SerovalPrimitiveNode("-1/0");
498
585
 
499
586
  // src/tree/shared.ts
500
587
  function getErrorConstructor(error) {
@@ -606,17 +693,7 @@ var AsyncParser = class {
606
693
  return nodes;
607
694
  }
608
695
  async generateArrayNode(id, current) {
609
- return {
610
- t: 7 /* Array */,
611
- i: id,
612
- a: await this.generateNodeList(current),
613
- s: void 0,
614
- l: void 0,
615
- m: void 0,
616
- c: void 0,
617
- d: void 0,
618
- n: void 0
619
- };
696
+ return new SerovalArrayNode(id, await this.generateNodeList(current));
620
697
  }
621
698
  async generateMapNode(id, current) {
622
699
  assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -642,17 +719,7 @@ var AsyncParser = class {
642
719
  keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
643
720
  valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
644
721
  }
645
- return {
646
- t: 6 /* Map */,
647
- i: id,
648
- a: void 0,
649
- s: void 0,
650
- l: void 0,
651
- m: void 0,
652
- c: void 0,
653
- d: { k: keyNodes, v: valueNodes, s: len },
654
- n: void 0
655
- };
722
+ return new SerovalMapNode(id, new SerovalMapRecordNode(keyNodes, valueNodes, len));
656
723
  }
657
724
  async generateSetNode(id, current) {
658
725
  assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -671,17 +738,7 @@ var AsyncParser = class {
671
738
  for (let i = 0; i < deferredSize; i++) {
672
739
  nodes[nodeSize + i] = await this.parse(deferred[i]);
673
740
  }
674
- return {
675
- t: 5 /* Set */,
676
- i: id,
677
- a: nodes,
678
- s: void 0,
679
- l: void 0,
680
- m: void 0,
681
- c: void 0,
682
- d: void 0,
683
- n: void 0
684
- };
741
+ return new SerovalSetNode(id, nodes);
685
742
  }
686
743
  async generateProperties(properties) {
687
744
  const keys = Object.keys(properties);
@@ -709,42 +766,21 @@ var AsyncParser = class {
709
766
  keyNodes[nodesSize + i] = deferredKeys[i];
710
767
  valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
711
768
  }
712
- return {
713
- k: keyNodes,
714
- v: valueNodes,
715
- s: size
716
- };
769
+ return new SerovalObjectRecordNode(keyNodes, valueNodes, size);
717
770
  }
718
771
  async generateIterableNode(id, current) {
719
772
  assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
720
773
  const options = getIterableOptions(current);
721
- return {
722
- t: 13 /* Iterable */,
723
- i: id,
724
- s: void 0,
725
- l: void 0,
726
- m: void 0,
727
- c: void 0,
774
+ return new SerovalIterableNode(
775
+ id,
728
776
  // Parse options first before the items
729
- d: options ? await this.generateProperties(options) : void 0,
730
- a: await this.generateNodeList(Array.from(current)),
731
- n: void 0
732
- };
777
+ options ? await this.generateProperties(options) : void 0,
778
+ await this.generateNodeList(Array.from(current))
779
+ );
733
780
  }
734
781
  async generatePromiseNode(id, current) {
735
782
  assert(this.ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
736
- return current.then(async (value) => ({
737
- t: 10 /* Promise */,
738
- i: id,
739
- s: void 0,
740
- l: void 0,
741
- m: void 0,
742
- c: void 0,
743
- // Parse options first before the items
744
- d: void 0,
745
- a: void 0,
746
- n: await this.parse(value)
747
- }));
783
+ return current.then(async (value) => new SerovalPromiseNode(id, await this.parse(value)));
748
784
  }
749
785
  async generateObjectNode(id, current, empty) {
750
786
  if (Symbol.iterator in current) {
@@ -753,47 +789,26 @@ var AsyncParser = class {
753
789
  if ("then" in current && typeof current.then === "function") {
754
790
  return this.generatePromiseNode(id, current);
755
791
  }
756
- return {
757
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
758
- i: id,
759
- s: void 0,
760
- l: void 0,
761
- m: void 0,
762
- c: void 0,
763
- d: await this.generateProperties(current),
764
- a: void 0,
765
- n: void 0
766
- };
792
+ const properties = await this.generateProperties(current);
793
+ if (empty) {
794
+ return new SerovalNullConstructorNode(id, properties);
795
+ }
796
+ return new SerovalObjectNode(id, properties);
767
797
  }
768
798
  async generateAggregateErrorNode(id, current) {
769
799
  const options = getErrorOptions(current);
770
800
  const optionsNode = options ? await this.generateProperties(options) : void 0;
771
- return {
772
- t: 12 /* AggregateError */,
773
- i: id,
774
- a: void 0,
775
- s: void 0,
776
- l: void 0,
777
- m: current.message,
778
- c: void 0,
779
- d: optionsNode,
780
- n: await this.parse(current.errors)
781
- };
801
+ return new SerovalAggregateErrorNode(
802
+ id,
803
+ current.message,
804
+ optionsNode,
805
+ await this.parse(current.errors)
806
+ );
782
807
  }
783
808
  async generateErrorNode(id, current) {
784
809
  const options = getErrorOptions(current);
785
810
  const optionsNode = options ? await this.generateProperties(options) : void 0;
786
- return {
787
- t: 11 /* Error */,
788
- i: id,
789
- a: void 0,
790
- s: void 0,
791
- l: void 0,
792
- m: current.message,
793
- c: getErrorConstructor(current),
794
- d: optionsNode,
795
- n: void 0
796
- };
811
+ return new SerovalErrorNode(id, getErrorConstructor(current), current.message, optionsNode);
797
812
  }
798
813
  async parse(current) {
799
814
  switch (typeof current) {
@@ -802,36 +817,37 @@ var AsyncParser = class {
802
817
  case "undefined":
803
818
  return UNDEFINED_NODE;
804
819
  case "string":
805
- return createPrimitiveNode(quote(current));
820
+ return new SerovalPrimitiveNode(quote(current));
806
821
  case "number":
807
822
  if (Object.is(current, -0)) {
808
823
  return NEG_ZERO_NODE;
809
824
  }
810
825
  if (Object.is(current, Infinity)) {
811
- return createPrimitiveNode("1/0");
826
+ return INFINITY_NODE;
812
827
  }
813
828
  if (Object.is(current, -Infinity)) {
814
- return createPrimitiveNode("-1/0");
829
+ return NEG_INFINITY_NODE;
815
830
  }
816
- return createPrimitiveNode(current);
831
+ return new SerovalPrimitiveNode(current);
817
832
  case "bigint":
818
- return createBigIntNode(this.ctx, current);
833
+ assert(this.ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
834
+ return new SerovalBigIntNode(current);
819
835
  case "object": {
820
836
  if (!current) {
821
837
  return NULL_NODE;
822
838
  }
823
839
  const id = createRef(this.ctx, current, true);
824
840
  if (this.ctx.markedRefs[id]) {
825
- return createReferenceNode(id);
841
+ return new SerovalReferenceNode(id);
826
842
  }
827
843
  if (Array.isArray(current)) {
828
844
  return this.generateArrayNode(id, current);
829
845
  }
830
846
  switch (current.constructor) {
831
847
  case Date:
832
- return createDateNode(id, current);
848
+ return new SerovalDateNode(id, current);
833
849
  case RegExp:
834
- return createRegExpNode(id, current);
850
+ return new SerovalRegExpNode(id, current);
835
851
  case Promise:
836
852
  return this.generatePromiseNode(id, current);
837
853
  case Int8Array:
@@ -843,10 +859,15 @@ var AsyncParser = class {
843
859
  case Uint8ClampedArray:
844
860
  case Float32Array:
845
861
  case Float64Array:
846
- return createTypedArrayNode(this.ctx, id, current);
862
+ assert(this.ctx.features & 1024 /* TypedArray */, `Unsupported value type "${current.constructor.name}"`);
863
+ return new SerovalTypedArrayNode(id, current);
847
864
  case BigInt64Array:
848
865
  case BigUint64Array:
849
- return createBigIntTypedArrayNode(this.ctx, id, current);
866
+ assert(
867
+ this.ctx.features & 2048 /* BigIntTypedArray */,
868
+ `Unsupported value type "${current.constructor.name}"`
869
+ );
870
+ return new SerovalBigIntTypedArrayNode(id, current);
850
871
  case Map:
851
872
  return this.generateMapNode(id, current);
852
873
  case Set:
@@ -1309,17 +1330,7 @@ var SyncParser = class {
1309
1330
  return nodes;
1310
1331
  }
1311
1332
  generateArrayNode(id, current) {
1312
- return {
1313
- t: 7 /* Array */,
1314
- i: id,
1315
- a: this.generateNodeList(current),
1316
- s: void 0,
1317
- l: void 0,
1318
- m: void 0,
1319
- c: void 0,
1320
- d: void 0,
1321
- n: void 0
1322
- };
1333
+ return new SerovalArrayNode(id, this.generateNodeList(current));
1323
1334
  }
1324
1335
  generateMapNode(id, current) {
1325
1336
  assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
@@ -1345,17 +1356,7 @@ var SyncParser = class {
1345
1356
  keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
1346
1357
  valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
1347
1358
  }
1348
- return {
1349
- t: 6 /* Map */,
1350
- i: id,
1351
- a: void 0,
1352
- s: void 0,
1353
- l: void 0,
1354
- m: void 0,
1355
- c: void 0,
1356
- d: { k: keyNodes, v: valueNodes, s: len },
1357
- n: void 0
1358
- };
1359
+ return new SerovalMapNode(id, new SerovalMapRecordNode(keyNodes, valueNodes, len));
1359
1360
  }
1360
1361
  generateSetNode(id, current) {
1361
1362
  assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
@@ -1374,17 +1375,7 @@ var SyncParser = class {
1374
1375
  for (let i = 0; i < deferredSize; i++) {
1375
1376
  nodes[nodeSize + i] = this.parse(deferred[i]);
1376
1377
  }
1377
- return {
1378
- t: 5 /* Set */,
1379
- i: id,
1380
- a: nodes,
1381
- s: void 0,
1382
- l: void 0,
1383
- m: void 0,
1384
- c: void 0,
1385
- d: void 0,
1386
- n: void 0
1387
- };
1378
+ return new SerovalSetNode(id, nodes);
1388
1379
  }
1389
1380
  generateProperties(properties) {
1390
1381
  const keys = Object.keys(properties);
@@ -1421,64 +1412,36 @@ var SyncParser = class {
1421
1412
  generateIterableNode(id, current) {
1422
1413
  assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
1423
1414
  const options = getIterableOptions(current);
1424
- return {
1425
- t: 13 /* Iterable */,
1426
- i: id,
1427
- s: void 0,
1428
- l: void 0,
1429
- m: void 0,
1430
- c: void 0,
1415
+ return new SerovalIterableNode(
1416
+ id,
1431
1417
  // Parse options first before the items
1432
- d: options ? this.generateProperties(options) : void 0,
1433
- a: this.generateNodeList(Array.from(current)),
1434
- n: void 0
1435
- };
1418
+ options ? this.generateProperties(options) : void 0,
1419
+ this.generateNodeList(Array.from(current))
1420
+ );
1436
1421
  }
1437
1422
  generateObjectNode(id, current, empty) {
1438
1423
  if (Symbol.iterator in current) {
1439
1424
  return this.generateIterableNode(id, current);
1440
1425
  }
1441
- return {
1442
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1443
- i: id,
1444
- s: void 0,
1445
- l: void 0,
1446
- m: void 0,
1447
- c: void 0,
1448
- d: this.generateProperties(current),
1449
- a: void 0,
1450
- n: void 0
1451
- };
1426
+ if (empty) {
1427
+ return new SerovalNullConstructorNode(id, this.generateProperties(current));
1428
+ }
1429
+ return new SerovalObjectNode(id, this.generateProperties(current));
1452
1430
  }
1453
1431
  generateAggregateErrorNode(id, current) {
1454
1432
  const options = getErrorOptions(current);
1455
1433
  const optionsNode = options ? this.generateProperties(options) : void 0;
1456
- return {
1457
- t: 12 /* AggregateError */,
1458
- i: id,
1459
- a: void 0,
1460
- s: void 0,
1461
- l: void 0,
1462
- m: current.message,
1463
- c: void 0,
1464
- d: optionsNode,
1465
- n: this.parse(current.errors)
1466
- };
1434
+ return new SerovalAggregateErrorNode(
1435
+ id,
1436
+ current.message,
1437
+ optionsNode,
1438
+ this.parse(current.errors)
1439
+ );
1467
1440
  }
1468
1441
  generateErrorNode(id, current) {
1469
1442
  const options = getErrorOptions(current);
1470
1443
  const optionsNode = options ? this.generateProperties(options) : void 0;
1471
- return {
1472
- t: 11 /* Error */,
1473
- i: id,
1474
- a: void 0,
1475
- s: void 0,
1476
- l: void 0,
1477
- m: current.message,
1478
- c: getErrorConstructor(current),
1479
- d: optionsNode,
1480
- n: void 0
1481
- };
1444
+ return new SerovalErrorNode(id, getErrorConstructor(current), current.message, optionsNode);
1482
1445
  }
1483
1446
  parse(current) {
1484
1447
  switch (typeof current) {
@@ -1487,36 +1450,37 @@ var SyncParser = class {
1487
1450
  case "undefined":
1488
1451
  return UNDEFINED_NODE;
1489
1452
  case "string":
1490
- return createPrimitiveNode(quote(current));
1453
+ return new SerovalPrimitiveNode(quote(current));
1491
1454
  case "number":
1492
1455
  if (Object.is(current, -0)) {
1493
1456
  return NEG_ZERO_NODE;
1494
1457
  }
1495
1458
  if (Object.is(current, Infinity)) {
1496
- return createPrimitiveNode("1/0");
1459
+ return INFINITY_NODE;
1497
1460
  }
1498
1461
  if (Object.is(current, -Infinity)) {
1499
- return createPrimitiveNode("-1/0");
1462
+ return NEG_INFINITY_NODE;
1500
1463
  }
1501
- return createPrimitiveNode(current);
1464
+ return new SerovalPrimitiveNode(current);
1502
1465
  case "bigint":
1503
- return createBigIntNode(this.ctx, current);
1466
+ assert(this.ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
1467
+ return new SerovalBigIntNode(current);
1504
1468
  case "object": {
1505
1469
  if (!current) {
1506
1470
  return NULL_NODE;
1507
1471
  }
1508
1472
  const id = createRef(this.ctx, current, true);
1509
1473
  if (this.ctx.markedRefs[id]) {
1510
- return createReferenceNode(id);
1474
+ return new SerovalReferenceNode(id);
1511
1475
  }
1512
1476
  if (Array.isArray(current)) {
1513
1477
  return this.generateArrayNode(id, current);
1514
1478
  }
1515
1479
  switch (current.constructor) {
1516
1480
  case Date:
1517
- return createDateNode(id, current);
1481
+ return new SerovalDateNode(id, current);
1518
1482
  case RegExp:
1519
- return createRegExpNode(id, current);
1483
+ return new SerovalRegExpNode(id, current);
1520
1484
  case Int8Array:
1521
1485
  case Int16Array:
1522
1486
  case Int32Array:
@@ -1526,10 +1490,15 @@ var SyncParser = class {
1526
1490
  case Uint8ClampedArray:
1527
1491
  case Float32Array:
1528
1492
  case Float64Array:
1529
- return createTypedArrayNode(this.ctx, id, current);
1493
+ assert(this.ctx.features & 1024 /* TypedArray */, `Unsupported value type "${current.constructor.name}"`);
1494
+ return new SerovalTypedArrayNode(id, current);
1530
1495
  case BigInt64Array:
1531
1496
  case BigUint64Array:
1532
- return createBigIntTypedArrayNode(this.ctx, id, current);
1497
+ assert(
1498
+ this.ctx.features & 2048 /* BigIntTypedArray */,
1499
+ `Unsupported value type "${current.constructor.name}"`
1500
+ );
1501
+ return new SerovalBigIntTypedArrayNode(id, current);
1533
1502
  case Map:
1534
1503
  return this.generateMapNode(id, current);
1535
1504
  case Set:
@@ -1602,16 +1571,16 @@ function finalize(ctx, rootID, isObject, result) {
1602
1571
  return result;
1603
1572
  }
1604
1573
  function serialize(source, options) {
1605
- const ctx = createParserContext(options);
1574
+ const ctx = new ParserContext(options);
1606
1575
  const [tree, rootID, isObject] = parseSync(ctx, source);
1607
- const serial = createSerializationContext(ctx);
1576
+ const serial = new SerializationContext(ctx);
1608
1577
  const result = serializeTree(serial, tree);
1609
1578
  return finalize(serial, rootID, isObject, result);
1610
1579
  }
1611
1580
  async function serializeAsync(source, options) {
1612
- const ctx = createParserContext(options);
1581
+ const ctx = new ParserContext(options);
1613
1582
  const [tree, rootID, isObject] = await parseAsync(ctx, source);
1614
- const serial = createSerializationContext(ctx);
1583
+ const serial = new SerializationContext(ctx);
1615
1584
  const result = serializeTree(serial, tree);
1616
1585
  return finalize(serial, rootID, isObject, result);
1617
1586
  }
@@ -1619,7 +1588,7 @@ function deserialize(source) {
1619
1588
  return (0, eval)(source);
1620
1589
  }
1621
1590
  function toJSON(source, options) {
1622
- const ctx = createParserContext(options);
1591
+ const ctx = new ParserContext(options);
1623
1592
  const [tree, root, isObject] = parseSync(ctx, source);
1624
1593
  return JSON.stringify([
1625
1594
  tree,
@@ -1630,7 +1599,7 @@ function toJSON(source, options) {
1630
1599
  ]);
1631
1600
  }
1632
1601
  async function toJSONAsync(source, options) {
1633
- const ctx = createParserContext(options);
1602
+ const ctx = new ParserContext(options);
1634
1603
  const [tree, root, isObject] = await parseAsync(ctx, source);
1635
1604
  return JSON.stringify([
1636
1605
  tree,
@@ -1642,7 +1611,7 @@ async function toJSONAsync(source, options) {
1642
1611
  }
1643
1612
  function compileJSON(source) {
1644
1613
  const parsed = JSON.parse(source);
1645
- const serial = createSerializationContext({
1614
+ const serial = new SerializationContext({
1646
1615
  features: parsed[3],
1647
1616
  markedRefs: parsed[4]
1648
1617
  });