seroval 0.4.0-alpha.11 → 0.4.0-alpha.12
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.
- package/dist/cjs/development/index.cjs +587 -570
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +589 -570
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +2 -2
- package/package.json +2 -2
- package/src/tree/async.ts +354 -359
- package/src/tree/sync.ts +308 -319
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => {
|
|
21
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
// src/index.ts
|
|
21
26
|
var src_exports = {};
|
|
@@ -573,317 +578,323 @@ function isIterable(value) {
|
|
|
573
578
|
}
|
|
574
579
|
|
|
575
580
|
// src/tree/async.ts
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
nodesSize++;
|
|
581
|
+
var AsyncParser = class {
|
|
582
|
+
constructor(ctx) {
|
|
583
|
+
__publicField(this, "ctx");
|
|
584
|
+
this.ctx = ctx;
|
|
585
|
+
}
|
|
586
|
+
async generateNodeList(current) {
|
|
587
|
+
const size = current.length;
|
|
588
|
+
const nodes = new Array(size);
|
|
589
|
+
const deferred = new Array(size);
|
|
590
|
+
let item;
|
|
591
|
+
for (let i = 0; i < size; i++) {
|
|
592
|
+
if (i in current) {
|
|
593
|
+
item = current[i];
|
|
594
|
+
if (isIterable(item)) {
|
|
595
|
+
deferred[i] = item;
|
|
596
|
+
} else {
|
|
597
|
+
nodes[i] = await this.parse(item);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
596
600
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
return {
|
|
603
|
-
k: keyNodes,
|
|
604
|
-
v: valueNodes,
|
|
605
|
-
s: size
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
async function generateSetNode(ctx, current, id) {
|
|
609
|
-
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
610
|
-
const len = current.size;
|
|
611
|
-
const nodes = new Array(len);
|
|
612
|
-
const deferred = new Array(len);
|
|
613
|
-
let deferredSize = 0;
|
|
614
|
-
let nodeSize = 0;
|
|
615
|
-
for (const item of current.keys()) {
|
|
616
|
-
if (isIterable(item)) {
|
|
617
|
-
deferred[deferredSize++] = item;
|
|
618
|
-
} else {
|
|
619
|
-
nodes[nodeSize++] = await generateTreeAsync(ctx, item);
|
|
601
|
+
for (let i = 0; i < size; i++) {
|
|
602
|
+
if (i in deferred) {
|
|
603
|
+
nodes[i] = await this.parse(deferred[i]);
|
|
604
|
+
}
|
|
620
605
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
606
|
+
return nodes;
|
|
607
|
+
}
|
|
608
|
+
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
|
+
};
|
|
620
|
+
}
|
|
621
|
+
async generateMapNode(id, current) {
|
|
622
|
+
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
623
|
+
const len = current.size;
|
|
624
|
+
const keyNodes = new Array(len);
|
|
625
|
+
const valueNodes = new Array(len);
|
|
626
|
+
const deferredKey = new Array(len);
|
|
627
|
+
const deferredValue = new Array(len);
|
|
628
|
+
let deferredSize = 0;
|
|
629
|
+
let nodeSize = 0;
|
|
630
|
+
for (const [key, value] of current.entries()) {
|
|
631
|
+
if (isIterable(key) || isIterable(value)) {
|
|
632
|
+
deferredKey[deferredSize] = key;
|
|
633
|
+
deferredValue[deferredSize] = value;
|
|
634
|
+
deferredSize++;
|
|
635
|
+
} else {
|
|
636
|
+
keyNodes[nodeSize] = await this.parse(key);
|
|
637
|
+
valueNodes[nodeSize] = await this.parse(value);
|
|
638
|
+
nodeSize++;
|
|
639
|
+
}
|
|
655
640
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
item = current[i];
|
|
641
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
642
|
+
keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
|
|
643
|
+
valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
|
|
644
|
+
}
|
|
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
|
+
};
|
|
656
|
+
}
|
|
657
|
+
async generateSetNode(id, current) {
|
|
658
|
+
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
659
|
+
const len = current.size;
|
|
660
|
+
const nodes = new Array(len);
|
|
661
|
+
const deferred = new Array(len);
|
|
662
|
+
let deferredSize = 0;
|
|
663
|
+
let nodeSize = 0;
|
|
664
|
+
for (const item of current.keys()) {
|
|
681
665
|
if (isIterable(item)) {
|
|
682
|
-
deferred[
|
|
666
|
+
deferred[deferredSize++] = item;
|
|
683
667
|
} else {
|
|
684
|
-
nodes[
|
|
668
|
+
nodes[nodeSize++] = await this.parse(item);
|
|
685
669
|
}
|
|
686
670
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
if (i in deferred) {
|
|
690
|
-
nodes[i] = await generateTreeAsync(ctx, deferred[i]);
|
|
671
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
672
|
+
nodes[nodeSize + i] = await this.parse(deferred[i]);
|
|
691
673
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
const options = getErrorOptions(current);
|
|
725
|
-
const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
|
|
726
|
-
return {
|
|
727
|
-
t: 11 /* Error */,
|
|
728
|
-
i: id,
|
|
729
|
-
a: void 0,
|
|
730
|
-
s: void 0,
|
|
731
|
-
l: void 0,
|
|
732
|
-
m: current.message,
|
|
733
|
-
c: getErrorConstructor(current),
|
|
734
|
-
d: optionsNode,
|
|
735
|
-
n: void 0
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
async function generateIterableNode(ctx, current, id) {
|
|
739
|
-
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
740
|
-
const options = getIterableOptions(current);
|
|
741
|
-
return {
|
|
742
|
-
t: 13 /* Iterable */,
|
|
743
|
-
i: id,
|
|
744
|
-
s: void 0,
|
|
745
|
-
l: void 0,
|
|
746
|
-
m: void 0,
|
|
747
|
-
c: void 0,
|
|
748
|
-
// Parse options first before the items
|
|
749
|
-
d: options ? await serializePropertiesAsync(ctx, options) : void 0,
|
|
750
|
-
a: await generateNodeList(ctx, Array.from(current)),
|
|
751
|
-
n: void 0
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
async function generateObjectNode(ctx, current, id, empty) {
|
|
755
|
-
if (Symbol.iterator in current) {
|
|
756
|
-
return generateIterableNode(ctx, current, id);
|
|
757
|
-
}
|
|
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);
|
|
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
|
+
};
|
|
685
|
+
}
|
|
686
|
+
async generateProperties(properties) {
|
|
687
|
+
const keys = Object.keys(properties);
|
|
688
|
+
const size = keys.length;
|
|
689
|
+
const keyNodes = new Array(size);
|
|
690
|
+
const valueNodes = new Array(size);
|
|
691
|
+
const deferredKeys = new Array(size);
|
|
692
|
+
const deferredValues = new Array(size);
|
|
693
|
+
let deferredSize = 0;
|
|
694
|
+
let nodesSize = 0;
|
|
695
|
+
let item;
|
|
696
|
+
for (const key of keys) {
|
|
697
|
+
item = properties[key];
|
|
698
|
+
if (isIterable(item)) {
|
|
699
|
+
deferredKeys[deferredSize] = key;
|
|
700
|
+
deferredValues[deferredSize] = item;
|
|
701
|
+
deferredSize++;
|
|
702
|
+
} else {
|
|
703
|
+
keyNodes[nodesSize] = key;
|
|
704
|
+
valueNodes[nodesSize] = await this.parse(item);
|
|
705
|
+
nodesSize++;
|
|
875
706
|
}
|
|
876
|
-
|
|
877
|
-
|
|
707
|
+
}
|
|
708
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
709
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
710
|
+
valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
k: keyNodes,
|
|
714
|
+
v: valueNodes,
|
|
715
|
+
s: size
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
async generateIterableNode(id, current) {
|
|
719
|
+
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
720
|
+
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,
|
|
728
|
+
// 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
|
+
};
|
|
733
|
+
}
|
|
734
|
+
async generatePromiseNode(id, current) {
|
|
735
|
+
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
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
async generateObjectNode(id, current, empty) {
|
|
750
|
+
if (Symbol.iterator in current) {
|
|
751
|
+
return this.generateIterableNode(id, current);
|
|
752
|
+
}
|
|
753
|
+
if ("then" in current && typeof current.then === "function") {
|
|
754
|
+
return this.generatePromiseNode(id, current);
|
|
755
|
+
}
|
|
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
|
+
};
|
|
767
|
+
}
|
|
768
|
+
async generateAggregateErrorNode(id, current) {
|
|
769
|
+
const options = getErrorOptions(current);
|
|
770
|
+
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
|
+
};
|
|
782
|
+
}
|
|
783
|
+
async generateErrorNode(id, current) {
|
|
784
|
+
const options = getErrorOptions(current);
|
|
785
|
+
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
|
+
};
|
|
797
|
+
}
|
|
798
|
+
async parse(current) {
|
|
799
|
+
switch (typeof current) {
|
|
800
|
+
case "boolean":
|
|
801
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
802
|
+
case "undefined":
|
|
803
|
+
return UNDEFINED_NODE;
|
|
804
|
+
case "string":
|
|
805
|
+
return createPrimitiveNode(quote(current));
|
|
806
|
+
case "number":
|
|
807
|
+
if (Object.is(current, -0)) {
|
|
808
|
+
return NEG_ZERO_NODE;
|
|
809
|
+
}
|
|
810
|
+
if (Object.is(current, Infinity)) {
|
|
811
|
+
return createPrimitiveNode("1/0");
|
|
812
|
+
}
|
|
813
|
+
if (Object.is(current, -Infinity)) {
|
|
814
|
+
return createPrimitiveNode("-1/0");
|
|
815
|
+
}
|
|
816
|
+
return createPrimitiveNode(current);
|
|
817
|
+
case "bigint":
|
|
818
|
+
return createBigIntNode(this.ctx, current);
|
|
819
|
+
case "object": {
|
|
820
|
+
if (!current) {
|
|
821
|
+
return NULL_NODE;
|
|
822
|
+
}
|
|
823
|
+
const id = createRef(this.ctx, current, true);
|
|
824
|
+
if (this.ctx.markedRefs[id]) {
|
|
825
|
+
return createReferenceNode(id);
|
|
826
|
+
}
|
|
827
|
+
if (Array.isArray(current)) {
|
|
828
|
+
return this.generateArrayNode(id, current);
|
|
829
|
+
}
|
|
830
|
+
switch (current.constructor) {
|
|
831
|
+
case Date:
|
|
832
|
+
return createDateNode(id, current);
|
|
833
|
+
case RegExp:
|
|
834
|
+
return createRegExpNode(id, current);
|
|
835
|
+
case Promise:
|
|
836
|
+
return this.generatePromiseNode(id, current);
|
|
837
|
+
case Int8Array:
|
|
838
|
+
case Int16Array:
|
|
839
|
+
case Int32Array:
|
|
840
|
+
case Uint8Array:
|
|
841
|
+
case Uint16Array:
|
|
842
|
+
case Uint32Array:
|
|
843
|
+
case Uint8ClampedArray:
|
|
844
|
+
case Float32Array:
|
|
845
|
+
case Float64Array:
|
|
846
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
847
|
+
case BigInt64Array:
|
|
848
|
+
case BigUint64Array:
|
|
849
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
850
|
+
case Map:
|
|
851
|
+
return this.generateMapNode(id, current);
|
|
852
|
+
case Set:
|
|
853
|
+
return this.generateSetNode(id, current);
|
|
854
|
+
case Object:
|
|
855
|
+
return this.generateObjectNode(id, current, false);
|
|
856
|
+
case void 0:
|
|
857
|
+
return this.generateObjectNode(id, current, true);
|
|
858
|
+
case AggregateError:
|
|
859
|
+
if (this.ctx.features & 1 /* AggregateError */) {
|
|
860
|
+
return this.generateAggregateErrorNode(id, current);
|
|
861
|
+
}
|
|
862
|
+
return this.generateErrorNode(id, current);
|
|
863
|
+
case Error:
|
|
864
|
+
case EvalError:
|
|
865
|
+
case RangeError:
|
|
866
|
+
case ReferenceError:
|
|
867
|
+
case SyntaxError:
|
|
868
|
+
case TypeError:
|
|
869
|
+
case URIError:
|
|
870
|
+
return this.generateErrorNode(id, current);
|
|
871
|
+
default:
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
|
|
875
|
+
return this.generateAggregateErrorNode(id, current);
|
|
876
|
+
}
|
|
877
|
+
if (current instanceof Error) {
|
|
878
|
+
return this.generateErrorNode(id, current);
|
|
879
|
+
}
|
|
880
|
+
if (current instanceof Promise) {
|
|
881
|
+
return this.generatePromiseNode(id, current);
|
|
882
|
+
}
|
|
883
|
+
if (Symbol.iterator in current) {
|
|
884
|
+
return this.generateIterableNode(id, current);
|
|
885
|
+
}
|
|
886
|
+
if ("then" in current && typeof current.then === "function") {
|
|
887
|
+
return this.generatePromiseNode(id, current);
|
|
888
|
+
}
|
|
889
|
+
throw new Error("Unsupported type");
|
|
878
890
|
}
|
|
879
|
-
|
|
891
|
+
default:
|
|
892
|
+
throw new Error("Unsupported type");
|
|
880
893
|
}
|
|
881
|
-
default:
|
|
882
|
-
throw new Error("Unsupported type");
|
|
883
894
|
}
|
|
884
|
-
}
|
|
895
|
+
};
|
|
885
896
|
async function parseAsync(ctx, current) {
|
|
886
|
-
const result = await
|
|
897
|
+
const result = await new AsyncParser(ctx).parse(current);
|
|
887
898
|
const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
|
|
888
899
|
return [result, createRef(ctx, current, false), isObject];
|
|
889
900
|
}
|
|
@@ -1270,291 +1281,297 @@ function serializeTree(ctx, node) {
|
|
|
1270
1281
|
}
|
|
1271
1282
|
|
|
1272
1283
|
// src/tree/sync.ts
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
nodesSize++;
|
|
1284
|
+
var SyncParser = class {
|
|
1285
|
+
constructor(ctx) {
|
|
1286
|
+
__publicField(this, "ctx");
|
|
1287
|
+
this.ctx = ctx;
|
|
1288
|
+
}
|
|
1289
|
+
generateNodeList(current) {
|
|
1290
|
+
const size = current.length;
|
|
1291
|
+
const nodes = new Array(size);
|
|
1292
|
+
const deferred = new Array(size);
|
|
1293
|
+
let item;
|
|
1294
|
+
for (let i = 0; i < size; i++) {
|
|
1295
|
+
if (i in current) {
|
|
1296
|
+
item = current[i];
|
|
1297
|
+
if (isIterable(item)) {
|
|
1298
|
+
deferred[i] = item;
|
|
1299
|
+
} else {
|
|
1300
|
+
nodes[i] = this.parse(item);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1293
1303
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
return {
|
|
1300
|
-
k: keyNodes,
|
|
1301
|
-
v: valueNodes,
|
|
1302
|
-
s: size
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
function generateSetNode2(ctx, current, id) {
|
|
1306
|
-
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
1307
|
-
const len = current.size;
|
|
1308
|
-
const nodes = new Array(len);
|
|
1309
|
-
const deferred = new Array(len);
|
|
1310
|
-
let deferredSize = 0;
|
|
1311
|
-
let nodeSize = 0;
|
|
1312
|
-
for (const item of current.keys()) {
|
|
1313
|
-
if (isIterable(item)) {
|
|
1314
|
-
deferred[deferredSize++] = item;
|
|
1315
|
-
} else {
|
|
1316
|
-
nodes[nodeSize++] = generateTreeSync(ctx, item);
|
|
1304
|
+
for (let i = 0; i < size; i++) {
|
|
1305
|
+
if (i in deferred) {
|
|
1306
|
+
nodes[i] = this.parse(deferred[i]);
|
|
1307
|
+
}
|
|
1317
1308
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1309
|
+
return nodes;
|
|
1310
|
+
}
|
|
1311
|
+
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
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
generateMapNode(id, current) {
|
|
1325
|
+
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
1326
|
+
const len = current.size;
|
|
1327
|
+
const keyNodes = new Array(len);
|
|
1328
|
+
const valueNodes = new Array(len);
|
|
1329
|
+
const deferredKey = new Array(len);
|
|
1330
|
+
const deferredValue = new Array(len);
|
|
1331
|
+
let deferredSize = 0;
|
|
1332
|
+
let nodeSize = 0;
|
|
1333
|
+
for (const [key, value] of current.entries()) {
|
|
1334
|
+
if (isIterable(key) || isIterable(value)) {
|
|
1335
|
+
deferredKey[deferredSize] = key;
|
|
1336
|
+
deferredValue[deferredSize] = value;
|
|
1337
|
+
deferredSize++;
|
|
1338
|
+
} else {
|
|
1339
|
+
keyNodes[nodeSize] = this.parse(key);
|
|
1340
|
+
valueNodes[nodeSize] = this.parse(value);
|
|
1341
|
+
nodeSize++;
|
|
1342
|
+
}
|
|
1352
1343
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
item = current[i];
|
|
1344
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1345
|
+
keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
|
|
1346
|
+
valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
|
|
1347
|
+
}
|
|
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
|
+
}
|
|
1360
|
+
generateSetNode(id, current) {
|
|
1361
|
+
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
1362
|
+
const len = current.size;
|
|
1363
|
+
const nodes = new Array(len);
|
|
1364
|
+
const deferred = new Array(len);
|
|
1365
|
+
let deferredSize = 0;
|
|
1366
|
+
let nodeSize = 0;
|
|
1367
|
+
for (const item of current.keys()) {
|
|
1378
1368
|
if (isIterable(item)) {
|
|
1379
|
-
deferred[
|
|
1369
|
+
deferred[deferredSize++] = item;
|
|
1380
1370
|
} else {
|
|
1381
|
-
nodes[
|
|
1371
|
+
nodes[nodeSize++] = this.parse(item);
|
|
1382
1372
|
}
|
|
1383
1373
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
if (i in deferred) {
|
|
1387
|
-
nodes[i] = generateTreeSync(ctx, deferred[i]);
|
|
1374
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1375
|
+
nodes[nodeSize + i] = this.parse(deferred[i]);
|
|
1388
1376
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
const options = getErrorOptions(current);
|
|
1422
|
-
const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
|
|
1423
|
-
return {
|
|
1424
|
-
t: 11 /* Error */,
|
|
1425
|
-
i: id,
|
|
1426
|
-
a: void 0,
|
|
1427
|
-
s: void 0,
|
|
1428
|
-
l: void 0,
|
|
1429
|
-
m: current.message,
|
|
1430
|
-
c: getErrorConstructor(current),
|
|
1431
|
-
d: optionsNode,
|
|
1432
|
-
n: void 0
|
|
1433
|
-
};
|
|
1434
|
-
}
|
|
1435
|
-
function generateIterableNode2(ctx, current, id) {
|
|
1436
|
-
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1437
|
-
const options = getIterableOptions(current);
|
|
1438
|
-
return {
|
|
1439
|
-
t: 13 /* Iterable */,
|
|
1440
|
-
i: id,
|
|
1441
|
-
s: void 0,
|
|
1442
|
-
l: void 0,
|
|
1443
|
-
m: void 0,
|
|
1444
|
-
c: void 0,
|
|
1445
|
-
// Parse options first before the items
|
|
1446
|
-
d: options ? serializePropertiesSync(ctx, options) : void 0,
|
|
1447
|
-
a: generateNodeList2(ctx, Array.from(current)),
|
|
1448
|
-
n: void 0
|
|
1449
|
-
};
|
|
1450
|
-
}
|
|
1451
|
-
function generateObjectNode2(ctx, current, id, empty) {
|
|
1452
|
-
if (Symbol.iterator in current) {
|
|
1453
|
-
return generateIterableNode2(ctx, current, id);
|
|
1454
|
-
}
|
|
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);
|
|
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
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
generateProperties(properties) {
|
|
1390
|
+
const keys = Object.keys(properties);
|
|
1391
|
+
const size = keys.length;
|
|
1392
|
+
const keyNodes = new Array(size);
|
|
1393
|
+
const valueNodes = new Array(size);
|
|
1394
|
+
const deferredKeys = new Array(size);
|
|
1395
|
+
const deferredValues = new Array(size);
|
|
1396
|
+
let deferredSize = 0;
|
|
1397
|
+
let nodesSize = 0;
|
|
1398
|
+
let item;
|
|
1399
|
+
for (const key of keys) {
|
|
1400
|
+
item = properties[key];
|
|
1401
|
+
if (isIterable(item)) {
|
|
1402
|
+
deferredKeys[deferredSize] = key;
|
|
1403
|
+
deferredValues[deferredSize] = item;
|
|
1404
|
+
deferredSize++;
|
|
1405
|
+
} else {
|
|
1406
|
+
keyNodes[nodesSize] = key;
|
|
1407
|
+
valueNodes[nodesSize] = this.parse(item);
|
|
1408
|
+
nodesSize++;
|
|
1546
1409
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1410
|
+
}
|
|
1411
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1412
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1413
|
+
valueNodes[nodesSize + i] = this.parse(deferredValues[i]);
|
|
1414
|
+
}
|
|
1415
|
+
return {
|
|
1416
|
+
k: keyNodes,
|
|
1417
|
+
v: valueNodes,
|
|
1418
|
+
s: size
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
generateIterableNode(id, current) {
|
|
1422
|
+
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1423
|
+
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,
|
|
1431
|
+
// 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
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
generateObjectNode(id, current, empty) {
|
|
1438
|
+
if (Symbol.iterator in current) {
|
|
1439
|
+
return this.generateIterableNode(id, current);
|
|
1440
|
+
}
|
|
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
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
generateAggregateErrorNode(id, current) {
|
|
1454
|
+
const options = getErrorOptions(current);
|
|
1455
|
+
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
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
generateErrorNode(id, current) {
|
|
1469
|
+
const options = getErrorOptions(current);
|
|
1470
|
+
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
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
parse(current) {
|
|
1484
|
+
switch (typeof current) {
|
|
1485
|
+
case "boolean":
|
|
1486
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
1487
|
+
case "undefined":
|
|
1488
|
+
return UNDEFINED_NODE;
|
|
1489
|
+
case "string":
|
|
1490
|
+
return createPrimitiveNode(quote(current));
|
|
1491
|
+
case "number":
|
|
1492
|
+
if (Object.is(current, -0)) {
|
|
1493
|
+
return NEG_ZERO_NODE;
|
|
1494
|
+
}
|
|
1495
|
+
if (Object.is(current, Infinity)) {
|
|
1496
|
+
return createPrimitiveNode("1/0");
|
|
1497
|
+
}
|
|
1498
|
+
if (Object.is(current, -Infinity)) {
|
|
1499
|
+
return createPrimitiveNode("-1/0");
|
|
1500
|
+
}
|
|
1501
|
+
return createPrimitiveNode(current);
|
|
1502
|
+
case "bigint":
|
|
1503
|
+
return createBigIntNode(this.ctx, current);
|
|
1504
|
+
case "object": {
|
|
1505
|
+
if (!current) {
|
|
1506
|
+
return NULL_NODE;
|
|
1507
|
+
}
|
|
1508
|
+
const id = createRef(this.ctx, current, true);
|
|
1509
|
+
if (this.ctx.markedRefs[id]) {
|
|
1510
|
+
return createReferenceNode(id);
|
|
1511
|
+
}
|
|
1512
|
+
if (Array.isArray(current)) {
|
|
1513
|
+
return this.generateArrayNode(id, current);
|
|
1514
|
+
}
|
|
1515
|
+
switch (current.constructor) {
|
|
1516
|
+
case Date:
|
|
1517
|
+
return createDateNode(id, current);
|
|
1518
|
+
case RegExp:
|
|
1519
|
+
return createRegExpNode(id, current);
|
|
1520
|
+
case Int8Array:
|
|
1521
|
+
case Int16Array:
|
|
1522
|
+
case Int32Array:
|
|
1523
|
+
case Uint8Array:
|
|
1524
|
+
case Uint16Array:
|
|
1525
|
+
case Uint32Array:
|
|
1526
|
+
case Uint8ClampedArray:
|
|
1527
|
+
case Float32Array:
|
|
1528
|
+
case Float64Array:
|
|
1529
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
1530
|
+
case BigInt64Array:
|
|
1531
|
+
case BigUint64Array:
|
|
1532
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
1533
|
+
case Map:
|
|
1534
|
+
return this.generateMapNode(id, current);
|
|
1535
|
+
case Set:
|
|
1536
|
+
return this.generateSetNode(id, current);
|
|
1537
|
+
case Object:
|
|
1538
|
+
return this.generateObjectNode(id, current, false);
|
|
1539
|
+
case void 0:
|
|
1540
|
+
return this.generateObjectNode(id, current, true);
|
|
1541
|
+
case AggregateError:
|
|
1542
|
+
if (this.ctx.features & 1 /* AggregateError */) {
|
|
1543
|
+
return this.generateAggregateErrorNode(id, current);
|
|
1544
|
+
}
|
|
1545
|
+
return this.generateErrorNode(id, current);
|
|
1546
|
+
case Error:
|
|
1547
|
+
case EvalError:
|
|
1548
|
+
case RangeError:
|
|
1549
|
+
case ReferenceError:
|
|
1550
|
+
case SyntaxError:
|
|
1551
|
+
case TypeError:
|
|
1552
|
+
case URIError:
|
|
1553
|
+
return this.generateErrorNode(id, current);
|
|
1554
|
+
default:
|
|
1555
|
+
break;
|
|
1556
|
+
}
|
|
1557
|
+
if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
|
|
1558
|
+
return this.generateAggregateErrorNode(id, current);
|
|
1559
|
+
}
|
|
1560
|
+
if (current instanceof Error) {
|
|
1561
|
+
return this.generateErrorNode(id, current);
|
|
1562
|
+
}
|
|
1563
|
+
if (Symbol.iterator in current) {
|
|
1564
|
+
return this.generateIterableNode(id, current);
|
|
1565
|
+
}
|
|
1566
|
+
throw new Error("Unsupported type");
|
|
1549
1567
|
}
|
|
1550
|
-
|
|
1568
|
+
default:
|
|
1569
|
+
throw new Error("Unsupported type");
|
|
1551
1570
|
}
|
|
1552
|
-
default:
|
|
1553
|
-
throw new Error("Unsupported type");
|
|
1554
1571
|
}
|
|
1555
|
-
}
|
|
1572
|
+
};
|
|
1556
1573
|
function parseSync(ctx, current) {
|
|
1557
|
-
const result =
|
|
1574
|
+
const result = new SyncParser(ctx).parse(current);
|
|
1558
1575
|
const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
|
|
1559
1576
|
return [result, createRef(ctx, current, false), isObject];
|
|
1560
1577
|
}
|