seroval 0.4.0-alpha.16 → 0.4.0-alpha.18

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.
@@ -263,10 +263,11 @@ function createTypedArrayNode(ctx, id, current) {
263
263
  n: void 0
264
264
  };
265
265
  }
266
+ var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
266
267
  function createBigIntTypedArrayNode(ctx, id, current) {
267
268
  const constructor = current.constructor.name;
268
269
  assert(
269
- ctx.features & 4096 /* BigIntTypedArray */,
270
+ (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
270
271
  `Unsupported value type "${constructor}"`
271
272
  );
272
273
  let result = "";
@@ -375,337 +376,335 @@ function isIterable(value) {
375
376
  }
376
377
 
377
378
  // src/tree/async.ts
378
- var AsyncParser = class {
379
- static async generateNodeList(ctx, current) {
380
- const size = current.length;
381
- const nodes = new Array(size);
382
- const deferred = new Array(size);
383
- let item;
384
- for (let i = 0; i < size; i++) {
385
- if (i in current) {
386
- item = current[i];
387
- if (isIterable(item)) {
388
- deferred[i] = item;
389
- } else {
390
- nodes[i] = await this.parse(ctx, item);
391
- }
392
- }
393
- }
394
- for (let i = 0; i < size; i++) {
395
- if (i in deferred) {
396
- nodes[i] = await this.parse(ctx, deferred[i]);
397
- }
398
- }
399
- return nodes;
400
- }
401
- static async generateArrayNode(ctx, id, current) {
402
- return {
403
- t: 7 /* Array */,
404
- i: id,
405
- s: void 0,
406
- l: void 0,
407
- c: void 0,
408
- m: void 0,
409
- d: void 0,
410
- a: await this.generateNodeList(ctx, current),
411
- n: void 0
412
- };
413
- }
414
- static async generateMapNode(ctx, id, current) {
415
- assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
416
- const len = current.size;
417
- const keyNodes = new Array(len);
418
- const valueNodes = new Array(len);
419
- const deferredKey = new Array(len);
420
- const deferredValue = new Array(len);
421
- let deferredSize = 0;
422
- let nodeSize = 0;
423
- for (const [key, value] of current.entries()) {
424
- if (isIterable(key) || isIterable(value)) {
425
- deferredKey[deferredSize] = key;
426
- deferredValue[deferredSize] = value;
427
- deferredSize++;
428
- } else {
429
- keyNodes[nodeSize] = await this.parse(ctx, key);
430
- valueNodes[nodeSize] = await this.parse(ctx, value);
431
- nodeSize++;
432
- }
433
- }
434
- for (let i = 0; i < deferredSize; i++) {
435
- keyNodes[nodeSize + i] = await this.parse(ctx, deferredKey[i]);
436
- valueNodes[nodeSize + i] = await this.parse(ctx, deferredValue[i]);
437
- }
438
- return {
439
- t: 6 /* Map */,
440
- i: id,
441
- s: void 0,
442
- l: void 0,
443
- c: void 0,
444
- m: void 0,
445
- d: { k: keyNodes, v: valueNodes, s: len },
446
- a: void 0,
447
- n: void 0
448
- };
449
- }
450
- static async generateSetNode(ctx, id, current) {
451
- assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
452
- const len = current.size;
453
- const nodes = new Array(len);
454
- const deferred = new Array(len);
455
- let deferredSize = 0;
456
- let nodeSize = 0;
457
- for (const item of current.keys()) {
379
+ async function generateNodeList(ctx, current) {
380
+ const size = current.length;
381
+ const nodes = new Array(size);
382
+ const deferred = new Array(size);
383
+ let item;
384
+ for (let i = 0; i < size; i++) {
385
+ if (i in current) {
386
+ item = current[i];
458
387
  if (isIterable(item)) {
459
- deferred[deferredSize++] = item;
388
+ deferred[i] = item;
460
389
  } else {
461
- nodes[nodeSize++] = await this.parse(ctx, item);
390
+ nodes[i] = await parse(ctx, item);
462
391
  }
463
392
  }
464
- for (let i = 0; i < deferredSize; i++) {
465
- nodes[nodeSize + i] = await this.parse(ctx, deferred[i]);
466
- }
467
- return {
468
- t: 5 /* Set */,
469
- i: id,
470
- s: void 0,
471
- l: void 0,
472
- c: void 0,
473
- m: void 0,
474
- d: void 0,
475
- a: nodes,
476
- n: void 0
477
- };
478
393
  }
479
- static async generateProperties(ctx, properties) {
480
- const keys = Object.keys(properties);
481
- const size = keys.length;
482
- const keyNodes = new Array(size);
483
- const valueNodes = new Array(size);
484
- const deferredKeys = new Array(size);
485
- const deferredValues = new Array(size);
486
- let deferredSize = 0;
487
- let nodesSize = 0;
488
- let item;
489
- for (const key of keys) {
490
- item = properties[key];
491
- if (isIterable(item)) {
492
- deferredKeys[deferredSize] = key;
493
- deferredValues[deferredSize] = item;
494
- deferredSize++;
495
- } else {
496
- keyNodes[nodesSize] = key;
497
- valueNodes[nodesSize] = await this.parse(ctx, item);
498
- nodesSize++;
499
- }
500
- }
501
- for (let i = 0; i < deferredSize; i++) {
502
- keyNodes[nodesSize + i] = deferredKeys[i];
503
- valueNodes[nodesSize + i] = await this.parse(ctx, deferredValues[i]);
394
+ for (let i = 0; i < size; i++) {
395
+ if (i in deferred) {
396
+ nodes[i] = await parse(ctx, deferred[i]);
504
397
  }
505
- return {
506
- k: keyNodes,
507
- v: valueNodes,
508
- s: size
509
- };
510
398
  }
511
- static async generateIterableNode(ctx, id, current) {
512
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
513
- const options = getIterableOptions(current);
514
- return {
515
- t: 13 /* Iterable */,
516
- i: id,
517
- s: void 0,
518
- l: void 0,
519
- c: void 0,
520
- m: void 0,
521
- // Parse options first before the items
522
- d: options ? await this.generateProperties(ctx, options) : void 0,
523
- a: await this.generateNodeList(ctx, Array.from(current)),
524
- n: void 0
525
- };
399
+ return nodes;
400
+ }
401
+ async function generateArrayNode(ctx, id, current) {
402
+ return {
403
+ t: 7 /* Array */,
404
+ i: id,
405
+ s: void 0,
406
+ l: void 0,
407
+ c: void 0,
408
+ m: void 0,
409
+ d: void 0,
410
+ a: await generateNodeList(ctx, current),
411
+ n: void 0
412
+ };
413
+ }
414
+ async function generateMapNode(ctx, id, current) {
415
+ assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
416
+ const len = current.size;
417
+ const keyNodes = new Array(len);
418
+ const valueNodes = new Array(len);
419
+ const deferredKey = new Array(len);
420
+ const deferredValue = new Array(len);
421
+ let deferredSize = 0;
422
+ let nodeSize = 0;
423
+ for (const [key, value] of current.entries()) {
424
+ if (isIterable(key) || isIterable(value)) {
425
+ deferredKey[deferredSize] = key;
426
+ deferredValue[deferredSize] = value;
427
+ deferredSize++;
428
+ } else {
429
+ keyNodes[nodeSize] = await parse(ctx, key);
430
+ valueNodes[nodeSize] = await parse(ctx, value);
431
+ nodeSize++;
432
+ }
526
433
  }
527
- static async generatePromiseNode(ctx, id, current) {
528
- assert(ctx.features & 256 /* Promise */, 'Unsupported type "Promise"');
529
- return current.then(async (value) => ({
530
- t: 10 /* Promise */,
531
- i: id,
532
- s: void 0,
533
- l: void 0,
534
- c: void 0,
535
- m: void 0,
536
- // Parse options first before the items
537
- d: void 0,
538
- a: void 0,
539
- n: await this.parse(ctx, value)
540
- }));
434
+ for (let i = 0; i < deferredSize; i++) {
435
+ keyNodes[nodeSize + i] = await parse(ctx, deferredKey[i]);
436
+ valueNodes[nodeSize + i] = await parse(ctx, deferredValue[i]);
541
437
  }
542
- static async generateObjectNode(ctx, id, current, empty) {
543
- if (Symbol.iterator in current) {
544
- return this.generateIterableNode(ctx, id, current);
438
+ return {
439
+ t: 6 /* Map */,
440
+ i: id,
441
+ s: void 0,
442
+ l: void 0,
443
+ c: void 0,
444
+ m: void 0,
445
+ d: { k: keyNodes, v: valueNodes, s: len },
446
+ a: void 0,
447
+ n: void 0
448
+ };
449
+ }
450
+ async function generateSetNode(ctx, id, current) {
451
+ assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
452
+ const len = current.size;
453
+ const nodes = new Array(len);
454
+ const deferred = new Array(len);
455
+ let deferredSize = 0;
456
+ let nodeSize = 0;
457
+ for (const item of current.keys()) {
458
+ if (isIterable(item)) {
459
+ deferred[deferredSize++] = item;
460
+ } else {
461
+ nodes[nodeSize++] = await parse(ctx, item);
545
462
  }
546
- if ("then" in current && typeof current.then === "function") {
547
- return this.generatePromiseNode(ctx, id, current);
463
+ }
464
+ for (let i = 0; i < deferredSize; i++) {
465
+ nodes[nodeSize + i] = await parse(ctx, deferred[i]);
466
+ }
467
+ return {
468
+ t: 5 /* Set */,
469
+ i: id,
470
+ s: void 0,
471
+ l: void 0,
472
+ c: void 0,
473
+ m: void 0,
474
+ d: void 0,
475
+ a: nodes,
476
+ n: void 0
477
+ };
478
+ }
479
+ async function generateProperties(ctx, properties) {
480
+ const keys = Object.keys(properties);
481
+ const size = keys.length;
482
+ const keyNodes = new Array(size);
483
+ const valueNodes = new Array(size);
484
+ const deferredKeys = new Array(size);
485
+ const deferredValues = new Array(size);
486
+ let deferredSize = 0;
487
+ let nodesSize = 0;
488
+ let item;
489
+ for (const key of keys) {
490
+ item = properties[key];
491
+ if (isIterable(item)) {
492
+ deferredKeys[deferredSize] = key;
493
+ deferredValues[deferredSize] = item;
494
+ deferredSize++;
495
+ } else {
496
+ keyNodes[nodesSize] = key;
497
+ valueNodes[nodesSize] = await parse(ctx, item);
498
+ nodesSize++;
548
499
  }
549
- return {
550
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
551
- i: id,
552
- s: void 0,
553
- l: void 0,
554
- c: void 0,
555
- m: void 0,
556
- d: await this.generateProperties(ctx, current),
557
- a: void 0,
558
- n: void 0
559
- };
560
500
  }
561
- static async generateAggregateErrorNode(ctx, id, current) {
562
- const options = getErrorOptions(ctx, current);
563
- const optionsNode = options ? await this.generateProperties(ctx, options) : void 0;
564
- return {
565
- t: 12 /* AggregateError */,
566
- i: id,
567
- s: void 0,
568
- l: void 0,
569
- c: void 0,
570
- m: current.message,
571
- d: optionsNode,
572
- a: void 0,
573
- n: await this.parse(ctx, current.errors)
574
- };
501
+ for (let i = 0; i < deferredSize; i++) {
502
+ keyNodes[nodesSize + i] = deferredKeys[i];
503
+ valueNodes[nodesSize + i] = await parse(ctx, deferredValues[i]);
575
504
  }
576
- static async generateErrorNode(ctx, id, current) {
577
- const options = getErrorOptions(ctx, current);
578
- const optionsNode = options ? await this.generateProperties(ctx, options) : void 0;
579
- return {
580
- t: 11 /* Error */,
581
- i: id,
582
- s: void 0,
583
- l: void 0,
584
- c: getErrorConstructor(current),
585
- m: current.message,
586
- d: optionsNode,
587
- a: void 0,
588
- n: void 0
589
- };
505
+ return {
506
+ k: keyNodes,
507
+ v: valueNodes,
508
+ s: size
509
+ };
510
+ }
511
+ async function generateIterableNode(ctx, id, current) {
512
+ assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
513
+ const options = getIterableOptions(current);
514
+ return {
515
+ t: 13 /* Iterable */,
516
+ i: id,
517
+ s: void 0,
518
+ l: void 0,
519
+ c: void 0,
520
+ m: void 0,
521
+ // Parse options first before the items
522
+ d: options ? await generateProperties(ctx, options) : void 0,
523
+ a: await generateNodeList(ctx, Array.from(current)),
524
+ n: void 0
525
+ };
526
+ }
527
+ async function generatePromiseNode(ctx, id, current) {
528
+ assert(ctx.features & 256 /* Promise */, 'Unsupported type "Promise"');
529
+ return current.then(async (value) => ({
530
+ t: 10 /* Promise */,
531
+ i: id,
532
+ s: void 0,
533
+ l: void 0,
534
+ c: void 0,
535
+ m: void 0,
536
+ // Parse options first before the items
537
+ d: void 0,
538
+ a: void 0,
539
+ n: await parse(ctx, value)
540
+ }));
541
+ }
542
+ async function generateObjectNode(ctx, id, current, empty) {
543
+ if (Symbol.iterator in current) {
544
+ return generateIterableNode(ctx, id, current);
590
545
  }
591
- static async parse(ctx, current) {
592
- switch (typeof current) {
593
- case "boolean":
594
- return current ? TRUE_NODE : FALSE_NODE;
595
- case "undefined":
596
- return UNDEFINED_NODE;
597
- case "string":
598
- return createPrimitiveNode(quote(current));
599
- case "number":
600
- if (Object.is(current, -0)) {
601
- return NEG_ZERO_NODE;
602
- }
603
- if (Object.is(current, Infinity)) {
604
- return createPrimitiveNode("1/0");
605
- }
606
- if (Object.is(current, -Infinity)) {
607
- return createPrimitiveNode("-1/0");
608
- }
609
- return createPrimitiveNode(current);
610
- case "bigint":
611
- return createBigIntNode(ctx, current);
612
- case "object": {
613
- if (!current) {
614
- return NULL_NODE;
615
- }
616
- const id = createRef(ctx, current, true);
617
- if (ctx.markedRefs.has(id)) {
618
- return createReferenceNode(id);
619
- }
620
- if (Array.isArray(current)) {
621
- return this.generateArrayNode(ctx, id, current);
622
- }
623
- switch (current.constructor) {
624
- case Date:
625
- return createDateNode(id, current);
626
- case RegExp:
627
- return createRegExpNode(id, current);
628
- case Promise:
629
- return this.generatePromiseNode(ctx, id, current);
630
- case Int8Array:
631
- case Int16Array:
632
- case Int32Array:
633
- case Uint8Array:
634
- case Uint16Array:
635
- case Uint32Array:
636
- case Uint8ClampedArray:
637
- case Float32Array:
638
- case Float64Array:
639
- return createTypedArrayNode(ctx, id, current);
640
- case BigInt64Array:
641
- case BigUint64Array:
642
- return createBigIntTypedArrayNode(ctx, id, current);
643
- case Map:
644
- return this.generateMapNode(
645
- ctx,
646
- id,
647
- current
648
- );
649
- case Set:
650
- return this.generateSetNode(
651
- ctx,
652
- id,
653
- current
654
- );
655
- case Object:
656
- return this.generateObjectNode(
657
- ctx,
658
- id,
659
- current,
660
- false
661
- );
662
- case void 0:
663
- return this.generateObjectNode(
664
- ctx,
665
- id,
666
- current,
667
- true
668
- );
669
- case AggregateError:
670
- if (ctx.features & 1 /* AggregateError */) {
671
- return this.generateAggregateErrorNode(ctx, id, current);
672
- }
673
- return this.generateErrorNode(ctx, id, current);
674
- case Error:
675
- case EvalError:
676
- case RangeError:
677
- case ReferenceError:
678
- case SyntaxError:
679
- case TypeError:
680
- case URIError:
681
- return this.generateErrorNode(ctx, id, current);
682
- default:
683
- break;
684
- }
685
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
686
- return this.generateAggregateErrorNode(ctx, id, current);
687
- }
688
- if (current instanceof Error) {
689
- return this.generateErrorNode(ctx, id, current);
690
- }
691
- if (current instanceof Promise) {
692
- return this.generatePromiseNode(ctx, id, current);
693
- }
694
- if (Symbol.iterator in current) {
695
- return this.generateIterableNode(ctx, id, current);
696
- }
697
- if ("then" in current && typeof current.then === "function") {
698
- return this.generatePromiseNode(ctx, id, current);
699
- }
700
- throw new Error("Unsupported type");
546
+ if ("then" in current && typeof current.then === "function") {
547
+ return generatePromiseNode(ctx, id, current);
548
+ }
549
+ return {
550
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
551
+ i: id,
552
+ s: void 0,
553
+ l: void 0,
554
+ c: void 0,
555
+ m: void 0,
556
+ d: await generateProperties(ctx, current),
557
+ a: void 0,
558
+ n: void 0
559
+ };
560
+ }
561
+ async function generateAggregateErrorNode(ctx, id, current) {
562
+ const options = getErrorOptions(ctx, current);
563
+ const optionsNode = options ? await generateProperties(ctx, options) : void 0;
564
+ return {
565
+ t: 12 /* AggregateError */,
566
+ i: id,
567
+ s: void 0,
568
+ l: void 0,
569
+ c: void 0,
570
+ m: current.message,
571
+ d: optionsNode,
572
+ a: void 0,
573
+ n: await parse(ctx, current.errors)
574
+ };
575
+ }
576
+ async function generateErrorNode(ctx, id, current) {
577
+ const options = getErrorOptions(ctx, current);
578
+ const optionsNode = options ? await generateProperties(ctx, options) : void 0;
579
+ return {
580
+ t: 11 /* Error */,
581
+ i: id,
582
+ s: void 0,
583
+ l: void 0,
584
+ c: getErrorConstructor(current),
585
+ m: current.message,
586
+ d: optionsNode,
587
+ a: void 0,
588
+ n: void 0
589
+ };
590
+ }
591
+ async function parse(ctx, current) {
592
+ switch (typeof current) {
593
+ case "boolean":
594
+ return current ? TRUE_NODE : FALSE_NODE;
595
+ case "undefined":
596
+ return UNDEFINED_NODE;
597
+ case "string":
598
+ return createPrimitiveNode(quote(current));
599
+ case "number":
600
+ if (Object.is(current, -0)) {
601
+ return NEG_ZERO_NODE;
701
602
  }
702
- default:
703
- throw new Error("Unsupported type");
603
+ if (Object.is(current, Infinity)) {
604
+ return createPrimitiveNode("1/0");
605
+ }
606
+ if (Object.is(current, -Infinity)) {
607
+ return createPrimitiveNode("-1/0");
608
+ }
609
+ return createPrimitiveNode(current);
610
+ case "bigint":
611
+ return createBigIntNode(ctx, current);
612
+ case "object": {
613
+ if (!current) {
614
+ return NULL_NODE;
615
+ }
616
+ const id = createRef(ctx, current, true);
617
+ if (ctx.markedRefs.has(id)) {
618
+ return createReferenceNode(id);
619
+ }
620
+ if (Array.isArray(current)) {
621
+ return generateArrayNode(ctx, id, current);
622
+ }
623
+ switch (current.constructor) {
624
+ case Date:
625
+ return createDateNode(id, current);
626
+ case RegExp:
627
+ return createRegExpNode(id, current);
628
+ case Promise:
629
+ return generatePromiseNode(ctx, id, current);
630
+ case Int8Array:
631
+ case Int16Array:
632
+ case Int32Array:
633
+ case Uint8Array:
634
+ case Uint16Array:
635
+ case Uint32Array:
636
+ case Uint8ClampedArray:
637
+ case Float32Array:
638
+ case Float64Array:
639
+ return createTypedArrayNode(ctx, id, current);
640
+ case BigInt64Array:
641
+ case BigUint64Array:
642
+ return createBigIntTypedArrayNode(ctx, id, current);
643
+ case Map:
644
+ return generateMapNode(
645
+ ctx,
646
+ id,
647
+ current
648
+ );
649
+ case Set:
650
+ return generateSetNode(
651
+ ctx,
652
+ id,
653
+ current
654
+ );
655
+ case Object:
656
+ return generateObjectNode(
657
+ ctx,
658
+ id,
659
+ current,
660
+ false
661
+ );
662
+ case void 0:
663
+ return generateObjectNode(
664
+ ctx,
665
+ id,
666
+ current,
667
+ true
668
+ );
669
+ case AggregateError:
670
+ if (ctx.features & 1 /* AggregateError */) {
671
+ return generateAggregateErrorNode(ctx, id, current);
672
+ }
673
+ return generateErrorNode(ctx, id, current);
674
+ case Error:
675
+ case EvalError:
676
+ case RangeError:
677
+ case ReferenceError:
678
+ case SyntaxError:
679
+ case TypeError:
680
+ case URIError:
681
+ return generateErrorNode(ctx, id, current);
682
+ default:
683
+ break;
684
+ }
685
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
686
+ return generateAggregateErrorNode(ctx, id, current);
687
+ }
688
+ if (current instanceof Error) {
689
+ return generateErrorNode(ctx, id, current);
690
+ }
691
+ if (current instanceof Promise) {
692
+ return generatePromiseNode(ctx, id, current);
693
+ }
694
+ if (Symbol.iterator in current) {
695
+ return generateIterableNode(ctx, id, current);
696
+ }
697
+ if ("then" in current && typeof current.then === "function") {
698
+ return generatePromiseNode(ctx, id, current);
699
+ }
700
+ throw new Error("Unsupported type");
704
701
  }
702
+ default:
703
+ throw new Error("Unsupported type");
705
704
  }
706
- };
705
+ }
707
706
  async function parseAsync(ctx, current) {
708
- const result = await AsyncParser.parse(ctx, current);
707
+ const result = await parse(ctx, current);
709
708
  const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
710
709
  return [result, createRef(ctx, current, false), isObject];
711
710
  }
@@ -823,579 +822,580 @@ function isReferenceInStack(ctx, node) {
823
822
  return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
824
823
  }
825
824
  var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
826
- var SerovalSerializer = class {
827
- static serializeNodeList(ctx, node) {
828
- const size = node.a.length;
829
- let values = "";
830
- let item;
831
- let isHoley = false;
832
- for (let i = 0; i < size; i++) {
833
- if (i !== 0) {
834
- values += ",";
835
- }
836
- item = node.a[i];
837
- if (item) {
838
- if (isReferenceInStack(ctx, item)) {
839
- createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
840
- isHoley = true;
841
- } else {
842
- values += this.serialize(ctx, item);
843
- isHoley = false;
844
- }
845
- } else {
846
- isHoley = true;
847
- }
848
- }
849
- if (isHoley) {
825
+ function serializeNodeList(ctx, node) {
826
+ const size = node.a.length;
827
+ let values = "";
828
+ let item;
829
+ let isHoley = false;
830
+ for (let i = 0; i < size; i++) {
831
+ if (i !== 0) {
850
832
  values += ",";
851
833
  }
852
- return "[" + values + "]";
853
- }
854
- static serializeArray(ctx, node) {
855
- ctx.stack.push(node.i);
856
- const result = this.serializeNodeList(ctx, node);
857
- ctx.stack.pop();
858
- return assignRef(ctx, node.i, result);
859
- }
860
- static serializeObject(ctx, sourceID, node) {
861
- if (node.s === 0) {
862
- return "{}";
863
- }
864
- let result = "";
865
- ctx.stack.push(sourceID);
866
- let key;
867
- let val;
868
- let check;
869
- let isIdentifier;
870
- let refParam;
871
- let hasPrev = false;
872
- for (let i = 0; i < node.s; i++) {
873
- key = node.k[i];
874
- val = node.v[i];
875
- check = Number(key);
876
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
877
- if (isReferenceInStack(ctx, val)) {
878
- refParam = getRefParam(ctx, val.i);
879
- if (isIdentifier && Number.isNaN(check)) {
880
- createObjectAssign(ctx, sourceID, key, refParam);
881
- } else {
882
- createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
883
- }
834
+ item = node.a[i];
835
+ if (item) {
836
+ if (isReferenceInStack(ctx, item)) {
837
+ createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
838
+ isHoley = true;
884
839
  } else {
885
- if (hasPrev) {
886
- result += ",";
887
- }
888
- result += isIdentifier ? key : quote(key);
889
- result += ":" + this.serialize(ctx, val);
890
- hasPrev = true;
840
+ values += serializeTree(ctx, item);
841
+ isHoley = false;
891
842
  }
843
+ } else {
844
+ isHoley = true;
892
845
  }
893
- ctx.stack.pop();
894
- return "{" + result + "}";
895
846
  }
896
- static serializeWithObjectAssign(ctx, value, id, serialized) {
897
- const fields = this.serializeObject(ctx, id, value);
898
- if (fields !== "{}") {
899
- return "Object.assign(" + serialized + "," + fields + ")";
900
- }
901
- return serialized;
847
+ if (isHoley) {
848
+ values += ",";
902
849
  }
903
- static serializeAssignments(ctx, sourceID, node) {
904
- ctx.stack.push(sourceID);
905
- const mainAssignments = [];
906
- let parentStack;
907
- let refParam;
908
- let key;
909
- let check;
910
- let parentAssignment;
911
- let isIdentifier;
912
- for (let i = 0; i < node.s; i++) {
913
- parentStack = ctx.stack;
914
- ctx.stack = [];
915
- refParam = this.serialize(ctx, node.v[i]);
916
- ctx.stack = parentStack;
917
- key = node.k[i];
918
- check = Number(key);
919
- parentAssignment = ctx.assignments;
920
- ctx.assignments = mainAssignments;
921
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
850
+ return "[" + values + "]";
851
+ }
852
+ function serializeArray(ctx, node) {
853
+ ctx.stack.push(node.i);
854
+ const result = serializeNodeList(ctx, node);
855
+ ctx.stack.pop();
856
+ return assignRef(ctx, node.i, result);
857
+ }
858
+ function serializeObject(ctx, sourceID, node) {
859
+ if (node.s === 0) {
860
+ return "{}";
861
+ }
862
+ let result = "";
863
+ ctx.stack.push(sourceID);
864
+ let key;
865
+ let val;
866
+ let check;
867
+ let isIdentifier;
868
+ let refParam;
869
+ let hasPrev = false;
870
+ for (let i = 0; i < node.s; i++) {
871
+ key = node.k[i];
872
+ val = node.v[i];
873
+ check = Number(key);
874
+ isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
875
+ if (isReferenceInStack(ctx, val)) {
876
+ refParam = getRefParam(ctx, val.i);
922
877
  if (isIdentifier && Number.isNaN(check)) {
923
878
  createObjectAssign(ctx, sourceID, key, refParam);
924
879
  } else {
925
880
  createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
926
881
  }
927
- ctx.assignments = parentAssignment;
882
+ } else {
883
+ if (hasPrev) {
884
+ result += ",";
885
+ }
886
+ result += isIdentifier ? key : quote(key);
887
+ result += ":" + serializeTree(ctx, val);
888
+ hasPrev = true;
928
889
  }
929
- ctx.stack.pop();
930
- return resolveAssignments(mainAssignments);
931
890
  }
932
- static serializeDictionary(ctx, i, d, init) {
933
- if (d) {
934
- if (ctx.features & 128 /* ObjectAssign */) {
935
- init = this.serializeWithObjectAssign(ctx, d, i, init);
936
- } else {
937
- markRef(ctx, i);
938
- const assignments = this.serializeAssignments(ctx, i, d);
939
- if (assignments) {
940
- const ref = getRefParam(ctx, i);
941
- return "(" + assignRef(ctx, i, init) + "," + assignments + ref + ")";
942
- }
943
- }
891
+ ctx.stack.pop();
892
+ return "{" + result + "}";
893
+ }
894
+ function serializeWithObjectAssign(ctx, value, id, serialized) {
895
+ const fields = serializeObject(ctx, id, value);
896
+ if (fields !== "{}") {
897
+ return "Object.assign(" + serialized + "," + fields + ")";
898
+ }
899
+ return serialized;
900
+ }
901
+ function serializeAssignments(ctx, sourceID, node) {
902
+ ctx.stack.push(sourceID);
903
+ const mainAssignments = [];
904
+ let parentStack;
905
+ let refParam;
906
+ let key;
907
+ let check;
908
+ let parentAssignment;
909
+ let isIdentifier;
910
+ for (let i = 0; i < node.s; i++) {
911
+ parentStack = ctx.stack;
912
+ ctx.stack = [];
913
+ refParam = serializeTree(ctx, node.v[i]);
914
+ ctx.stack = parentStack;
915
+ key = node.k[i];
916
+ check = Number(key);
917
+ parentAssignment = ctx.assignments;
918
+ ctx.assignments = mainAssignments;
919
+ isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
920
+ if (isIdentifier && Number.isNaN(check)) {
921
+ createObjectAssign(ctx, sourceID, key, refParam);
922
+ } else {
923
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
944
924
  }
945
- return assignRef(ctx, i, init);
925
+ ctx.assignments = parentAssignment;
946
926
  }
947
- static serializeNullConstructor(ctx, node) {
948
- return this.serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
927
+ ctx.stack.pop();
928
+ return resolveAssignments(mainAssignments);
929
+ }
930
+ function serializeDictionary(ctx, i, d, init) {
931
+ if (d) {
932
+ if (ctx.features & 128 /* ObjectAssign */) {
933
+ init = serializeWithObjectAssign(ctx, d, i, init);
934
+ } else {
935
+ markRef(ctx, i);
936
+ const assignments = serializeAssignments(ctx, i, d);
937
+ if (assignments) {
938
+ const ref = getRefParam(ctx, i);
939
+ return "(" + assignRef(ctx, i, init) + "," + assignments + ref + ")";
940
+ }
941
+ }
949
942
  }
950
- static serializeSet(ctx, node) {
951
- let serialized = "new Set";
952
- const size = node.a.length;
953
- if (size) {
954
- let result = "";
955
- ctx.stack.push(node.i);
956
- let item;
957
- let hasPrev = false;
958
- for (let i = 0; i < size; i++) {
959
- item = node.a[i];
960
- if (isReferenceInStack(ctx, item)) {
961
- createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
962
- } else {
963
- if (hasPrev) {
964
- result += ",";
965
- }
966
- result += this.serialize(ctx, item);
967
- hasPrev = true;
943
+ return assignRef(ctx, i, init);
944
+ }
945
+ function serializeNullConstructor(ctx, node) {
946
+ return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
947
+ }
948
+ function serializeSet(ctx, node) {
949
+ let serialized = "new Set";
950
+ const size = node.a.length;
951
+ if (size) {
952
+ let result = "";
953
+ ctx.stack.push(node.i);
954
+ let item;
955
+ let hasPrev = false;
956
+ for (let i = 0; i < size; i++) {
957
+ item = node.a[i];
958
+ if (isReferenceInStack(ctx, item)) {
959
+ createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
960
+ } else {
961
+ if (hasPrev) {
962
+ result += ",";
968
963
  }
969
- }
970
- ctx.stack.pop();
971
- if (result) {
972
- serialized += "([" + result + "])";
964
+ result += serializeTree(ctx, item);
965
+ hasPrev = true;
973
966
  }
974
967
  }
975
- return assignRef(ctx, node.i, serialized);
968
+ ctx.stack.pop();
969
+ if (result) {
970
+ serialized += "([" + result + "])";
971
+ }
976
972
  }
977
- static serializeMap(ctx, node) {
978
- let serialized = "new Map";
979
- if (node.d.s) {
980
- let result = "";
981
- ctx.stack.push(node.i);
982
- let key;
983
- let val;
984
- let keyRef;
985
- let valueRef;
986
- let parent;
987
- let hasPrev = false;
988
- for (let i = 0; i < node.d.s; i++) {
989
- key = node.d.k[i];
990
- val = node.d.v[i];
991
- if (isReferenceInStack(ctx, key)) {
992
- keyRef = getRefParam(ctx, key.i);
993
- if (isReferenceInStack(ctx, val)) {
994
- valueRef = getRefParam(ctx, val.i);
995
- createMapSet(ctx, node.i, keyRef, valueRef);
996
- } else {
997
- parent = ctx.stack;
998
- ctx.stack = [];
999
- createMapSet(ctx, node.i, keyRef, this.serialize(ctx, val));
1000
- ctx.stack = parent;
1001
- }
1002
- } else if (isReferenceInStack(ctx, val)) {
973
+ return assignRef(ctx, node.i, serialized);
974
+ }
975
+ function serializeMap(ctx, node) {
976
+ let serialized = "new Map";
977
+ if (node.d.s) {
978
+ let result = "";
979
+ ctx.stack.push(node.i);
980
+ let key;
981
+ let val;
982
+ let keyRef;
983
+ let valueRef;
984
+ let parent;
985
+ let hasPrev = false;
986
+ for (let i = 0; i < node.d.s; i++) {
987
+ key = node.d.k[i];
988
+ val = node.d.v[i];
989
+ if (isReferenceInStack(ctx, key)) {
990
+ keyRef = getRefParam(ctx, key.i);
991
+ if (isReferenceInStack(ctx, val)) {
1003
992
  valueRef = getRefParam(ctx, val.i);
993
+ createMapSet(ctx, node.i, keyRef, valueRef);
994
+ } else {
1004
995
  parent = ctx.stack;
1005
996
  ctx.stack = [];
1006
- createMapSet(ctx, node.i, this.serialize(ctx, key), valueRef);
997
+ createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
1007
998
  ctx.stack = parent;
1008
- } else {
1009
- if (hasPrev) {
1010
- result += ",";
1011
- }
1012
- result += "[" + this.serialize(ctx, key) + "," + this.serialize(ctx, val) + "]";
1013
- hasPrev = true;
1014
999
  }
1015
- }
1016
- ctx.stack.pop();
1017
- if (result) {
1018
- serialized += "([" + result + "])";
1000
+ } else if (isReferenceInStack(ctx, val)) {
1001
+ valueRef = getRefParam(ctx, val.i);
1002
+ parent = ctx.stack;
1003
+ ctx.stack = [];
1004
+ createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
1005
+ ctx.stack = parent;
1006
+ } else {
1007
+ if (hasPrev) {
1008
+ result += ",";
1009
+ }
1010
+ result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
1011
+ hasPrev = true;
1019
1012
  }
1020
1013
  }
1021
- return assignRef(ctx, node.i, serialized);
1022
- }
1023
- static serializeAggregateError(ctx, node) {
1024
- ctx.stack.push(node.i);
1025
- const serialized = "new AggregateError(" + this.serialize(ctx, node.n) + "," + quote(node.m) + ")";
1026
1014
  ctx.stack.pop();
1027
- return this.serializeDictionary(ctx, node.i, node.d, serialized);
1028
- }
1029
- static serializeError(ctx, node) {
1030
- const serialized = "new " + node.c + "(" + quote(node.m) + ")";
1031
- return this.serializeDictionary(ctx, node.i, node.d, serialized);
1032
- }
1033
- static serializePromise(ctx, node) {
1034
- let serialized;
1035
- if (isReferenceInStack(ctx, node.n)) {
1036
- serialized = "Promise.resolve().then(()=>" + getRefParam(ctx, node.n.i) + ")";
1037
- } else {
1038
- ctx.stack.push(node.i);
1039
- const result = this.serialize(ctx, node.n);
1040
- ctx.stack.pop();
1041
- serialized = "Promise.resolve(" + result + ")";
1015
+ if (result) {
1016
+ serialized += "([" + result + "])";
1042
1017
  }
1043
- return assignRef(ctx, node.i, serialized);
1044
1018
  }
1045
- static serializeTypedArray(ctx, node) {
1046
- let args = "[" + node.s + "]";
1047
- if (node.l !== 0) {
1048
- args += "," + node.l.toString();
1049
- }
1050
- return assignRef(ctx, node.i, "new " + node.c + "(" + args + ")");
1051
- }
1052
- static serializeIterable(ctx, node) {
1053
- const parent = ctx.stack;
1054
- ctx.stack = [];
1055
- const values = this.serializeNodeList(ctx, node);
1056
- ctx.stack = parent;
1057
- let serialized = values;
1058
- if (ctx.features & 2 /* ArrayPrototypeValues */) {
1059
- serialized += ".values()";
1060
- } else {
1061
- serialized += "[Symbol.iterator]()";
1062
- }
1019
+ return assignRef(ctx, node.i, serialized);
1020
+ }
1021
+ function serializeAggregateError(ctx, node) {
1022
+ ctx.stack.push(node.i);
1023
+ const serialized = "new AggregateError(" + serializeTree(ctx, node.n) + "," + quote(node.m) + ")";
1024
+ ctx.stack.pop();
1025
+ return serializeDictionary(ctx, node.i, node.d, serialized);
1026
+ }
1027
+ function serializeError(ctx, node) {
1028
+ const serialized = "new " + node.c + "(" + quote(node.m) + ")";
1029
+ return serializeDictionary(ctx, node.i, node.d, serialized);
1030
+ }
1031
+ function serializePromise(ctx, node) {
1032
+ let serialized;
1033
+ if (isReferenceInStack(ctx, node.n)) {
1034
+ const ref = getRefParam(ctx, node.n.i);
1063
1035
  if (ctx.features & 4 /* ArrowFunction */) {
1064
- serialized = "{[Symbol.iterator]:()=>" + serialized + "}";
1065
- } else if (ctx.features & 64 /* MethodShorthand */) {
1066
- serialized = "{[Symbol.iterator](){return " + serialized + "}}";
1036
+ serialized = "Promise.resolve().then(()=>" + ref + ")";
1067
1037
  } else {
1068
- serialized = "{[Symbol.iterator]:function(){return " + serialized + "}}";
1038
+ serialized = "Promise.resolve().then(function(){return " + ref + "})";
1069
1039
  }
1070
- return this.serializeDictionary(ctx, node.i, node.d, serialized);
1040
+ } else {
1041
+ ctx.stack.push(node.i);
1042
+ const result = serializeTree(ctx, node.n);
1043
+ ctx.stack.pop();
1044
+ serialized = "Promise.resolve(" + result + ")";
1071
1045
  }
1072
- static serialize(ctx, node) {
1073
- switch (node.t) {
1074
- case 0 /* Primitive */:
1075
- return String(node.s);
1076
- case 1 /* BigInt */:
1077
- return node.s;
1078
- case 2 /* Reference */:
1079
- return getRefParam(ctx, node.i);
1080
- case 7 /* Array */:
1081
- return this.serializeArray(ctx, node);
1082
- case 8 /* Object */:
1083
- return assignRef(ctx, node.i, this.serializeObject(ctx, node.i, node.d));
1084
- case 9 /* NullConstructor */:
1085
- return this.serializeNullConstructor(ctx, node);
1086
- case 3 /* Date */:
1087
- return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
1088
- case 4 /* RegExp */:
1089
- return assignRef(ctx, node.i, node.s);
1090
- case 5 /* Set */:
1091
- return this.serializeSet(ctx, node);
1092
- case 6 /* Map */:
1093
- return this.serializeMap(ctx, node);
1094
- case 15 /* BigIntTypedArray */:
1095
- case 14 /* TypedArray */:
1096
- return this.serializeTypedArray(ctx, node);
1097
- case 12 /* AggregateError */:
1098
- return this.serializeAggregateError(ctx, node);
1099
- case 11 /* Error */:
1100
- return this.serializeError(ctx, node);
1101
- case 13 /* Iterable */:
1102
- return this.serializeIterable(ctx, node);
1103
- case 10 /* Promise */:
1104
- return this.serializePromise(ctx, node);
1105
- default:
1106
- throw new Error("Unsupported type");
1107
- }
1046
+ return assignRef(ctx, node.i, serialized);
1047
+ }
1048
+ function serializeTypedArray(ctx, node) {
1049
+ let args = "[" + node.s + "]";
1050
+ if (node.l !== 0) {
1051
+ args += "," + node.l.toString();
1108
1052
  }
1109
- };
1110
-
1111
- // src/tree/sync.ts
1112
- var SyncParser = class {
1113
- static generateNodeList(ctx, current) {
1114
- const size = current.length;
1115
- const nodes = new Array(size);
1116
- const deferred = new Array(size);
1117
- let item;
1118
- for (let i = 0; i < size; i++) {
1119
- if (i in current) {
1120
- item = current[i];
1121
- if (isIterable(item)) {
1122
- deferred[i] = item;
1123
- } else {
1124
- nodes[i] = this.parse(ctx, item);
1125
- }
1126
- }
1127
- }
1128
- for (let i = 0; i < size; i++) {
1129
- if (i in deferred) {
1130
- nodes[i] = this.parse(ctx, deferred[i]);
1131
- }
1132
- }
1133
- return nodes;
1053
+ return assignRef(ctx, node.i, "new " + node.c + "(" + args + ")");
1054
+ }
1055
+ function serializeIterable(ctx, node) {
1056
+ const parent = ctx.stack;
1057
+ ctx.stack = [];
1058
+ const values = serializeNodeList(ctx, node);
1059
+ ctx.stack = parent;
1060
+ let serialized = values;
1061
+ if (ctx.features & 2 /* ArrayPrototypeValues */) {
1062
+ serialized += ".values()";
1063
+ } else {
1064
+ serialized += "[Symbol.iterator]()";
1134
1065
  }
1135
- static generateArrayNode(ctx, id, current) {
1136
- return {
1137
- t: 7 /* Array */,
1138
- i: id,
1139
- s: void 0,
1140
- l: void 0,
1141
- c: void 0,
1142
- m: void 0,
1143
- d: void 0,
1144
- a: this.generateNodeList(ctx, current),
1145
- n: void 0
1146
- };
1066
+ if (ctx.features & 4 /* ArrowFunction */) {
1067
+ serialized = "{[Symbol.iterator]:()=>" + serialized + "}";
1068
+ } else if (ctx.features & 64 /* MethodShorthand */) {
1069
+ serialized = "{[Symbol.iterator](){return " + serialized + "}}";
1070
+ } else {
1071
+ serialized = "{[Symbol.iterator]:function(){return " + serialized + "}}";
1147
1072
  }
1148
- static generateMapNode(ctx, id, current) {
1149
- assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
1150
- const len = current.size;
1151
- const keyNodes = new Array(len);
1152
- const valueNodes = new Array(len);
1153
- const deferredKey = new Array(len);
1154
- const deferredValue = new Array(len);
1155
- let deferredSize = 0;
1156
- let nodeSize = 0;
1157
- for (const [key, value] of current.entries()) {
1158
- if (isIterable(key) || isIterable(value)) {
1159
- deferredKey[deferredSize] = key;
1160
- deferredValue[deferredSize] = value;
1161
- deferredSize++;
1162
- } else {
1163
- keyNodes[nodeSize] = this.parse(ctx, key);
1164
- valueNodes[nodeSize] = this.parse(ctx, value);
1165
- nodeSize++;
1166
- }
1167
- }
1168
- for (let i = 0; i < deferredSize; i++) {
1169
- keyNodes[nodeSize + i] = this.parse(ctx, deferredKey[i]);
1170
- valueNodes[nodeSize + i] = this.parse(ctx, deferredValue[i]);
1171
- }
1172
- return {
1173
- t: 6 /* Map */,
1174
- i: id,
1175
- s: void 0,
1176
- l: void 0,
1177
- c: void 0,
1178
- m: void 0,
1179
- d: { k: keyNodes, v: valueNodes, s: len },
1180
- a: void 0,
1181
- n: void 0
1182
- };
1073
+ return serializeDictionary(ctx, node.i, node.d, serialized);
1074
+ }
1075
+ function serializeTree(ctx, node) {
1076
+ switch (node.t) {
1077
+ case 0 /* Primitive */:
1078
+ return String(node.s);
1079
+ case 1 /* BigInt */:
1080
+ return node.s;
1081
+ case 2 /* Reference */:
1082
+ return getRefParam(ctx, node.i);
1083
+ case 7 /* Array */:
1084
+ return serializeArray(ctx, node);
1085
+ case 8 /* Object */:
1086
+ return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1087
+ case 9 /* NullConstructor */:
1088
+ return serializeNullConstructor(ctx, node);
1089
+ case 3 /* Date */:
1090
+ return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
1091
+ case 4 /* RegExp */:
1092
+ return assignRef(ctx, node.i, node.s);
1093
+ case 5 /* Set */:
1094
+ return serializeSet(ctx, node);
1095
+ case 6 /* Map */:
1096
+ return serializeMap(ctx, node);
1097
+ case 15 /* BigIntTypedArray */:
1098
+ case 14 /* TypedArray */:
1099
+ return serializeTypedArray(ctx, node);
1100
+ case 12 /* AggregateError */:
1101
+ return serializeAggregateError(ctx, node);
1102
+ case 11 /* Error */:
1103
+ return serializeError(ctx, node);
1104
+ case 13 /* Iterable */:
1105
+ return serializeIterable(ctx, node);
1106
+ case 10 /* Promise */:
1107
+ return serializePromise(ctx, node);
1108
+ default:
1109
+ throw new Error("Unsupported type");
1183
1110
  }
1184
- static generateSetNode(ctx, id, current) {
1185
- assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
1186
- const len = current.size;
1187
- const nodes = new Array(len);
1188
- const deferred = new Array(len);
1189
- let deferredSize = 0;
1190
- let nodeSize = 0;
1191
- for (const item of current.keys()) {
1111
+ }
1112
+
1113
+ // src/tree/sync.ts
1114
+ function generateNodeList2(ctx, current) {
1115
+ const size = current.length;
1116
+ const nodes = new Array(size);
1117
+ const deferred = new Array(size);
1118
+ let item;
1119
+ for (let i = 0; i < size; i++) {
1120
+ if (i in current) {
1121
+ item = current[i];
1192
1122
  if (isIterable(item)) {
1193
- deferred[deferredSize++] = item;
1123
+ deferred[i] = item;
1194
1124
  } else {
1195
- nodes[nodeSize++] = this.parse(ctx, item);
1125
+ nodes[i] = parse2(ctx, item);
1196
1126
  }
1197
1127
  }
1198
- for (let i = 0; i < deferredSize; i++) {
1199
- nodes[nodeSize + i] = this.parse(ctx, deferred[i]);
1128
+ }
1129
+ for (let i = 0; i < size; i++) {
1130
+ if (i in deferred) {
1131
+ nodes[i] = parse2(ctx, deferred[i]);
1200
1132
  }
1201
- return {
1202
- t: 5 /* Set */,
1203
- i: id,
1204
- s: void 0,
1205
- l: void 0,
1206
- c: void 0,
1207
- m: void 0,
1208
- d: void 0,
1209
- a: nodes,
1210
- n: void 0
1211
- };
1212
1133
  }
1213
- static generateProperties(ctx, properties) {
1214
- const keys = Object.keys(properties);
1215
- const size = keys.length;
1216
- const keyNodes = new Array(size);
1217
- const valueNodes = new Array(size);
1218
- const deferredKeys = new Array(size);
1219
- const deferredValues = new Array(size);
1220
- let deferredSize = 0;
1221
- let nodesSize = 0;
1222
- let item;
1223
- for (const key of keys) {
1224
- item = properties[key];
1225
- if (isIterable(item)) {
1226
- deferredKeys[deferredSize] = key;
1227
- deferredValues[deferredSize] = item;
1228
- deferredSize++;
1229
- } else {
1230
- keyNodes[nodesSize] = key;
1231
- valueNodes[nodesSize] = this.parse(ctx, item);
1232
- nodesSize++;
1233
- }
1134
+ return nodes;
1135
+ }
1136
+ function generateArrayNode2(ctx, id, current) {
1137
+ return {
1138
+ t: 7 /* Array */,
1139
+ i: id,
1140
+ s: void 0,
1141
+ l: void 0,
1142
+ c: void 0,
1143
+ m: void 0,
1144
+ d: void 0,
1145
+ a: generateNodeList2(ctx, current),
1146
+ n: void 0
1147
+ };
1148
+ }
1149
+ function generateMapNode2(ctx, id, current) {
1150
+ assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
1151
+ const len = current.size;
1152
+ const keyNodes = new Array(len);
1153
+ const valueNodes = new Array(len);
1154
+ const deferredKey = new Array(len);
1155
+ const deferredValue = new Array(len);
1156
+ let deferredSize = 0;
1157
+ let nodeSize = 0;
1158
+ for (const [key, value] of current.entries()) {
1159
+ if (isIterable(key) || isIterable(value)) {
1160
+ deferredKey[deferredSize] = key;
1161
+ deferredValue[deferredSize] = value;
1162
+ deferredSize++;
1163
+ } else {
1164
+ keyNodes[nodeSize] = parse2(ctx, key);
1165
+ valueNodes[nodeSize] = parse2(ctx, value);
1166
+ nodeSize++;
1234
1167
  }
1235
- for (let i = 0; i < deferredSize; i++) {
1236
- keyNodes[nodesSize + i] = deferredKeys[i];
1237
- valueNodes[nodesSize + i] = this.parse(ctx, deferredValues[i]);
1168
+ }
1169
+ for (let i = 0; i < deferredSize; i++) {
1170
+ keyNodes[nodeSize + i] = parse2(ctx, deferredKey[i]);
1171
+ valueNodes[nodeSize + i] = parse2(ctx, deferredValue[i]);
1172
+ }
1173
+ return {
1174
+ t: 6 /* Map */,
1175
+ i: id,
1176
+ s: void 0,
1177
+ l: void 0,
1178
+ c: void 0,
1179
+ m: void 0,
1180
+ d: { k: keyNodes, v: valueNodes, s: len },
1181
+ a: void 0,
1182
+ n: void 0
1183
+ };
1184
+ }
1185
+ function generateSetNode2(ctx, id, current) {
1186
+ assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
1187
+ const len = current.size;
1188
+ const nodes = new Array(len);
1189
+ const deferred = new Array(len);
1190
+ let deferredSize = 0;
1191
+ let nodeSize = 0;
1192
+ for (const item of current.keys()) {
1193
+ if (isIterable(item)) {
1194
+ deferred[deferredSize++] = item;
1195
+ } else {
1196
+ nodes[nodeSize++] = parse2(ctx, item);
1238
1197
  }
1239
- return {
1240
- k: keyNodes,
1241
- v: valueNodes,
1242
- s: size
1243
- };
1244
1198
  }
1245
- static generateIterableNode(ctx, id, current) {
1246
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
1247
- const options = getIterableOptions(current);
1248
- return {
1249
- t: 13 /* Iterable */,
1250
- i: id,
1251
- s: void 0,
1252
- l: void 0,
1253
- c: void 0,
1254
- m: void 0,
1255
- // Parse options first before the items
1256
- d: options ? this.generateProperties(ctx, options) : void 0,
1257
- a: this.generateNodeList(ctx, Array.from(current)),
1258
- n: void 0
1259
- };
1199
+ for (let i = 0; i < deferredSize; i++) {
1200
+ nodes[nodeSize + i] = parse2(ctx, deferred[i]);
1260
1201
  }
1261
- static generateObjectNode(ctx, id, current, empty) {
1262
- if (Symbol.iterator in current) {
1263
- return this.generateIterableNode(ctx, id, current);
1202
+ return {
1203
+ t: 5 /* Set */,
1204
+ i: id,
1205
+ s: void 0,
1206
+ l: void 0,
1207
+ c: void 0,
1208
+ m: void 0,
1209
+ d: void 0,
1210
+ a: nodes,
1211
+ n: void 0
1212
+ };
1213
+ }
1214
+ function generateProperties2(ctx, properties) {
1215
+ const keys = Object.keys(properties);
1216
+ const size = keys.length;
1217
+ const keyNodes = new Array(size);
1218
+ const valueNodes = new Array(size);
1219
+ const deferredKeys = new Array(size);
1220
+ const deferredValues = new Array(size);
1221
+ let deferredSize = 0;
1222
+ let nodesSize = 0;
1223
+ let item;
1224
+ for (const key of keys) {
1225
+ item = properties[key];
1226
+ if (isIterable(item)) {
1227
+ deferredKeys[deferredSize] = key;
1228
+ deferredValues[deferredSize] = item;
1229
+ deferredSize++;
1230
+ } else {
1231
+ keyNodes[nodesSize] = key;
1232
+ valueNodes[nodesSize] = parse2(ctx, item);
1233
+ nodesSize++;
1264
1234
  }
1265
- return {
1266
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1267
- i: id,
1268
- s: void 0,
1269
- l: void 0,
1270
- c: void 0,
1271
- m: void 0,
1272
- d: this.generateProperties(ctx, current),
1273
- a: void 0,
1274
- n: void 0
1275
- };
1276
1235
  }
1277
- static generateAggregateErrorNode(ctx, id, current) {
1278
- const options = getErrorOptions(ctx, current);
1279
- const optionsNode = options ? this.generateProperties(ctx, options) : void 0;
1280
- return {
1281
- t: 12 /* AggregateError */,
1282
- i: id,
1283
- s: void 0,
1284
- l: void 0,
1285
- c: void 0,
1286
- m: current.message,
1287
- d: optionsNode,
1288
- a: void 0,
1289
- n: this.parse(ctx, current.errors)
1290
- };
1236
+ for (let i = 0; i < deferredSize; i++) {
1237
+ keyNodes[nodesSize + i] = deferredKeys[i];
1238
+ valueNodes[nodesSize + i] = parse2(ctx, deferredValues[i]);
1291
1239
  }
1292
- static generateErrorNode(ctx, id, current) {
1293
- const options = getErrorOptions(ctx, current);
1294
- const optionsNode = options ? this.generateProperties(ctx, options) : void 0;
1295
- return {
1296
- t: 11 /* Error */,
1297
- i: id,
1298
- s: void 0,
1299
- l: void 0,
1300
- c: getErrorConstructor(current),
1301
- m: current.message,
1302
- d: optionsNode,
1303
- a: void 0,
1304
- n: void 0
1305
- };
1240
+ return {
1241
+ k: keyNodes,
1242
+ v: valueNodes,
1243
+ s: size
1244
+ };
1245
+ }
1246
+ function generateIterableNode2(ctx, id, current) {
1247
+ assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
1248
+ const options = getIterableOptions(current);
1249
+ return {
1250
+ t: 13 /* Iterable */,
1251
+ i: id,
1252
+ s: void 0,
1253
+ l: void 0,
1254
+ c: void 0,
1255
+ m: void 0,
1256
+ // Parse options first before the items
1257
+ d: options ? generateProperties2(ctx, options) : void 0,
1258
+ a: generateNodeList2(ctx, Array.from(current)),
1259
+ n: void 0
1260
+ };
1261
+ }
1262
+ function generateObjectNode2(ctx, id, current, empty) {
1263
+ if (Symbol.iterator in current) {
1264
+ return generateIterableNode2(ctx, id, current);
1306
1265
  }
1307
- static parse(ctx, current) {
1308
- switch (typeof current) {
1309
- case "boolean":
1310
- return current ? TRUE_NODE : FALSE_NODE;
1311
- case "undefined":
1312
- return UNDEFINED_NODE;
1313
- case "string":
1314
- return createPrimitiveNode(quote(current));
1315
- case "number":
1316
- if (Object.is(current, -0)) {
1317
- return NEG_ZERO_NODE;
1318
- }
1319
- if (Object.is(current, Infinity)) {
1320
- return createPrimitiveNode("1/0");
1321
- }
1322
- if (Object.is(current, -Infinity)) {
1323
- return createPrimitiveNode("-1/0");
1324
- }
1325
- return createPrimitiveNode(current);
1326
- case "bigint":
1327
- return createBigIntNode(ctx, current);
1328
- case "object": {
1329
- if (!current) {
1330
- return NULL_NODE;
1331
- }
1332
- const id = createRef(ctx, current, true);
1333
- if (ctx.markedRefs.has(id)) {
1334
- return createReferenceNode(id);
1335
- }
1336
- if (Array.isArray(current)) {
1337
- return this.generateArrayNode(ctx, id, current);
1338
- }
1339
- switch (current.constructor) {
1340
- case Date:
1341
- return createDateNode(id, current);
1342
- case RegExp:
1343
- return createRegExpNode(id, current);
1344
- case Int8Array:
1345
- case Int16Array:
1346
- case Int32Array:
1347
- case Uint8Array:
1348
- case Uint16Array:
1349
- case Uint32Array:
1350
- case Uint8ClampedArray:
1351
- case Float32Array:
1352
- case Float64Array:
1353
- return createTypedArrayNode(ctx, id, current);
1354
- case BigInt64Array:
1355
- case BigUint64Array:
1356
- return createBigIntTypedArrayNode(ctx, id, current);
1357
- case Map:
1358
- return this.generateMapNode(ctx, id, current);
1359
- case Set:
1360
- return this.generateSetNode(ctx, id, current);
1361
- case Object:
1362
- return this.generateObjectNode(ctx, id, current, false);
1363
- case void 0:
1364
- return this.generateObjectNode(ctx, id, current, true);
1365
- case AggregateError:
1366
- if (ctx.features & 1 /* AggregateError */) {
1367
- return this.generateAggregateErrorNode(ctx, id, current);
1368
- }
1369
- return this.generateErrorNode(ctx, id, current);
1370
- case Error:
1371
- case EvalError:
1372
- case RangeError:
1373
- case ReferenceError:
1374
- case SyntaxError:
1375
- case TypeError:
1376
- case URIError:
1377
- return this.generateErrorNode(ctx, id, current);
1378
- default:
1379
- break;
1380
- }
1381
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1382
- return this.generateAggregateErrorNode(ctx, id, current);
1383
- }
1384
- if (current instanceof Error) {
1385
- return this.generateErrorNode(ctx, id, current);
1386
- }
1387
- if (Symbol.iterator in current) {
1388
- return this.generateIterableNode(ctx, id, current);
1389
- }
1390
- throw new Error("Unsupported type");
1266
+ return {
1267
+ t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1268
+ i: id,
1269
+ s: void 0,
1270
+ l: void 0,
1271
+ c: void 0,
1272
+ m: void 0,
1273
+ d: generateProperties2(ctx, current),
1274
+ a: void 0,
1275
+ n: void 0
1276
+ };
1277
+ }
1278
+ function generateAggregateErrorNode2(ctx, id, current) {
1279
+ const options = getErrorOptions(ctx, current);
1280
+ const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1281
+ return {
1282
+ t: 12 /* AggregateError */,
1283
+ i: id,
1284
+ s: void 0,
1285
+ l: void 0,
1286
+ c: void 0,
1287
+ m: current.message,
1288
+ d: optionsNode,
1289
+ a: void 0,
1290
+ n: parse2(ctx, current.errors)
1291
+ };
1292
+ }
1293
+ function generateErrorNode2(ctx, id, current) {
1294
+ const options = getErrorOptions(ctx, current);
1295
+ const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1296
+ return {
1297
+ t: 11 /* Error */,
1298
+ i: id,
1299
+ s: void 0,
1300
+ l: void 0,
1301
+ c: getErrorConstructor(current),
1302
+ m: current.message,
1303
+ d: optionsNode,
1304
+ a: void 0,
1305
+ n: void 0
1306
+ };
1307
+ }
1308
+ function parse2(ctx, current) {
1309
+ switch (typeof current) {
1310
+ case "boolean":
1311
+ return current ? TRUE_NODE : FALSE_NODE;
1312
+ case "undefined":
1313
+ return UNDEFINED_NODE;
1314
+ case "string":
1315
+ return createPrimitiveNode(quote(current));
1316
+ case "number":
1317
+ if (Object.is(current, -0)) {
1318
+ return NEG_ZERO_NODE;
1391
1319
  }
1392
- default:
1393
- throw new Error("Unsupported type");
1320
+ if (Object.is(current, Infinity)) {
1321
+ return createPrimitiveNode("1/0");
1322
+ }
1323
+ if (Object.is(current, -Infinity)) {
1324
+ return createPrimitiveNode("-1/0");
1325
+ }
1326
+ return createPrimitiveNode(current);
1327
+ case "bigint":
1328
+ return createBigIntNode(ctx, current);
1329
+ case "object": {
1330
+ if (!current) {
1331
+ return NULL_NODE;
1332
+ }
1333
+ const id = createRef(ctx, current, true);
1334
+ if (ctx.markedRefs.has(id)) {
1335
+ return createReferenceNode(id);
1336
+ }
1337
+ if (Array.isArray(current)) {
1338
+ return generateArrayNode2(ctx, id, current);
1339
+ }
1340
+ switch (current.constructor) {
1341
+ case Date:
1342
+ return createDateNode(id, current);
1343
+ case RegExp:
1344
+ return createRegExpNode(id, current);
1345
+ case Int8Array:
1346
+ case Int16Array:
1347
+ case Int32Array:
1348
+ case Uint8Array:
1349
+ case Uint16Array:
1350
+ case Uint32Array:
1351
+ case Uint8ClampedArray:
1352
+ case Float32Array:
1353
+ case Float64Array:
1354
+ return createTypedArrayNode(ctx, id, current);
1355
+ case BigInt64Array:
1356
+ case BigUint64Array:
1357
+ return createBigIntTypedArrayNode(ctx, id, current);
1358
+ case Map:
1359
+ return generateMapNode2(ctx, id, current);
1360
+ case Set:
1361
+ return generateSetNode2(ctx, id, current);
1362
+ case Object:
1363
+ return generateObjectNode2(ctx, id, current, false);
1364
+ case void 0:
1365
+ return generateObjectNode2(ctx, id, current, true);
1366
+ case AggregateError:
1367
+ if (ctx.features & 1 /* AggregateError */) {
1368
+ return generateAggregateErrorNode2(ctx, id, current);
1369
+ }
1370
+ return generateErrorNode2(ctx, id, current);
1371
+ case Error:
1372
+ case EvalError:
1373
+ case RangeError:
1374
+ case ReferenceError:
1375
+ case SyntaxError:
1376
+ case TypeError:
1377
+ case URIError:
1378
+ return generateErrorNode2(ctx, id, current);
1379
+ default:
1380
+ break;
1381
+ }
1382
+ if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1383
+ return generateAggregateErrorNode2(ctx, id, current);
1384
+ }
1385
+ if (current instanceof Error) {
1386
+ return generateErrorNode2(ctx, id, current);
1387
+ }
1388
+ if (Symbol.iterator in current) {
1389
+ return generateIterableNode2(ctx, id, current);
1390
+ }
1391
+ throw new Error("Unsupported type");
1394
1392
  }
1393
+ default:
1394
+ throw new Error("Unsupported type");
1395
1395
  }
1396
- };
1396
+ }
1397
1397
  function parseSync(ctx, current) {
1398
- const result = SyncParser.parse(ctx, current);
1398
+ const result = parse2(ctx, current);
1399
1399
  const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
1400
1400
  return [result, createRef(ctx, current, false), isObject];
1401
1401
  }
@@ -1428,14 +1428,14 @@ function serialize(source, options) {
1428
1428
  const ctx = createParserContext(options);
1429
1429
  const [tree, rootID, isObject] = parseSync(ctx, source);
1430
1430
  const serial = createSerializationContext(ctx);
1431
- const result = SerovalSerializer.serialize(serial, tree);
1431
+ const result = serializeTree(serial, tree);
1432
1432
  return finalize(serial, rootID, isObject, result);
1433
1433
  }
1434
1434
  async function serializeAsync(source, options) {
1435
1435
  const ctx = createParserContext(options);
1436
1436
  const [tree, rootID, isObject] = await parseAsync(ctx, source);
1437
1437
  const serial = createSerializationContext(ctx);
1438
- const result = SerovalSerializer.serialize(serial, tree);
1438
+ const result = serializeTree(serial, tree);
1439
1439
  return finalize(serial, rootID, isObject, result);
1440
1440
  }
1441
1441
  function deserialize(source) {
@@ -1469,7 +1469,7 @@ function compileJSON(source) {
1469
1469
  features: parsed.f,
1470
1470
  markedRefs: parsed.m
1471
1471
  });
1472
- const result = SerovalSerializer.serialize(serial, parsed.t);
1472
+ const result = serializeTree(serial, parsed.t);
1473
1473
  return finalize(serial, parsed.r, parsed.i, result);
1474
1474
  }
1475
1475
  function fromJSON(source) {