seroval 0.4.0-alpha.8 → 0.4.0-alpha.9
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 +373 -166
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +373 -166
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/tree/serialize.d.ts +1 -1
- package/dist/types/tree/types.d.ts +108 -59
- package/package.json +2 -2
- package/src/tree/async.ts +111 -34
- package/src/tree/serialize.ts +116 -121
- package/src/tree/shared.ts +67 -11
- package/src/tree/sync.ts +99 -25
- package/src/tree/types.ts +143 -65
|
@@ -394,14 +394,24 @@ function getIterableOptions(obj) {
|
|
|
394
394
|
return void 0;
|
|
395
395
|
}
|
|
396
396
|
function isReferenceInStack(ctx, node) {
|
|
397
|
-
return node
|
|
397
|
+
return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
|
|
398
398
|
}
|
|
399
399
|
function generateRef(ctx, current) {
|
|
400
400
|
const ref = ctx.refs.has(current);
|
|
401
401
|
if (ref) {
|
|
402
402
|
const refID = ctx.refs.get(current) || 0;
|
|
403
403
|
markRef(ctx, refID);
|
|
404
|
-
return
|
|
404
|
+
return {
|
|
405
|
+
t: 2 /* Reference */,
|
|
406
|
+
i: refID,
|
|
407
|
+
a: void 0,
|
|
408
|
+
s: void 0,
|
|
409
|
+
l: void 0,
|
|
410
|
+
m: void 0,
|
|
411
|
+
c: void 0,
|
|
412
|
+
d: void 0,
|
|
413
|
+
n: void 0
|
|
414
|
+
};
|
|
405
415
|
}
|
|
406
416
|
const id = ctx.refs.size;
|
|
407
417
|
ctx.refs.set(current, id);
|
|
@@ -410,18 +420,58 @@ function generateRef(ctx, current) {
|
|
|
410
420
|
function generateSemiPrimitiveValue(ctx, current, id) {
|
|
411
421
|
if (typeof current === "bigint") {
|
|
412
422
|
assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
413
|
-
return
|
|
423
|
+
return {
|
|
424
|
+
t: 1 /* BigInt */,
|
|
425
|
+
i: void 0,
|
|
426
|
+
a: void 0,
|
|
427
|
+
s: `${current}n`,
|
|
428
|
+
l: void 0,
|
|
429
|
+
m: void 0,
|
|
430
|
+
c: void 0,
|
|
431
|
+
d: void 0,
|
|
432
|
+
n: void 0
|
|
433
|
+
};
|
|
414
434
|
}
|
|
415
435
|
if (constructorCheck(current, Date)) {
|
|
416
|
-
return
|
|
436
|
+
return {
|
|
437
|
+
t: 3 /* Date */,
|
|
438
|
+
i: id,
|
|
439
|
+
a: void 0,
|
|
440
|
+
s: current.toISOString(),
|
|
441
|
+
l: void 0,
|
|
442
|
+
m: void 0,
|
|
443
|
+
c: void 0,
|
|
444
|
+
d: void 0,
|
|
445
|
+
n: void 0
|
|
446
|
+
};
|
|
417
447
|
}
|
|
418
448
|
if (constructorCheck(current, RegExp)) {
|
|
419
|
-
return
|
|
449
|
+
return {
|
|
450
|
+
t: 4 /* RegExp */,
|
|
451
|
+
i: id,
|
|
452
|
+
a: void 0,
|
|
453
|
+
s: String(current),
|
|
454
|
+
l: void 0,
|
|
455
|
+
m: void 0,
|
|
456
|
+
c: void 0,
|
|
457
|
+
d: void 0,
|
|
458
|
+
n: void 0
|
|
459
|
+
};
|
|
420
460
|
}
|
|
421
461
|
if (constructorCheck(current, Int8Array) || constructorCheck(current, Int16Array) || constructorCheck(current, Int32Array) || constructorCheck(current, Uint8Array) || constructorCheck(current, Uint16Array) || constructorCheck(current, Uint32Array) || constructorCheck(current, Uint8ClampedArray) || constructorCheck(current, Float32Array) || constructorCheck(current, Float64Array)) {
|
|
422
462
|
const constructor = current.constructor.name;
|
|
423
463
|
assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
424
|
-
return
|
|
464
|
+
return {
|
|
465
|
+
t: 14 /* TypedArray */,
|
|
466
|
+
i: id,
|
|
467
|
+
a: void 0,
|
|
468
|
+
s: current.toString(),
|
|
469
|
+
l: current.byteOffset,
|
|
470
|
+
m: void 0,
|
|
471
|
+
c: constructor,
|
|
472
|
+
d: void 0,
|
|
473
|
+
n: void 0
|
|
474
|
+
};
|
|
425
475
|
}
|
|
426
476
|
if (constructorCheck(current, BigInt64Array) || constructorCheck(current, BigUint64Array)) {
|
|
427
477
|
const constructor = current.constructor.name;
|
|
@@ -435,11 +485,17 @@ function generateSemiPrimitiveValue(ctx, current, id) {
|
|
|
435
485
|
result += `${current[i]}n,`;
|
|
436
486
|
}
|
|
437
487
|
result += `"${current[cap]}"`;
|
|
438
|
-
return
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
488
|
+
return {
|
|
489
|
+
t: 14 /* TypedArray */,
|
|
490
|
+
i: id,
|
|
491
|
+
a: void 0,
|
|
492
|
+
s: result,
|
|
493
|
+
l: current.byteOffset,
|
|
494
|
+
m: void 0,
|
|
495
|
+
c: constructor,
|
|
496
|
+
d: void 0,
|
|
497
|
+
n: void 0
|
|
498
|
+
};
|
|
443
499
|
}
|
|
444
500
|
return void 0;
|
|
445
501
|
}
|
|
@@ -496,7 +552,11 @@ async function serializePropertiesAsync(ctx, properties) {
|
|
|
496
552
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
497
553
|
valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
|
|
498
554
|
}
|
|
499
|
-
return
|
|
555
|
+
return {
|
|
556
|
+
k: keyNodes,
|
|
557
|
+
v: valueNodes,
|
|
558
|
+
s: size
|
|
559
|
+
};
|
|
500
560
|
}
|
|
501
561
|
async function generateSetNode(ctx, current, id) {
|
|
502
562
|
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -515,7 +575,17 @@ async function generateSetNode(ctx, current, id) {
|
|
|
515
575
|
for (let i = 0; i < deferredSize; i++) {
|
|
516
576
|
nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
|
|
517
577
|
}
|
|
518
|
-
return
|
|
578
|
+
return {
|
|
579
|
+
t: 5 /* Set */,
|
|
580
|
+
i: id,
|
|
581
|
+
a: nodes,
|
|
582
|
+
s: void 0,
|
|
583
|
+
l: void 0,
|
|
584
|
+
m: void 0,
|
|
585
|
+
c: void 0,
|
|
586
|
+
d: void 0,
|
|
587
|
+
n: void 0
|
|
588
|
+
};
|
|
519
589
|
}
|
|
520
590
|
async function generateMapNode(ctx, current, id) {
|
|
521
591
|
assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -541,7 +611,17 @@ async function generateMapNode(ctx, current, id) {
|
|
|
541
611
|
keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
|
|
542
612
|
valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
|
|
543
613
|
}
|
|
544
|
-
return
|
|
614
|
+
return {
|
|
615
|
+
t: 6 /* Map */,
|
|
616
|
+
i: id,
|
|
617
|
+
a: void 0,
|
|
618
|
+
s: void 0,
|
|
619
|
+
l: void 0,
|
|
620
|
+
m: void 0,
|
|
621
|
+
c: void 0,
|
|
622
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
623
|
+
n: void 0
|
|
624
|
+
};
|
|
545
625
|
}
|
|
546
626
|
async function generateNodeList(ctx, current) {
|
|
547
627
|
const size = current.length;
|
|
@@ -564,42 +644,81 @@ async function generateNodeList(ctx, current) {
|
|
|
564
644
|
return nodes;
|
|
565
645
|
}
|
|
566
646
|
async function generateArrayNode(ctx, current, id) {
|
|
567
|
-
return
|
|
647
|
+
return {
|
|
648
|
+
t: 7 /* Array */,
|
|
649
|
+
i: id,
|
|
650
|
+
a: await generateNodeList(ctx, current),
|
|
651
|
+
s: void 0,
|
|
652
|
+
l: void 0,
|
|
653
|
+
m: void 0,
|
|
654
|
+
c: void 0,
|
|
655
|
+
d: void 0,
|
|
656
|
+
n: void 0
|
|
657
|
+
};
|
|
568
658
|
}
|
|
569
659
|
async function generateAggregateErrorNode(ctx, current, id) {
|
|
570
660
|
const options = getErrorOptions(current);
|
|
571
661
|
const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
662
|
+
return {
|
|
663
|
+
t: 12 /* AggregateError */,
|
|
664
|
+
i: id,
|
|
665
|
+
a: void 0,
|
|
666
|
+
s: void 0,
|
|
667
|
+
l: void 0,
|
|
668
|
+
m: current.message,
|
|
669
|
+
c: void 0,
|
|
670
|
+
d: optionsNode,
|
|
671
|
+
n: await generateTreeAsync(ctx, current.errors)
|
|
672
|
+
};
|
|
578
673
|
}
|
|
579
674
|
async function generateErrorNode(ctx, current, id) {
|
|
580
675
|
const options = getErrorOptions(current);
|
|
581
676
|
const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
|
|
582
|
-
return
|
|
583
|
-
11 /* Error */,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
677
|
+
return {
|
|
678
|
+
t: 11 /* Error */,
|
|
679
|
+
i: id,
|
|
680
|
+
a: void 0,
|
|
681
|
+
s: void 0,
|
|
682
|
+
l: void 0,
|
|
683
|
+
m: current.message,
|
|
684
|
+
c: getErrorConstructor(current),
|
|
685
|
+
d: optionsNode,
|
|
686
|
+
n: void 0
|
|
687
|
+
};
|
|
587
688
|
}
|
|
588
689
|
async function generateIterableNode(ctx, current, id) {
|
|
589
690
|
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
590
691
|
const options = getIterableOptions(current);
|
|
591
|
-
return
|
|
692
|
+
return {
|
|
693
|
+
t: 13 /* Iterable */,
|
|
694
|
+
i: id,
|
|
695
|
+
s: void 0,
|
|
696
|
+
l: void 0,
|
|
697
|
+
m: void 0,
|
|
698
|
+
c: void 0,
|
|
592
699
|
// Parse options first before the items
|
|
593
|
-
options ? await serializePropertiesAsync(ctx, options) : void 0,
|
|
594
|
-
await generateNodeList(ctx, Array.from(current))
|
|
595
|
-
|
|
700
|
+
d: options ? await serializePropertiesAsync(ctx, options) : void 0,
|
|
701
|
+
a: await generateNodeList(ctx, Array.from(current)),
|
|
702
|
+
n: void 0
|
|
703
|
+
};
|
|
596
704
|
}
|
|
597
705
|
async function generateTreeAsync(ctx, current) {
|
|
598
706
|
if (isPrimitive(current)) {
|
|
599
|
-
return
|
|
707
|
+
return {
|
|
708
|
+
t: 0 /* Primitive */,
|
|
709
|
+
i: void 0,
|
|
710
|
+
s: serializePrimitive(current),
|
|
711
|
+
l: void 0,
|
|
712
|
+
m: void 0,
|
|
713
|
+
c: void 0,
|
|
714
|
+
// Parse options first before the items
|
|
715
|
+
d: void 0,
|
|
716
|
+
a: void 0,
|
|
717
|
+
n: void 0
|
|
718
|
+
};
|
|
600
719
|
}
|
|
601
720
|
const id = generateRef(ctx, current);
|
|
602
|
-
if (
|
|
721
|
+
if (typeof id !== "number") {
|
|
603
722
|
return id;
|
|
604
723
|
}
|
|
605
724
|
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
|
|
@@ -608,11 +727,18 @@ async function generateTreeAsync(ctx, current) {
|
|
|
608
727
|
}
|
|
609
728
|
if (isPromise(current)) {
|
|
610
729
|
assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
|
|
611
|
-
return current.then(async (value) =>
|
|
612
|
-
10 /* Promise */,
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
730
|
+
return current.then(async (value) => ({
|
|
731
|
+
t: 10 /* Promise */,
|
|
732
|
+
i: id,
|
|
733
|
+
s: void 0,
|
|
734
|
+
l: void 0,
|
|
735
|
+
m: void 0,
|
|
736
|
+
c: void 0,
|
|
737
|
+
// Parse options first before the items
|
|
738
|
+
d: void 0,
|
|
739
|
+
a: void 0,
|
|
740
|
+
n: await generateTreeAsync(ctx, value)
|
|
741
|
+
}));
|
|
616
742
|
}
|
|
617
743
|
if (constructorCheck(current, Set)) {
|
|
618
744
|
return generateSetNode(ctx, current, id);
|
|
@@ -634,17 +760,24 @@ async function generateTreeAsync(ctx, current) {
|
|
|
634
760
|
}
|
|
635
761
|
const empty = current.constructor == null;
|
|
636
762
|
if (current.constructor === Object || empty) {
|
|
637
|
-
return
|
|
638
|
-
empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
763
|
+
return {
|
|
764
|
+
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
765
|
+
i: id,
|
|
766
|
+
s: void 0,
|
|
767
|
+
l: void 0,
|
|
768
|
+
m: void 0,
|
|
769
|
+
c: void 0,
|
|
770
|
+
// Parse options first before the items
|
|
771
|
+
d: await serializePropertiesAsync(ctx, current),
|
|
772
|
+
a: void 0,
|
|
773
|
+
n: void 0
|
|
774
|
+
};
|
|
642
775
|
}
|
|
643
776
|
throw new Error("Unsupported value");
|
|
644
777
|
}
|
|
645
778
|
async function parseAsync(ctx, current) {
|
|
646
779
|
const result = await generateTreeAsync(ctx, current);
|
|
647
|
-
return [result, createRef(ctx, current), result
|
|
780
|
+
return [result, createRef(ctx, current), result.t === 8 /* Object */];
|
|
648
781
|
}
|
|
649
782
|
|
|
650
783
|
// src/tree/serialize.ts
|
|
@@ -752,15 +885,15 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
752
885
|
createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
|
|
753
886
|
}
|
|
754
887
|
var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
|
|
755
|
-
function serializeAssignments(ctx, targetRef,
|
|
888
|
+
function serializeAssignments(ctx, targetRef, node) {
|
|
756
889
|
ctx.stack.push(targetRef);
|
|
757
890
|
const mainAssignments = [];
|
|
758
|
-
for (let i = 0; i <
|
|
891
|
+
for (let i = 0; i < node.s; i++) {
|
|
759
892
|
const parentStack = ctx.stack;
|
|
760
893
|
ctx.stack = [];
|
|
761
|
-
const refParam = serializeTree(ctx,
|
|
894
|
+
const refParam = serializeTree(ctx, node.v[i]);
|
|
762
895
|
ctx.stack = parentStack;
|
|
763
|
-
const key =
|
|
896
|
+
const key = node.k[i];
|
|
764
897
|
const check = Number(key);
|
|
765
898
|
const parentAssignment = ctx.assignments;
|
|
766
899
|
ctx.assignments = mainAssignments;
|
|
@@ -775,19 +908,19 @@ function serializeAssignments(ctx, targetRef, [keys, values, size]) {
|
|
|
775
908
|
ctx.stack.pop();
|
|
776
909
|
return resolveAssignments(mainAssignments);
|
|
777
910
|
}
|
|
778
|
-
function serializeObject(ctx, sourceID,
|
|
779
|
-
if (
|
|
911
|
+
function serializeObject(ctx, sourceID, node) {
|
|
912
|
+
if (node.s === 0) {
|
|
780
913
|
return "{}";
|
|
781
914
|
}
|
|
782
915
|
let result = "";
|
|
783
916
|
ctx.stack.push(sourceID);
|
|
784
|
-
for (let i = 0; i <
|
|
785
|
-
const key =
|
|
786
|
-
const val =
|
|
917
|
+
for (let i = 0; i < node.s; i++) {
|
|
918
|
+
const key = node.k[i];
|
|
919
|
+
const val = node.v[i];
|
|
787
920
|
const check = Number(key);
|
|
788
921
|
const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
|
|
789
922
|
if (isReferenceInStack(ctx, val)) {
|
|
790
|
-
const refParam = getRefParam(ctx, val
|
|
923
|
+
const refParam = getRefParam(ctx, val.i);
|
|
791
924
|
if (isIdentifier && Number.isNaN(check)) {
|
|
792
925
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
793
926
|
} else {
|
|
@@ -800,35 +933,35 @@ function serializeObject(ctx, sourceID, [keys, values, size]) {
|
|
|
800
933
|
ctx.stack.pop();
|
|
801
934
|
return `{${result.substring(0, result.length - 1)}}`;
|
|
802
935
|
}
|
|
803
|
-
function serializePromise(ctx,
|
|
936
|
+
function serializePromise(ctx, node) {
|
|
804
937
|
let serialized;
|
|
805
|
-
if (isReferenceInStack(ctx,
|
|
806
|
-
serialized = `Promise.resolve().then(()=>${getRefParam(ctx,
|
|
938
|
+
if (isReferenceInStack(ctx, node.n)) {
|
|
939
|
+
serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
|
|
807
940
|
} else {
|
|
808
|
-
ctx.stack.push(
|
|
809
|
-
const result = serializeTree(ctx,
|
|
941
|
+
ctx.stack.push(node.i);
|
|
942
|
+
const result = serializeTree(ctx, node.n);
|
|
810
943
|
ctx.stack.pop();
|
|
811
944
|
serialized = `Promise.resolve(${result})`;
|
|
812
945
|
}
|
|
813
|
-
return assignRef(ctx,
|
|
946
|
+
return assignRef(ctx, node.i, serialized);
|
|
814
947
|
}
|
|
815
|
-
function serializeTypedArray(ctx,
|
|
816
|
-
let args = `[${
|
|
817
|
-
if (
|
|
818
|
-
args += `,${
|
|
948
|
+
function serializeTypedArray(ctx, node) {
|
|
949
|
+
let args = `[${node.s}]`;
|
|
950
|
+
if (node.l !== 0) {
|
|
951
|
+
args += `,${node.l}`;
|
|
819
952
|
}
|
|
820
|
-
return assignRef(ctx,
|
|
953
|
+
return assignRef(ctx, node.i, `new ${node.c}(${args})`);
|
|
821
954
|
}
|
|
822
|
-
function serializeSet(ctx,
|
|
955
|
+
function serializeSet(ctx, node) {
|
|
823
956
|
let serialized = "new Set";
|
|
824
|
-
const size =
|
|
957
|
+
const size = node.a.length;
|
|
825
958
|
if (size) {
|
|
826
959
|
let result = "";
|
|
827
|
-
ctx.stack.push(
|
|
960
|
+
ctx.stack.push(node.i);
|
|
828
961
|
for (let i = 0; i < size; i++) {
|
|
829
|
-
const item =
|
|
962
|
+
const item = node.a[i];
|
|
830
963
|
if (isReferenceInStack(ctx, item)) {
|
|
831
|
-
createSetAdd(ctx,
|
|
964
|
+
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
832
965
|
} else {
|
|
833
966
|
result += `${serializeTree(ctx, item)},`;
|
|
834
967
|
}
|
|
@@ -838,32 +971,32 @@ function serializeSet(ctx, value, id) {
|
|
|
838
971
|
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
839
972
|
}
|
|
840
973
|
}
|
|
841
|
-
return assignRef(ctx,
|
|
974
|
+
return assignRef(ctx, node.i, serialized);
|
|
842
975
|
}
|
|
843
|
-
function serializeMap(ctx,
|
|
976
|
+
function serializeMap(ctx, node) {
|
|
844
977
|
let serialized = "new Map";
|
|
845
|
-
if (
|
|
978
|
+
if (node.d.s) {
|
|
846
979
|
let result = "";
|
|
847
|
-
ctx.stack.push(
|
|
848
|
-
for (let i = 0; i <
|
|
849
|
-
const key =
|
|
850
|
-
const val =
|
|
980
|
+
ctx.stack.push(node.i);
|
|
981
|
+
for (let i = 0; i < node.d.s; i++) {
|
|
982
|
+
const key = node.d.k[i];
|
|
983
|
+
const val = node.d.v[i];
|
|
851
984
|
if (isReferenceInStack(ctx, key)) {
|
|
852
|
-
const keyRef = getRefParam(ctx, key
|
|
985
|
+
const keyRef = getRefParam(ctx, key.i);
|
|
853
986
|
if (isReferenceInStack(ctx, val)) {
|
|
854
|
-
const valueRef = getRefParam(ctx, val
|
|
855
|
-
createMapSet(ctx,
|
|
987
|
+
const valueRef = getRefParam(ctx, val.i);
|
|
988
|
+
createMapSet(ctx, node.i, keyRef, valueRef);
|
|
856
989
|
} else {
|
|
857
990
|
const parent = ctx.stack;
|
|
858
991
|
ctx.stack = [];
|
|
859
|
-
createMapSet(ctx,
|
|
992
|
+
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
860
993
|
ctx.stack = parent;
|
|
861
994
|
}
|
|
862
995
|
} else if (isReferenceInStack(ctx, val)) {
|
|
863
|
-
const valueRef = getRefParam(ctx, val
|
|
996
|
+
const valueRef = getRefParam(ctx, val.i);
|
|
864
997
|
const parent = ctx.stack;
|
|
865
998
|
ctx.stack = [];
|
|
866
|
-
createMapSet(ctx,
|
|
999
|
+
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
867
1000
|
ctx.stack = parent;
|
|
868
1001
|
} else {
|
|
869
1002
|
result += `[${serializeTree(ctx, key)},${serializeTree(ctx, val)}],`;
|
|
@@ -874,16 +1007,16 @@ function serializeMap(ctx, keys, values, size, id) {
|
|
|
874
1007
|
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
875
1008
|
}
|
|
876
1009
|
}
|
|
877
|
-
return assignRef(ctx,
|
|
1010
|
+
return assignRef(ctx, node.i, serialized);
|
|
878
1011
|
}
|
|
879
|
-
function serializeNodeList(ctx,
|
|
880
|
-
const size =
|
|
1012
|
+
function serializeNodeList(ctx, node) {
|
|
1013
|
+
const size = node.a.length;
|
|
881
1014
|
let values = "";
|
|
882
1015
|
for (let i = 0; i < size; i++) {
|
|
883
|
-
const item =
|
|
1016
|
+
const item = node.a[i];
|
|
884
1017
|
if (item) {
|
|
885
1018
|
if (isReferenceInStack(ctx, item)) {
|
|
886
|
-
createArrayAssign(ctx,
|
|
1019
|
+
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
887
1020
|
values += ",";
|
|
888
1021
|
} else {
|
|
889
1022
|
values += serializeTree(ctx, item);
|
|
@@ -897,11 +1030,11 @@ function serializeNodeList(ctx, value, id) {
|
|
|
897
1030
|
}
|
|
898
1031
|
return `[${values}]`;
|
|
899
1032
|
}
|
|
900
|
-
function serializeArray(ctx,
|
|
901
|
-
ctx.stack.push(
|
|
902
|
-
const result = serializeNodeList(ctx,
|
|
1033
|
+
function serializeArray(ctx, node) {
|
|
1034
|
+
ctx.stack.push(node.i);
|
|
1035
|
+
const result = serializeNodeList(ctx, node);
|
|
903
1036
|
ctx.stack.pop();
|
|
904
|
-
return assignRef(ctx,
|
|
1037
|
+
return assignRef(ctx, node.i, result);
|
|
905
1038
|
}
|
|
906
1039
|
function serializeWithObjectAssign(ctx, value, id, serialized) {
|
|
907
1040
|
const fields = serializeObject(ctx, id, value);
|
|
@@ -910,44 +1043,44 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
|
|
|
910
1043
|
}
|
|
911
1044
|
return serialized;
|
|
912
1045
|
}
|
|
913
|
-
function serializeAggregateError(ctx,
|
|
914
|
-
ctx.stack.push(
|
|
915
|
-
let serialized = `new AggregateError(${serializeTree(ctx,
|
|
1046
|
+
function serializeAggregateError(ctx, node) {
|
|
1047
|
+
ctx.stack.push(node.i);
|
|
1048
|
+
let serialized = `new AggregateError(${serializeTree(ctx, node.n)},${quote(node.m)})`;
|
|
916
1049
|
ctx.stack.pop();
|
|
917
|
-
if (
|
|
1050
|
+
if (node.d) {
|
|
918
1051
|
if (ctx.features & 64 /* ObjectAssign */) {
|
|
919
|
-
serialized = serializeWithObjectAssign(ctx,
|
|
1052
|
+
serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
|
|
920
1053
|
} else {
|
|
921
|
-
markRef(ctx,
|
|
922
|
-
const assignments = serializeAssignments(ctx,
|
|
1054
|
+
markRef(ctx, node.i);
|
|
1055
|
+
const assignments = serializeAssignments(ctx, node.i, node.d);
|
|
923
1056
|
if (assignments) {
|
|
924
|
-
const ref = getRefParam(ctx,
|
|
925
|
-
return `(${assignRef(ctx,
|
|
1057
|
+
const ref = getRefParam(ctx, node.i);
|
|
1058
|
+
return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
|
|
926
1059
|
}
|
|
927
1060
|
}
|
|
928
1061
|
}
|
|
929
|
-
return assignRef(ctx,
|
|
1062
|
+
return assignRef(ctx, node.i, serialized);
|
|
930
1063
|
}
|
|
931
|
-
function serializeError(ctx,
|
|
932
|
-
let serialized = `new ${
|
|
933
|
-
if (
|
|
1064
|
+
function serializeError(ctx, node) {
|
|
1065
|
+
let serialized = `new ${node.c}(${quote(node.m)})`;
|
|
1066
|
+
if (node.d) {
|
|
934
1067
|
if (ctx.features & 64 /* ObjectAssign */) {
|
|
935
|
-
serialized = serializeWithObjectAssign(ctx,
|
|
1068
|
+
serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
|
|
936
1069
|
} else {
|
|
937
|
-
markRef(ctx,
|
|
938
|
-
const assignments = serializeAssignments(ctx,
|
|
1070
|
+
markRef(ctx, node.i);
|
|
1071
|
+
const assignments = serializeAssignments(ctx, node.i, node.d);
|
|
939
1072
|
if (assignments) {
|
|
940
|
-
const ref = getRefParam(ctx,
|
|
941
|
-
return `(${assignRef(ctx,
|
|
1073
|
+
const ref = getRefParam(ctx, node.i);
|
|
1074
|
+
return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
|
|
942
1075
|
}
|
|
943
1076
|
}
|
|
944
1077
|
}
|
|
945
|
-
return assignRef(ctx,
|
|
1078
|
+
return assignRef(ctx, node.i, serialized);
|
|
946
1079
|
}
|
|
947
|
-
function serializeIterable(ctx,
|
|
1080
|
+
function serializeIterable(ctx, node) {
|
|
948
1081
|
const parent = ctx.stack;
|
|
949
1082
|
ctx.stack = [];
|
|
950
|
-
const values = serializeNodeList(ctx,
|
|
1083
|
+
const values = serializeNodeList(ctx, node);
|
|
951
1084
|
ctx.stack = parent;
|
|
952
1085
|
let serialized;
|
|
953
1086
|
if (ctx.features & 2 /* ArrayPrototypeValues */) {
|
|
@@ -962,67 +1095,67 @@ function serializeIterable(ctx, options, items, id) {
|
|
|
962
1095
|
} else {
|
|
963
1096
|
serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
|
|
964
1097
|
}
|
|
965
|
-
if (
|
|
1098
|
+
if (node.d) {
|
|
966
1099
|
if (ctx.features & 64 /* ObjectAssign */) {
|
|
967
|
-
serialized = serializeWithObjectAssign(ctx,
|
|
1100
|
+
serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
|
|
968
1101
|
} else {
|
|
969
|
-
markRef(ctx,
|
|
970
|
-
const assignments = serializeAssignments(ctx,
|
|
1102
|
+
markRef(ctx, node.i);
|
|
1103
|
+
const assignments = serializeAssignments(ctx, node.i, node.d);
|
|
971
1104
|
if (assignments) {
|
|
972
|
-
const ref = getRefParam(ctx,
|
|
973
|
-
return `(${assignRef(ctx,
|
|
1105
|
+
const ref = getRefParam(ctx, node.i);
|
|
1106
|
+
return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
|
|
974
1107
|
}
|
|
975
1108
|
}
|
|
976
1109
|
}
|
|
977
|
-
return assignRef(ctx,
|
|
1110
|
+
return assignRef(ctx, node.i, serialized);
|
|
978
1111
|
}
|
|
979
|
-
function serializeNullConstructor(ctx,
|
|
1112
|
+
function serializeNullConstructor(ctx, node) {
|
|
980
1113
|
let serialized = "Object.create(null)";
|
|
981
1114
|
if (ctx.features & 64 /* ObjectAssign */) {
|
|
982
|
-
serialized = serializeWithObjectAssign(ctx,
|
|
1115
|
+
serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
|
|
983
1116
|
} else {
|
|
984
|
-
markRef(ctx,
|
|
985
|
-
const assignments = serializeAssignments(ctx,
|
|
1117
|
+
markRef(ctx, node.i);
|
|
1118
|
+
const assignments = serializeAssignments(ctx, node.i, node.d);
|
|
986
1119
|
if (assignments) {
|
|
987
|
-
const ref = getRefParam(ctx,
|
|
988
|
-
return `(${assignRef(ctx,
|
|
1120
|
+
const ref = getRefParam(ctx, node.i);
|
|
1121
|
+
return `(${assignRef(ctx, node.i, serialized)},${assignments}${ref})`;
|
|
989
1122
|
}
|
|
990
1123
|
}
|
|
991
|
-
return assignRef(ctx,
|
|
1124
|
+
return assignRef(ctx, node.i, serialized);
|
|
992
1125
|
}
|
|
993
|
-
function serializeTree(ctx,
|
|
994
|
-
switch (
|
|
1126
|
+
function serializeTree(ctx, node) {
|
|
1127
|
+
switch (node.t) {
|
|
995
1128
|
case 0 /* Primitive */:
|
|
996
|
-
return String(
|
|
1129
|
+
return String(node.s);
|
|
997
1130
|
case 2 /* Reference */:
|
|
998
|
-
return getRefParam(ctx,
|
|
1131
|
+
return getRefParam(ctx, node.i);
|
|
999
1132
|
case 10 /* Promise */:
|
|
1000
|
-
return serializePromise(ctx,
|
|
1133
|
+
return serializePromise(ctx, node);
|
|
1001
1134
|
case 1 /* BigInt */:
|
|
1002
|
-
return
|
|
1135
|
+
return node.s;
|
|
1003
1136
|
case 3 /* Date */:
|
|
1004
|
-
return assignRef(ctx,
|
|
1137
|
+
return assignRef(ctx, node.i, `new Date("${node.s}")`);
|
|
1005
1138
|
case 4 /* RegExp */:
|
|
1006
|
-
return assignRef(ctx,
|
|
1139
|
+
return assignRef(ctx, node.i, node.s);
|
|
1007
1140
|
case 15 /* BigIntTypedArray */:
|
|
1008
1141
|
case 14 /* TypedArray */:
|
|
1009
|
-
return serializeTypedArray(ctx,
|
|
1142
|
+
return serializeTypedArray(ctx, node);
|
|
1010
1143
|
case 5 /* Set */:
|
|
1011
|
-
return serializeSet(ctx,
|
|
1144
|
+
return serializeSet(ctx, node);
|
|
1012
1145
|
case 6 /* Map */:
|
|
1013
|
-
return serializeMap(ctx,
|
|
1146
|
+
return serializeMap(ctx, node);
|
|
1014
1147
|
case 7 /* Array */:
|
|
1015
|
-
return serializeArray(ctx,
|
|
1148
|
+
return serializeArray(ctx, node);
|
|
1016
1149
|
case 12 /* AggregateError */:
|
|
1017
|
-
return serializeAggregateError(ctx,
|
|
1150
|
+
return serializeAggregateError(ctx, node);
|
|
1018
1151
|
case 11 /* Error */:
|
|
1019
|
-
return serializeError(ctx,
|
|
1152
|
+
return serializeError(ctx, node);
|
|
1020
1153
|
case 13 /* Iterable */:
|
|
1021
|
-
return serializeIterable(ctx,
|
|
1154
|
+
return serializeIterable(ctx, node);
|
|
1022
1155
|
case 9 /* NullConstructor */:
|
|
1023
|
-
return serializeNullConstructor(ctx,
|
|
1156
|
+
return serializeNullConstructor(ctx, node);
|
|
1024
1157
|
case 8 /* Object */:
|
|
1025
|
-
return assignRef(ctx,
|
|
1158
|
+
return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
|
|
1026
1159
|
default:
|
|
1027
1160
|
throw new Error("Unsupported type");
|
|
1028
1161
|
}
|
|
@@ -1053,7 +1186,11 @@ function serializePropertiesSync(ctx, properties) {
|
|
|
1053
1186
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1054
1187
|
valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
|
|
1055
1188
|
}
|
|
1056
|
-
return
|
|
1189
|
+
return {
|
|
1190
|
+
k: keyNodes,
|
|
1191
|
+
v: valueNodes,
|
|
1192
|
+
s: size
|
|
1193
|
+
};
|
|
1057
1194
|
}
|
|
1058
1195
|
function generateSetNode2(ctx, current, id) {
|
|
1059
1196
|
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -1072,7 +1209,17 @@ function generateSetNode2(ctx, current, id) {
|
|
|
1072
1209
|
for (let i = 0; i < deferredSize; i++) {
|
|
1073
1210
|
nodes[nodeSize + i] = generateTreeSync(ctx, deferred[i]);
|
|
1074
1211
|
}
|
|
1075
|
-
return
|
|
1212
|
+
return {
|
|
1213
|
+
t: 5 /* Set */,
|
|
1214
|
+
i: id,
|
|
1215
|
+
a: nodes,
|
|
1216
|
+
s: void 0,
|
|
1217
|
+
l: void 0,
|
|
1218
|
+
m: void 0,
|
|
1219
|
+
c: void 0,
|
|
1220
|
+
d: void 0,
|
|
1221
|
+
n: void 0
|
|
1222
|
+
};
|
|
1076
1223
|
}
|
|
1077
1224
|
function generateMapNode2(ctx, current, id) {
|
|
1078
1225
|
assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -1098,7 +1245,17 @@ function generateMapNode2(ctx, current, id) {
|
|
|
1098
1245
|
keyNodes[nodeSize + i] = generateTreeSync(ctx, deferredKey[i]);
|
|
1099
1246
|
valueNodes[nodeSize + i] = generateTreeSync(ctx, deferredValue[i]);
|
|
1100
1247
|
}
|
|
1101
|
-
return
|
|
1248
|
+
return {
|
|
1249
|
+
t: 6 /* Map */,
|
|
1250
|
+
i: id,
|
|
1251
|
+
a: void 0,
|
|
1252
|
+
s: void 0,
|
|
1253
|
+
l: void 0,
|
|
1254
|
+
m: void 0,
|
|
1255
|
+
c: void 0,
|
|
1256
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1257
|
+
n: void 0
|
|
1258
|
+
};
|
|
1102
1259
|
}
|
|
1103
1260
|
function generateNodeList2(ctx, current) {
|
|
1104
1261
|
const size = current.length;
|
|
@@ -1121,38 +1278,81 @@ function generateNodeList2(ctx, current) {
|
|
|
1121
1278
|
return nodes;
|
|
1122
1279
|
}
|
|
1123
1280
|
function generateArrayNode2(ctx, current, id) {
|
|
1124
|
-
return
|
|
1281
|
+
return {
|
|
1282
|
+
t: 7 /* Array */,
|
|
1283
|
+
i: id,
|
|
1284
|
+
a: generateNodeList2(ctx, current),
|
|
1285
|
+
s: void 0,
|
|
1286
|
+
l: void 0,
|
|
1287
|
+
m: void 0,
|
|
1288
|
+
c: void 0,
|
|
1289
|
+
d: void 0,
|
|
1290
|
+
n: void 0
|
|
1291
|
+
};
|
|
1125
1292
|
}
|
|
1126
1293
|
function generateAggregateErrorNode2(ctx, current, id) {
|
|
1127
1294
|
const options = getErrorOptions(current);
|
|
1128
1295
|
const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
|
|
1129
|
-
|
|
1130
|
-
|
|
1296
|
+
return {
|
|
1297
|
+
t: 12 /* AggregateError */,
|
|
1298
|
+
i: id,
|
|
1299
|
+
a: void 0,
|
|
1300
|
+
s: void 0,
|
|
1301
|
+
l: void 0,
|
|
1302
|
+
m: current.message,
|
|
1303
|
+
c: void 0,
|
|
1304
|
+
d: optionsNode,
|
|
1305
|
+
n: generateTreeSync(ctx, current.errors)
|
|
1306
|
+
};
|
|
1131
1307
|
}
|
|
1132
1308
|
function generateErrorNode2(ctx, current, id) {
|
|
1133
1309
|
const options = getErrorOptions(current);
|
|
1134
1310
|
const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
|
|
1135
|
-
return
|
|
1136
|
-
11 /* Error */,
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1311
|
+
return {
|
|
1312
|
+
t: 11 /* Error */,
|
|
1313
|
+
i: id,
|
|
1314
|
+
a: void 0,
|
|
1315
|
+
s: void 0,
|
|
1316
|
+
l: void 0,
|
|
1317
|
+
m: current.message,
|
|
1318
|
+
c: getErrorConstructor(current),
|
|
1319
|
+
d: optionsNode,
|
|
1320
|
+
n: void 0
|
|
1321
|
+
};
|
|
1140
1322
|
}
|
|
1141
1323
|
function generateIterableNode2(ctx, current, id) {
|
|
1142
1324
|
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1143
1325
|
const options = getIterableOptions(current);
|
|
1144
|
-
return
|
|
1326
|
+
return {
|
|
1327
|
+
t: 13 /* Iterable */,
|
|
1328
|
+
i: id,
|
|
1329
|
+
s: void 0,
|
|
1330
|
+
l: void 0,
|
|
1331
|
+
m: void 0,
|
|
1332
|
+
c: void 0,
|
|
1145
1333
|
// Parse options first before the items
|
|
1146
|
-
options ? serializePropertiesSync(ctx, options) : void 0,
|
|
1147
|
-
generateNodeList2(ctx, Array.from(current))
|
|
1148
|
-
|
|
1334
|
+
d: options ? serializePropertiesSync(ctx, options) : void 0,
|
|
1335
|
+
a: generateNodeList2(ctx, Array.from(current)),
|
|
1336
|
+
n: void 0
|
|
1337
|
+
};
|
|
1149
1338
|
}
|
|
1150
1339
|
function generateTreeSync(ctx, current) {
|
|
1151
1340
|
if (isPrimitive(current)) {
|
|
1152
|
-
return
|
|
1341
|
+
return {
|
|
1342
|
+
t: 0 /* Primitive */,
|
|
1343
|
+
i: void 0,
|
|
1344
|
+
s: serializePrimitive(current),
|
|
1345
|
+
l: void 0,
|
|
1346
|
+
m: void 0,
|
|
1347
|
+
c: void 0,
|
|
1348
|
+
// Parse options first before the items
|
|
1349
|
+
d: void 0,
|
|
1350
|
+
a: void 0,
|
|
1351
|
+
n: void 0
|
|
1352
|
+
};
|
|
1153
1353
|
}
|
|
1154
1354
|
const id = generateRef(ctx, current);
|
|
1155
|
-
if (
|
|
1355
|
+
if (typeof id !== "number") {
|
|
1156
1356
|
return id;
|
|
1157
1357
|
}
|
|
1158
1358
|
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
|
|
@@ -1179,17 +1379,24 @@ function generateTreeSync(ctx, current) {
|
|
|
1179
1379
|
}
|
|
1180
1380
|
const empty = current.constructor == null;
|
|
1181
1381
|
if (current.constructor === Object || empty) {
|
|
1182
|
-
return
|
|
1183
|
-
empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1382
|
+
return {
|
|
1383
|
+
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
1384
|
+
i: id,
|
|
1385
|
+
s: void 0,
|
|
1386
|
+
l: void 0,
|
|
1387
|
+
m: void 0,
|
|
1388
|
+
c: void 0,
|
|
1389
|
+
// Parse options first before the items
|
|
1390
|
+
d: serializePropertiesSync(ctx, current),
|
|
1391
|
+
a: void 0,
|
|
1392
|
+
n: void 0
|
|
1393
|
+
};
|
|
1187
1394
|
}
|
|
1188
1395
|
throw new Error("Unsupported value");
|
|
1189
1396
|
}
|
|
1190
1397
|
function parseSync(ctx, current) {
|
|
1191
1398
|
const result = generateTreeSync(ctx, current);
|
|
1192
|
-
return [result, createRef(ctx, current), result
|
|
1399
|
+
return [result, createRef(ctx, current), result.t === 8 /* Object */];
|
|
1193
1400
|
}
|
|
1194
1401
|
|
|
1195
1402
|
// src/index.ts
|