seroval 0.4.0-alpha.10 → 0.4.0-alpha.11

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.
@@ -31,28 +31,6 @@ __export(src_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(src_exports);
33
33
 
34
- // src/checks.ts
35
- function isPrimitive(current) {
36
- if (!current || current === true) {
37
- return true;
38
- }
39
- const type = typeof current;
40
- return type === "number" || type === "string";
41
- }
42
- function isPromise(obj) {
43
- return !!obj && (typeof obj === "object" || typeof obj === "function") && "then" in obj && typeof obj.then === "function";
44
- }
45
- function isIterableBuiltin(obj) {
46
- if (!!obj && typeof obj === "object") {
47
- const cons = obj.constructor;
48
- return Array.isArray(obj) || cons === Set || cons === Map;
49
- }
50
- return false;
51
- }
52
- function isIterable(obj) {
53
- return !!obj && typeof obj === "object" && !isIterableBuiltin(obj) && Symbol.iterator in obj && typeof obj[Symbol.iterator] === "function";
54
- }
55
-
56
34
  // src/compat.ts
57
35
  function compareVersion(left, right) {
58
36
  let diff = left[0] - right[0];
@@ -399,6 +377,120 @@ function quote(str) {
399
377
  return `"${result}"`;
400
378
  }
401
379
 
380
+ // src/tree/primitives.ts
381
+ function createPrimitiveNode(value) {
382
+ return {
383
+ t: 0 /* Primitive */,
384
+ i: void 0,
385
+ s: value,
386
+ l: void 0,
387
+ m: void 0,
388
+ c: void 0,
389
+ d: void 0,
390
+ a: void 0,
391
+ n: void 0
392
+ };
393
+ }
394
+ var TRUE_NODE = createPrimitiveNode("!0");
395
+ var FALSE_NODE = createPrimitiveNode("!1");
396
+ var UNDEFINED_NODE = createPrimitiveNode("void 0");
397
+ var NULL_NODE = createPrimitiveNode(null);
398
+ var NEG_ZERO_NODE = createPrimitiveNode("-0");
399
+ var INFINITY_NODE = createPrimitiveNode("1/0");
400
+ var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
401
+ function createBigIntNode(ctx, current) {
402
+ assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
403
+ return {
404
+ t: 1 /* BigInt */,
405
+ i: void 0,
406
+ a: void 0,
407
+ s: `${current}n`,
408
+ l: void 0,
409
+ m: void 0,
410
+ c: void 0,
411
+ d: void 0,
412
+ n: void 0
413
+ };
414
+ }
415
+ function createReferenceNode(id) {
416
+ return {
417
+ t: 2 /* Reference */,
418
+ i: id,
419
+ a: void 0,
420
+ s: void 0,
421
+ l: void 0,
422
+ m: void 0,
423
+ c: void 0,
424
+ d: void 0,
425
+ n: void 0
426
+ };
427
+ }
428
+ function createDateNode(id, current) {
429
+ return {
430
+ t: 3 /* Date */,
431
+ i: id,
432
+ a: void 0,
433
+ s: current.toISOString(),
434
+ l: void 0,
435
+ m: void 0,
436
+ c: void 0,
437
+ d: void 0,
438
+ n: void 0
439
+ };
440
+ }
441
+ function createRegExpNode(id, current) {
442
+ return {
443
+ t: 4 /* RegExp */,
444
+ i: id,
445
+ a: void 0,
446
+ s: String(current),
447
+ l: void 0,
448
+ m: void 0,
449
+ c: void 0,
450
+ d: void 0,
451
+ n: void 0
452
+ };
453
+ }
454
+ function createTypedArrayNode(ctx, id, current) {
455
+ const constructor = current.constructor.name;
456
+ assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
457
+ return {
458
+ t: 14 /* TypedArray */,
459
+ i: id,
460
+ a: void 0,
461
+ s: current.toString(),
462
+ l: current.byteOffset,
463
+ m: void 0,
464
+ c: constructor,
465
+ d: void 0,
466
+ n: void 0
467
+ };
468
+ }
469
+ function createBigIntTypedArrayNode(ctx, id, current) {
470
+ const constructor = current.constructor.name;
471
+ assert(
472
+ ctx.features & 2048 /* BigIntTypedArray */,
473
+ `Unsupported value type "${constructor}"`
474
+ );
475
+ let result = "";
476
+ const cap = current.length - 1;
477
+ for (let i = 0; i < cap; i++) {
478
+ result += `${current[i]}n,`;
479
+ }
480
+ result += `"${current[cap]}"`;
481
+ return {
482
+ t: 15 /* BigIntTypedArray */,
483
+ i: id,
484
+ a: void 0,
485
+ s: result,
486
+ l: current.byteOffset,
487
+ m: void 0,
488
+ c: constructor,
489
+ d: void 0,
490
+ n: void 0
491
+ };
492
+ }
493
+
402
494
  // src/tree/shared.ts
403
495
  function getErrorConstructor(error) {
404
496
  if (error instanceof EvalError) {
@@ -452,33 +544,16 @@ function getIterableOptions(obj) {
452
544
  function isReferenceInStack(ctx, node) {
453
545
  return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
454
546
  }
455
- function generateSemiPrimitiveValue(ctx, current, id) {
456
- const cs = current.constructor;
457
- switch (cs) {
458
- case Date:
459
- return {
460
- t: 3 /* Date */,
461
- i: id,
462
- a: void 0,
463
- s: current.toISOString(),
464
- l: void 0,
465
- m: void 0,
466
- c: void 0,
467
- d: void 0,
468
- n: void 0
469
- };
470
- case RegExp:
471
- return {
472
- t: 4 /* RegExp */,
473
- i: id,
474
- a: void 0,
475
- s: String(current),
476
- l: void 0,
477
- m: void 0,
478
- c: void 0,
479
- d: void 0,
480
- n: void 0
481
- };
547
+ function isIterable(value) {
548
+ if (!value || typeof value !== "object") {
549
+ return false;
550
+ }
551
+ if (Array.isArray(value)) {
552
+ return false;
553
+ }
554
+ switch (value.constructor) {
555
+ case Map:
556
+ case Set:
482
557
  case Int8Array:
483
558
  case Int16Array:
484
559
  case Int32Array:
@@ -487,76 +562,14 @@ function generateSemiPrimitiveValue(ctx, current, id) {
487
562
  case Uint32Array:
488
563
  case Uint8ClampedArray:
489
564
  case Float32Array:
490
- case Float64Array: {
491
- const constructor = cs.name;
492
- assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
493
- return {
494
- t: 14 /* TypedArray */,
495
- i: id,
496
- a: void 0,
497
- s: current.toString(),
498
- l: current.byteOffset,
499
- m: void 0,
500
- c: constructor,
501
- d: void 0,
502
- n: void 0
503
- };
504
- }
565
+ case Float64Array:
505
566
  case BigInt64Array:
506
- case BigUint64Array: {
507
- const constructor = cs.name;
508
- assert(
509
- ctx.features & 2048 /* BigIntTypedArray */,
510
- `Unsupported value type "${constructor}"`
511
- );
512
- let result = "";
513
- const cap = current.length - 1;
514
- for (let i = 0; i < cap; i++) {
515
- result += `${current[i]}n,`;
516
- }
517
- result += `"${current[cap]}"`;
518
- return {
519
- t: 14 /* TypedArray */,
520
- i: id,
521
- a: void 0,
522
- s: result,
523
- l: current.byteOffset,
524
- m: void 0,
525
- c: constructor,
526
- d: void 0,
527
- n: void 0
528
- };
529
- }
567
+ case BigUint64Array:
568
+ return false;
530
569
  default:
531
- return void 0;
532
- }
533
- }
534
- function serializePrimitive(value) {
535
- if (value === true) {
536
- return "!0";
570
+ break;
537
571
  }
538
- if (value === false) {
539
- return "!1";
540
- }
541
- if (value === void 0) {
542
- return "void 0";
543
- }
544
- if (value === null) {
545
- return null;
546
- }
547
- if (typeof value === "string") {
548
- return quote(value);
549
- }
550
- if (Object.is(value, -0)) {
551
- return "-0";
552
- }
553
- if (Object.is(value, Infinity)) {
554
- return "1/0";
555
- }
556
- if (Object.is(value, -Infinity)) {
557
- return "-1/0";
558
- }
559
- return value;
572
+ return Symbol.iterator in value;
560
573
  }
561
574
 
562
575
  // src/tree/async.ts
@@ -569,14 +582,16 @@ async function serializePropertiesAsync(ctx, properties) {
569
582
  const deferredValues = new Array(size);
570
583
  let deferredSize = 0;
571
584
  let nodesSize = 0;
585
+ let item;
572
586
  for (const key of keys) {
573
- if (isIterable(properties[key])) {
587
+ item = properties[key];
588
+ if (isIterable(item)) {
574
589
  deferredKeys[deferredSize] = key;
575
- deferredValues[deferredSize] = properties[key];
590
+ deferredValues[deferredSize] = item;
576
591
  deferredSize++;
577
592
  } else {
578
593
  keyNodes[nodesSize] = key;
579
- valueNodes[nodesSize] = await generateTreeAsync(ctx, properties[key]);
594
+ valueNodes[nodesSize] = await generateTreeAsync(ctx, item);
580
595
  nodesSize++;
581
596
  }
582
597
  }
@@ -659,12 +674,14 @@ async function generateNodeList(ctx, current) {
659
674
  const size = current.length;
660
675
  const nodes = new Array(size);
661
676
  const deferred = new Array(size);
677
+ let item;
662
678
  for (let i = 0; i < size; i++) {
663
679
  if (i in current) {
664
- if (isIterable(current[i])) {
665
- deferred[i] = current[i];
680
+ item = current[i];
681
+ if (isIterable(item)) {
682
+ deferred[i] = item;
666
683
  } else {
667
- nodes[i] = await generateTreeAsync(ctx, current[i]);
684
+ nodes[i] = await generateTreeAsync(ctx, item);
668
685
  }
669
686
  }
670
687
  }
@@ -734,110 +751,141 @@ async function generateIterableNode(ctx, current, id) {
734
751
  n: void 0
735
752
  };
736
753
  }
737
- async function generateTreeAsync(ctx, current) {
738
- if (isPrimitive(current)) {
739
- return {
740
- t: 0 /* Primitive */,
741
- i: void 0,
742
- s: serializePrimitive(current),
743
- l: void 0,
744
- m: void 0,
745
- c: void 0,
746
- // Parse options first before the items
747
- d: void 0,
748
- a: void 0,
749
- n: void 0
750
- };
751
- }
752
- if (typeof current === "bigint") {
753
- assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
754
- return {
755
- t: 1 /* BigInt */,
756
- i: void 0,
757
- a: void 0,
758
- s: `${current}n`,
759
- l: void 0,
760
- m: void 0,
761
- c: void 0,
762
- d: void 0,
763
- n: void 0
764
- };
765
- }
766
- const id = createRef(ctx, current, true);
767
- if (ctx.markedRefs[id]) {
768
- return {
769
- t: 2 /* Reference */,
770
- i: id,
771
- a: void 0,
772
- s: void 0,
773
- l: void 0,
774
- m: void 0,
775
- c: void 0,
776
- d: void 0,
777
- n: void 0
778
- };
779
- }
780
- if (Array.isArray(current)) {
781
- return generateArrayNode(ctx, current, id);
782
- }
783
- const cs = current.constructor;
784
- const empty = cs == null;
785
- if (cs === Object || empty) {
786
- if (Symbol.iterator in current) {
787
- return generateIterableNode(ctx, current, id);
788
- }
789
- return {
790
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
791
- i: id,
792
- s: void 0,
793
- l: void 0,
794
- m: void 0,
795
- c: void 0,
796
- // Parse options first before the items
797
- d: await serializePropertiesAsync(ctx, current),
798
- a: void 0,
799
- n: void 0
800
- };
801
- }
802
- if (cs === Set) {
803
- return generateSetNode(ctx, current, id);
804
- }
805
- if (cs === Map) {
806
- return generateMapNode(ctx, current, id);
807
- }
808
- const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
809
- if (semiPrimitive) {
810
- return semiPrimitive;
811
- }
754
+ async function generateObjectNode(ctx, current, id, empty) {
812
755
  if (Symbol.iterator in current) {
813
756
  return generateIterableNode(ctx, current, id);
814
757
  }
815
- if (isPromise(current)) {
816
- assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
817
- return current.then(async (value) => ({
818
- t: 10 /* Promise */,
819
- i: id,
820
- s: void 0,
821
- l: void 0,
822
- m: void 0,
823
- c: void 0,
824
- // Parse options first before the items
825
- d: void 0,
826
- a: void 0,
827
- n: await generateTreeAsync(ctx, value)
828
- }));
829
- }
830
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
831
- return generateAggregateErrorNode(ctx, current, id);
832
- }
833
- if (current instanceof Error) {
834
- return generateErrorNode(ctx, current, id);
835
- }
836
- throw new Error("Unsupported value");
758
+ if ("then" in current && typeof current.then === "function") {
759
+ return generatePromiseNode(ctx, current, id);
760
+ }
761
+ return {
762
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
763
+ i: id,
764
+ s: void 0,
765
+ l: void 0,
766
+ m: void 0,
767
+ c: void 0,
768
+ d: await serializePropertiesAsync(ctx, current),
769
+ a: void 0,
770
+ n: void 0
771
+ };
772
+ }
773
+ async function generatePromiseNode(ctx, current, id) {
774
+ assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
775
+ return current.then(async (value) => ({
776
+ t: 10 /* Promise */,
777
+ i: id,
778
+ s: void 0,
779
+ l: void 0,
780
+ m: void 0,
781
+ c: void 0,
782
+ // Parse options first before the items
783
+ d: void 0,
784
+ a: void 0,
785
+ n: await generateTreeAsync(ctx, value)
786
+ }));
787
+ }
788
+ async function generateTreeAsync(ctx, current) {
789
+ switch (typeof current) {
790
+ case "boolean":
791
+ return current ? TRUE_NODE : FALSE_NODE;
792
+ case "undefined":
793
+ return UNDEFINED_NODE;
794
+ case "string":
795
+ return createPrimitiveNode(quote(current));
796
+ case "number":
797
+ if (Object.is(current, -0)) {
798
+ return NEG_ZERO_NODE;
799
+ }
800
+ if (Object.is(current, Infinity)) {
801
+ return createPrimitiveNode("1/0");
802
+ }
803
+ if (Object.is(current, -Infinity)) {
804
+ return createPrimitiveNode("-1/0");
805
+ }
806
+ return createPrimitiveNode(current);
807
+ case "bigint":
808
+ return createBigIntNode(ctx, current);
809
+ case "object": {
810
+ if (!current) {
811
+ return NULL_NODE;
812
+ }
813
+ const id = createRef(ctx, current, true);
814
+ if (ctx.markedRefs[id]) {
815
+ return createReferenceNode(id);
816
+ }
817
+ if (Array.isArray(current)) {
818
+ return generateArrayNode(ctx, current, id);
819
+ }
820
+ switch (current.constructor) {
821
+ case Date:
822
+ return createDateNode(id, current);
823
+ case RegExp:
824
+ return createRegExpNode(id, current);
825
+ case Promise:
826
+ return generatePromiseNode(ctx, current, id);
827
+ case Map:
828
+ return generateMapNode(ctx, current, id);
829
+ case Set:
830
+ return generateSetNode(ctx, current, id);
831
+ case Object:
832
+ return generateObjectNode(ctx, current, id, false);
833
+ case void 0:
834
+ return generateObjectNode(ctx, current, id, true);
835
+ case Int8Array:
836
+ case Int16Array:
837
+ case Int32Array:
838
+ case Uint8Array:
839
+ case Uint16Array:
840
+ case Uint32Array:
841
+ case Uint8ClampedArray:
842
+ case Float32Array:
843
+ case Float64Array:
844
+ return createTypedArrayNode(ctx, id, current);
845
+ case BigInt64Array:
846
+ case BigUint64Array:
847
+ return createBigIntTypedArrayNode(ctx, id, current);
848
+ case AggregateError:
849
+ if (ctx.features & 1 /* AggregateError */) {
850
+ return generateAggregateErrorNode(ctx, current, id);
851
+ }
852
+ return generateErrorNode(ctx, current, id);
853
+ case Error:
854
+ case EvalError:
855
+ case RangeError:
856
+ case ReferenceError:
857
+ case SyntaxError:
858
+ case TypeError:
859
+ case URIError:
860
+ return generateErrorNode(ctx, current, id);
861
+ default:
862
+ break;
863
+ }
864
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
865
+ return generateAggregateErrorNode(ctx, current, id);
866
+ }
867
+ if (current instanceof Error) {
868
+ return generateErrorNode(ctx, current, id);
869
+ }
870
+ if (current instanceof Promise) {
871
+ return generatePromiseNode(ctx, current, id);
872
+ }
873
+ if (Symbol.iterator in current) {
874
+ return generateIterableNode(ctx, current, id);
875
+ }
876
+ if ("then" in current && typeof current.then === "function") {
877
+ return generatePromiseNode(ctx, current, id);
878
+ }
879
+ throw new Error("Unsupported type");
880
+ }
881
+ default:
882
+ throw new Error("Unsupported type");
883
+ }
837
884
  }
838
885
  async function parseAsync(ctx, current) {
839
886
  const result = await generateTreeAsync(ctx, current);
840
- return [result, createRef(ctx, current, false), result.t === 8 /* Object */];
887
+ const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
888
+ return [result, createRef(ctx, current, false), isObject];
841
889
  }
842
890
 
843
891
  // src/tree/serialize.ts
@@ -1231,14 +1279,16 @@ function serializePropertiesSync(ctx, properties) {
1231
1279
  const deferredValues = new Array(size);
1232
1280
  let deferredSize = 0;
1233
1281
  let nodesSize = 0;
1282
+ let item;
1234
1283
  for (const key of keys) {
1235
- if (isIterable(properties[key])) {
1284
+ item = properties[key];
1285
+ if (isIterable(item)) {
1236
1286
  deferredKeys[deferredSize] = key;
1237
- deferredValues[deferredSize] = properties[key];
1287
+ deferredValues[deferredSize] = item;
1238
1288
  deferredSize++;
1239
1289
  } else {
1240
1290
  keyNodes[nodesSize] = key;
1241
- valueNodes[nodesSize] = generateTreeSync(ctx, properties[key]);
1291
+ valueNodes[nodesSize] = generateTreeSync(ctx, item);
1242
1292
  nodesSize++;
1243
1293
  }
1244
1294
  }
@@ -1321,12 +1371,14 @@ function generateNodeList2(ctx, current) {
1321
1371
  const size = current.length;
1322
1372
  const nodes = new Array(size);
1323
1373
  const deferred = new Array(size);
1374
+ let item;
1324
1375
  for (let i = 0; i < size; i++) {
1325
1376
  if (i in current) {
1326
- if (isIterable(current[i])) {
1327
- deferred[i] = current[i];
1377
+ item = current[i];
1378
+ if (isIterable(item)) {
1379
+ deferred[i] = item;
1328
1380
  } else {
1329
- nodes[i] = generateTreeSync(ctx, current[i]);
1381
+ nodes[i] = generateTreeSync(ctx, item);
1330
1382
  }
1331
1383
  }
1332
1384
  }
@@ -1396,95 +1448,115 @@ function generateIterableNode2(ctx, current, id) {
1396
1448
  n: void 0
1397
1449
  };
1398
1450
  }
1399
- function generateTreeSync(ctx, current) {
1400
- if (isPrimitive(current)) {
1401
- return {
1402
- t: 0 /* Primitive */,
1403
- i: void 0,
1404
- s: serializePrimitive(current),
1405
- l: void 0,
1406
- m: void 0,
1407
- c: void 0,
1408
- // Parse options first before the items
1409
- d: void 0,
1410
- a: void 0,
1411
- n: void 0
1412
- };
1413
- }
1414
- if (typeof current === "bigint") {
1415
- assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
1416
- return {
1417
- t: 1 /* BigInt */,
1418
- i: void 0,
1419
- a: void 0,
1420
- s: `${current}n`,
1421
- l: void 0,
1422
- m: void 0,
1423
- c: void 0,
1424
- d: void 0,
1425
- n: void 0
1426
- };
1427
- }
1428
- const id = createRef(ctx, current, true);
1429
- if (ctx.markedRefs[id]) {
1430
- return {
1431
- t: 2 /* Reference */,
1432
- i: id,
1433
- a: void 0,
1434
- s: void 0,
1435
- l: void 0,
1436
- m: void 0,
1437
- c: void 0,
1438
- d: void 0,
1439
- n: void 0
1440
- };
1441
- }
1442
- if (Array.isArray(current)) {
1443
- return generateArrayNode2(ctx, current, id);
1444
- }
1445
- const cs = current.constructor;
1446
- const empty = cs == null;
1447
- if (cs === Object || empty) {
1448
- if (Symbol.iterator in current) {
1449
- return generateIterableNode2(ctx, current, id);
1450
- }
1451
- return {
1452
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1453
- i: id,
1454
- s: void 0,
1455
- l: void 0,
1456
- m: void 0,
1457
- c: void 0,
1458
- // Parse options first before the items
1459
- d: serializePropertiesSync(ctx, current),
1460
- a: void 0,
1461
- n: void 0
1462
- };
1463
- }
1464
- if (cs === Set) {
1465
- return generateSetNode2(ctx, current, id);
1466
- }
1467
- if (cs === Map) {
1468
- return generateMapNode2(ctx, current, id);
1469
- }
1470
- const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
1471
- if (semiPrimitive) {
1472
- return semiPrimitive;
1473
- }
1451
+ function generateObjectNode2(ctx, current, id, empty) {
1474
1452
  if (Symbol.iterator in current) {
1475
1453
  return generateIterableNode2(ctx, current, id);
1476
1454
  }
1477
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1478
- return generateAggregateErrorNode2(ctx, current, id);
1479
- }
1480
- if (current instanceof Error) {
1481
- return generateErrorNode2(ctx, current, id);
1455
+ return {
1456
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1457
+ i: id,
1458
+ s: void 0,
1459
+ l: void 0,
1460
+ m: void 0,
1461
+ c: void 0,
1462
+ d: serializePropertiesSync(ctx, current),
1463
+ a: void 0,
1464
+ n: void 0
1465
+ };
1466
+ }
1467
+ function generateTreeSync(ctx, current) {
1468
+ switch (typeof current) {
1469
+ case "boolean":
1470
+ return current ? TRUE_NODE : FALSE_NODE;
1471
+ case "undefined":
1472
+ return UNDEFINED_NODE;
1473
+ case "string":
1474
+ return createPrimitiveNode(quote(current));
1475
+ case "number":
1476
+ if (Object.is(current, -0)) {
1477
+ return NEG_ZERO_NODE;
1478
+ }
1479
+ if (Object.is(current, Infinity)) {
1480
+ return createPrimitiveNode("1/0");
1481
+ }
1482
+ if (Object.is(current, -Infinity)) {
1483
+ return createPrimitiveNode("-1/0");
1484
+ }
1485
+ return createPrimitiveNode(current);
1486
+ case "bigint":
1487
+ return createBigIntNode(ctx, current);
1488
+ case "object": {
1489
+ if (!current) {
1490
+ return NULL_NODE;
1491
+ }
1492
+ const id = createRef(ctx, current, true);
1493
+ if (ctx.markedRefs[id]) {
1494
+ return createReferenceNode(id);
1495
+ }
1496
+ if (Array.isArray(current)) {
1497
+ return generateArrayNode2(ctx, current, id);
1498
+ }
1499
+ switch (current.constructor) {
1500
+ case Date:
1501
+ return createDateNode(id, current);
1502
+ case RegExp:
1503
+ return createRegExpNode(id, current);
1504
+ case Map:
1505
+ return generateMapNode2(ctx, current, id);
1506
+ case Set:
1507
+ return generateSetNode2(ctx, current, id);
1508
+ case Object:
1509
+ return generateObjectNode2(ctx, current, id, false);
1510
+ case void 0:
1511
+ return generateObjectNode2(ctx, current, id, true);
1512
+ case Int8Array:
1513
+ case Int16Array:
1514
+ case Int32Array:
1515
+ case Uint8Array:
1516
+ case Uint16Array:
1517
+ case Uint32Array:
1518
+ case Uint8ClampedArray:
1519
+ case Float32Array:
1520
+ case Float64Array:
1521
+ return createTypedArrayNode(ctx, id, current);
1522
+ case BigInt64Array:
1523
+ case BigUint64Array:
1524
+ return createBigIntTypedArrayNode(ctx, id, current);
1525
+ case AggregateError:
1526
+ if (ctx.features & 1 /* AggregateError */) {
1527
+ return generateAggregateErrorNode2(ctx, current, id);
1528
+ }
1529
+ return generateErrorNode2(ctx, current, id);
1530
+ case Error:
1531
+ case EvalError:
1532
+ case RangeError:
1533
+ case ReferenceError:
1534
+ case SyntaxError:
1535
+ case TypeError:
1536
+ case URIError:
1537
+ return generateErrorNode2(ctx, current, id);
1538
+ default:
1539
+ break;
1540
+ }
1541
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1542
+ return generateAggregateErrorNode2(ctx, current, id);
1543
+ }
1544
+ if (current instanceof Error) {
1545
+ return generateErrorNode2(ctx, current, id);
1546
+ }
1547
+ if (Symbol.iterator in current) {
1548
+ return generateIterableNode2(ctx, current, id);
1549
+ }
1550
+ throw new Error("Unsupported type");
1551
+ }
1552
+ default:
1553
+ throw new Error("Unsupported type");
1482
1554
  }
1483
- throw new Error("Unsupported value");
1484
1555
  }
1485
1556
  function parseSync(ctx, current) {
1486
1557
  const result = generateTreeSync(ctx, current);
1487
- return [result, createRef(ctx, current, false), result.t === 8 /* Object */];
1558
+ const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
1559
+ return [result, createRef(ctx, current, false), isObject];
1488
1560
  }
1489
1561
 
1490
1562
  // src/index.ts
@@ -1514,9 +1586,6 @@ function finalize(ctx, rootID, isObject, result) {
1514
1586
  }
1515
1587
  function serialize(source, options) {
1516
1588
  const ctx = createParserContext(options);
1517
- if (isPrimitive(source)) {
1518
- return String(serializePrimitive(source));
1519
- }
1520
1589
  const [tree, rootID, isObject] = parseSync(ctx, source);
1521
1590
  const serial = createSerializationContext(ctx);
1522
1591
  const result = serializeTree(serial, tree);
@@ -1524,9 +1593,6 @@ function serialize(source, options) {
1524
1593
  }
1525
1594
  async function serializeAsync(source, options) {
1526
1595
  const ctx = createParserContext(options);
1527
- if (isPrimitive(source)) {
1528
- return String(serializePrimitive(source));
1529
- }
1530
1596
  const [tree, rootID, isObject] = await parseAsync(ctx, source);
1531
1597
  const serial = createSerializationContext(ctx);
1532
1598
  const result = serializeTree(serial, tree);