seroval 0.5.1 → 0.6.0
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/README.md +38 -0
- package/dist/cjs/development/index.cjs +236 -72
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +236 -72
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/compat.d.ts +3 -2
- package/dist/types/context.d.ts +3 -4
- package/dist/types/index.d.ts +9 -9
- package/dist/types/tree/async.d.ts +1 -2
- package/dist/types/tree/deserialize.d.ts +1 -2
- package/dist/types/tree/primitives.d.ts +4 -3
- package/dist/types/tree/reference.d.ts +6 -0
- package/dist/types/tree/sync.d.ts +1 -2
- package/dist/types/tree/types.d.ts +23 -5
- package/dist/types/tree/web-api.d.ts +4 -0
- package/dist/types/types.d.ts +2 -1
- package/package.json +3 -3
- package/src/compat.ts +2 -1
- package/src/context.ts +5 -6
- package/src/index.ts +10 -16
- package/src/tree/async.ts +82 -59
- package/src/tree/deserialize.ts +31 -20
- package/src/tree/primitives.ts +25 -3
- package/src/tree/reference.ts +61 -0
- package/src/tree/serialize.ts +30 -23
- package/src/tree/sync.ts +88 -52
- package/src/tree/types.ts +29 -5
- package/src/tree/web-api.ts +42 -0
- package/src/types.ts +6 -1
|
@@ -13,9 +13,10 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
13
13
|
Feature2[Feature2["Symbol"] = 1024] = "Symbol";
|
|
14
14
|
Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
|
|
15
15
|
Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
|
|
16
|
+
Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
|
|
16
17
|
return Feature2;
|
|
17
18
|
})(Feature || {});
|
|
18
|
-
var ALL_ENABLED =
|
|
19
|
+
var ALL_ENABLED = 12287;
|
|
19
20
|
|
|
20
21
|
// src/get-identifier.ts
|
|
21
22
|
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
@@ -81,7 +82,7 @@ function getRootID(ctx, current) {
|
|
|
81
82
|
}
|
|
82
83
|
return ref;
|
|
83
84
|
}
|
|
84
|
-
function
|
|
85
|
+
function createIndexedValue(ctx, current) {
|
|
85
86
|
const ref = ctx.refs.get(current);
|
|
86
87
|
if (ref == null) {
|
|
87
88
|
const id = ctx.refs.size;
|
|
@@ -144,6 +145,59 @@ function invQuote(str) {
|
|
|
144
145
|
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\x3C/g, "<").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\u2028/g, "\u2028").replace(/\\u2029/g, "\u2029");
|
|
145
146
|
}
|
|
146
147
|
|
|
148
|
+
// src/tree/reference.ts
|
|
149
|
+
var REFERENCE = /* @__PURE__ */ new Map();
|
|
150
|
+
var INV_REFERENCE = /* @__PURE__ */ new Map();
|
|
151
|
+
function createReference(id, value) {
|
|
152
|
+
REFERENCE.set(value, id);
|
|
153
|
+
INV_REFERENCE.set(id, value);
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
function hasReferenceID(value) {
|
|
157
|
+
return REFERENCE.has(value);
|
|
158
|
+
}
|
|
159
|
+
function hasReference(id) {
|
|
160
|
+
return INV_REFERENCE.has(id);
|
|
161
|
+
}
|
|
162
|
+
function getReferenceID(value) {
|
|
163
|
+
assert(hasReferenceID(value), "Missing reference id");
|
|
164
|
+
return REFERENCE.get(value);
|
|
165
|
+
}
|
|
166
|
+
function getReference(id) {
|
|
167
|
+
assert(hasReference(id), "Missing reference for id:" + id);
|
|
168
|
+
return INV_REFERENCE.get(id);
|
|
169
|
+
}
|
|
170
|
+
var GLOBAL_KEY = "__SEROVAL__";
|
|
171
|
+
if (typeof globalThis !== void 0) {
|
|
172
|
+
Object.defineProperty(globalThis, GLOBAL_KEY, {
|
|
173
|
+
value: INV_REFERENCE,
|
|
174
|
+
configurable: true,
|
|
175
|
+
writable: false,
|
|
176
|
+
enumerable: false
|
|
177
|
+
});
|
|
178
|
+
} else if (typeof window !== void 0) {
|
|
179
|
+
Object.defineProperty(window, GLOBAL_KEY, {
|
|
180
|
+
value: INV_REFERENCE,
|
|
181
|
+
configurable: true,
|
|
182
|
+
writable: false,
|
|
183
|
+
enumerable: false
|
|
184
|
+
});
|
|
185
|
+
} else if (typeof self !== void 0) {
|
|
186
|
+
Object.defineProperty(self, GLOBAL_KEY, {
|
|
187
|
+
value: INV_REFERENCE,
|
|
188
|
+
configurable: true,
|
|
189
|
+
writable: false,
|
|
190
|
+
enumerable: false
|
|
191
|
+
});
|
|
192
|
+
} else if (typeof global !== void 0) {
|
|
193
|
+
Object.defineProperty(global, GLOBAL_KEY, {
|
|
194
|
+
value: INV_REFERENCE,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: false,
|
|
197
|
+
enumerable: false
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
147
201
|
// src/tree/symbols.ts
|
|
148
202
|
var SYMBOL_STRING = {
|
|
149
203
|
[0 /* AsyncIterator */]: "Symbol.asyncIterator",
|
|
@@ -320,9 +374,9 @@ function createBigIntNode(ctx, current) {
|
|
|
320
374
|
f: void 0
|
|
321
375
|
};
|
|
322
376
|
}
|
|
323
|
-
function
|
|
377
|
+
function createIndexedValueNode(id) {
|
|
324
378
|
return {
|
|
325
|
-
t: 10 /*
|
|
379
|
+
t: 10 /* IndexedValue */,
|
|
326
380
|
i: id,
|
|
327
381
|
s: void 0,
|
|
328
382
|
l: void 0,
|
|
@@ -403,7 +457,9 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
403
457
|
f: void 0
|
|
404
458
|
};
|
|
405
459
|
}
|
|
406
|
-
function createWKSymbolNode(current) {
|
|
460
|
+
function createWKSymbolNode(ctx, current) {
|
|
461
|
+
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
|
|
462
|
+
assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
|
|
407
463
|
return {
|
|
408
464
|
t: 24 /* WKSymbol */,
|
|
409
465
|
i: void 0,
|
|
@@ -416,6 +472,19 @@ function createWKSymbolNode(current) {
|
|
|
416
472
|
f: void 0
|
|
417
473
|
};
|
|
418
474
|
}
|
|
475
|
+
function createReferenceNode(id, ref) {
|
|
476
|
+
return {
|
|
477
|
+
t: 27 /* Reference */,
|
|
478
|
+
i: id,
|
|
479
|
+
s: quote(getReferenceID(ref)),
|
|
480
|
+
l: void 0,
|
|
481
|
+
c: void 0,
|
|
482
|
+
m: void 0,
|
|
483
|
+
d: void 0,
|
|
484
|
+
a: void 0,
|
|
485
|
+
f: void 0
|
|
486
|
+
};
|
|
487
|
+
}
|
|
419
488
|
|
|
420
489
|
// src/tree/shared.ts
|
|
421
490
|
function getErrorConstructorName(error) {
|
|
@@ -555,6 +624,36 @@ function isValidIdentifier(name) {
|
|
|
555
624
|
return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
|
|
556
625
|
}
|
|
557
626
|
|
|
627
|
+
// src/tree/web-api.ts
|
|
628
|
+
function createURLNode(ctx, id, current) {
|
|
629
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URL"');
|
|
630
|
+
return {
|
|
631
|
+
t: 25 /* URL */,
|
|
632
|
+
i: id,
|
|
633
|
+
s: current.href,
|
|
634
|
+
l: void 0,
|
|
635
|
+
c: void 0,
|
|
636
|
+
m: void 0,
|
|
637
|
+
d: void 0,
|
|
638
|
+
f: void 0,
|
|
639
|
+
a: void 0
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
function createURLSearchParamsNode(ctx, id, current) {
|
|
643
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URLSearchParams"');
|
|
644
|
+
return {
|
|
645
|
+
t: 26 /* URLSearchParams */,
|
|
646
|
+
i: id,
|
|
647
|
+
s: current.toString(),
|
|
648
|
+
l: void 0,
|
|
649
|
+
c: void 0,
|
|
650
|
+
m: void 0,
|
|
651
|
+
d: void 0,
|
|
652
|
+
f: void 0,
|
|
653
|
+
a: void 0
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
558
657
|
// src/tree/async.ts
|
|
559
658
|
async function generateNodeList(ctx, current) {
|
|
560
659
|
const size = current.length;
|
|
@@ -748,7 +847,7 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
748
847
|
s: void 0,
|
|
749
848
|
l: current.errors.length,
|
|
750
849
|
c: void 0,
|
|
751
|
-
m: current.message,
|
|
850
|
+
m: quote(current.message),
|
|
752
851
|
d: optionsNode,
|
|
753
852
|
a: await generateNodeList(ctx, current.errors),
|
|
754
853
|
f: void 0
|
|
@@ -763,7 +862,7 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
763
862
|
s: void 0,
|
|
764
863
|
l: void 0,
|
|
765
864
|
c: getErrorConstructorName(current),
|
|
766
|
-
m: current.message,
|
|
865
|
+
m: quote(current.message),
|
|
767
866
|
d: optionsNode,
|
|
768
867
|
a: void 0,
|
|
769
868
|
f: void 0
|
|
@@ -784,24 +883,26 @@ async function parse(ctx, current) {
|
|
|
784
883
|
case -Infinity:
|
|
785
884
|
return NEG_INFINITY_NODE;
|
|
786
885
|
default:
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
886
|
+
if (current !== current) {
|
|
887
|
+
return NAN_NODE;
|
|
888
|
+
}
|
|
889
|
+
if (Object.is(current, -0)) {
|
|
890
|
+
return NEG_ZERO_NODE;
|
|
891
|
+
}
|
|
892
|
+
return createNumberNode(current);
|
|
794
893
|
}
|
|
795
|
-
return createNumberNode(current);
|
|
796
894
|
case "bigint":
|
|
797
895
|
return createBigIntNode(ctx, current);
|
|
798
896
|
case "object": {
|
|
799
897
|
if (!current) {
|
|
800
898
|
return NULL_NODE;
|
|
801
899
|
}
|
|
802
|
-
const id =
|
|
900
|
+
const id = createIndexedValue(ctx, current);
|
|
803
901
|
if (ctx.markedRefs.has(id)) {
|
|
804
|
-
return
|
|
902
|
+
return createIndexedValueNode(id);
|
|
903
|
+
}
|
|
904
|
+
if (hasReferenceID(current)) {
|
|
905
|
+
return createReferenceNode(id, current);
|
|
805
906
|
}
|
|
806
907
|
if (Array.isArray(current)) {
|
|
807
908
|
return generateArrayNode(ctx, id, current);
|
|
@@ -865,6 +966,10 @@ async function parse(ctx, current) {
|
|
|
865
966
|
case TypeError:
|
|
866
967
|
case URIError:
|
|
867
968
|
return generateErrorNode(ctx, id, current);
|
|
969
|
+
case URL:
|
|
970
|
+
return createURLNode(ctx, id, current);
|
|
971
|
+
case URLSearchParams:
|
|
972
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
868
973
|
default:
|
|
869
974
|
break;
|
|
870
975
|
}
|
|
@@ -889,9 +994,22 @@ async function parse(ctx, current) {
|
|
|
889
994
|
throw new Error("Unsupported type");
|
|
890
995
|
}
|
|
891
996
|
case "symbol":
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
997
|
+
if (hasReferenceID(current)) {
|
|
998
|
+
const id = createIndexedValue(ctx, current);
|
|
999
|
+
if (ctx.markedRefs.has(id)) {
|
|
1000
|
+
return createIndexedValueNode(id);
|
|
1001
|
+
}
|
|
1002
|
+
return createReferenceNode(id, current);
|
|
1003
|
+
}
|
|
1004
|
+
return createWKSymbolNode(ctx, current);
|
|
1005
|
+
case "function": {
|
|
1006
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1007
|
+
const id = createIndexedValue(ctx, current);
|
|
1008
|
+
if (ctx.markedRefs.has(id)) {
|
|
1009
|
+
return createIndexedValueNode(id);
|
|
1010
|
+
}
|
|
1011
|
+
return createReferenceNode(id, current);
|
|
1012
|
+
}
|
|
895
1013
|
default:
|
|
896
1014
|
throw new Error("Unsupported type");
|
|
897
1015
|
}
|
|
@@ -903,7 +1021,7 @@ async function parseAsync(ctx, current) {
|
|
|
903
1021
|
}
|
|
904
1022
|
|
|
905
1023
|
// src/tree/deserialize.ts
|
|
906
|
-
function
|
|
1024
|
+
function assignIndexedValue(ctx, index, value) {
|
|
907
1025
|
ctx.valueMap.set(index, value);
|
|
908
1026
|
return value;
|
|
909
1027
|
}
|
|
@@ -918,7 +1036,7 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
918
1036
|
return result;
|
|
919
1037
|
}
|
|
920
1038
|
function deserializeArray(ctx, node) {
|
|
921
|
-
const result =
|
|
1039
|
+
const result = assignIndexedValue(
|
|
922
1040
|
ctx,
|
|
923
1041
|
node.i,
|
|
924
1042
|
new Array(node.l)
|
|
@@ -938,21 +1056,25 @@ function deserializeProperties(ctx, node, result) {
|
|
|
938
1056
|
return result;
|
|
939
1057
|
}
|
|
940
1058
|
function deserializeNullConstructor(ctx, node) {
|
|
941
|
-
const result =
|
|
1059
|
+
const result = assignIndexedValue(
|
|
1060
|
+
ctx,
|
|
1061
|
+
node.i,
|
|
1062
|
+
/* @__PURE__ */ Object.create(null)
|
|
1063
|
+
);
|
|
942
1064
|
ctx.stack.push(node.i);
|
|
943
1065
|
deserializeProperties(ctx, node.d, result);
|
|
944
1066
|
ctx.stack.pop();
|
|
945
1067
|
return result;
|
|
946
1068
|
}
|
|
947
1069
|
function deserializeObject(ctx, node) {
|
|
948
|
-
const result =
|
|
1070
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
949
1071
|
ctx.stack.push(node.i);
|
|
950
1072
|
deserializeProperties(ctx, node.d, result);
|
|
951
1073
|
ctx.stack.pop();
|
|
952
1074
|
return result;
|
|
953
1075
|
}
|
|
954
1076
|
function deserializeSet(ctx, node) {
|
|
955
|
-
const result =
|
|
1077
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
956
1078
|
ctx.stack.push(node.i);
|
|
957
1079
|
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
958
1080
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
@@ -961,7 +1083,7 @@ function deserializeSet(ctx, node) {
|
|
|
961
1083
|
return result;
|
|
962
1084
|
}
|
|
963
1085
|
function deserializeMap(ctx, node) {
|
|
964
|
-
const result =
|
|
1086
|
+
const result = assignIndexedValue(
|
|
965
1087
|
ctx,
|
|
966
1088
|
node.i,
|
|
967
1089
|
/* @__PURE__ */ new Map()
|
|
@@ -986,7 +1108,7 @@ function deserializeDictionary(ctx, node, result) {
|
|
|
986
1108
|
return result;
|
|
987
1109
|
}
|
|
988
1110
|
function deserializeAggregateError(ctx, node) {
|
|
989
|
-
const result =
|
|
1111
|
+
const result = assignIndexedValue(ctx, node.i, new AggregateError([], invQuote(node.m)));
|
|
990
1112
|
ctx.stack.push(node.i);
|
|
991
1113
|
result.errors = deserializeNodeList(ctx, node, new Array(node.l));
|
|
992
1114
|
ctx.stack.pop();
|
|
@@ -994,7 +1116,7 @@ function deserializeAggregateError(ctx, node) {
|
|
|
994
1116
|
}
|
|
995
1117
|
function deserializeError(ctx, node) {
|
|
996
1118
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
997
|
-
const result =
|
|
1119
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(invQuote(node.m)));
|
|
998
1120
|
return deserializeDictionary(ctx, node, result);
|
|
999
1121
|
}
|
|
1000
1122
|
function createDeferred() {
|
|
@@ -1010,14 +1132,14 @@ function createDeferred() {
|
|
|
1010
1132
|
}
|
|
1011
1133
|
function deserializePromise(ctx, node) {
|
|
1012
1134
|
const deferred = createDeferred();
|
|
1013
|
-
const result =
|
|
1135
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1014
1136
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1015
1137
|
return result;
|
|
1016
1138
|
}
|
|
1017
1139
|
function deserializeTypedArray(ctx, node) {
|
|
1018
1140
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1019
1141
|
const dummy = new TypedArray();
|
|
1020
|
-
const result =
|
|
1142
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1021
1143
|
dummy.buffer,
|
|
1022
1144
|
node.l
|
|
1023
1145
|
));
|
|
@@ -1029,7 +1151,7 @@ function deserializeTypedArray(ctx, node) {
|
|
|
1029
1151
|
function deserializeIterable(ctx, node) {
|
|
1030
1152
|
const values = [];
|
|
1031
1153
|
deserializeNodeList(ctx, node, values);
|
|
1032
|
-
const result =
|
|
1154
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1033
1155
|
[Symbol.iterator]: () => values.values()
|
|
1034
1156
|
});
|
|
1035
1157
|
return deserializeDictionary(ctx, node, result);
|
|
@@ -1055,7 +1177,7 @@ function deserializeTree(ctx, node) {
|
|
|
1055
1177
|
return NaN;
|
|
1056
1178
|
case 9 /* BigInt */:
|
|
1057
1179
|
return BigInt(node.s);
|
|
1058
|
-
case 10 /*
|
|
1180
|
+
case 10 /* IndexedValue */:
|
|
1059
1181
|
return ctx.valueMap.get(node.i);
|
|
1060
1182
|
case 15 /* Array */:
|
|
1061
1183
|
return deserializeArray(ctx, node);
|
|
@@ -1064,9 +1186,9 @@ function deserializeTree(ctx, node) {
|
|
|
1064
1186
|
case 17 /* NullConstructor */:
|
|
1065
1187
|
return deserializeNullConstructor(ctx, node);
|
|
1066
1188
|
case 11 /* Date */:
|
|
1067
|
-
return
|
|
1189
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1068
1190
|
case 12 /* RegExp */:
|
|
1069
|
-
return
|
|
1191
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1070
1192
|
case 13 /* Set */:
|
|
1071
1193
|
return deserializeSet(ctx, node);
|
|
1072
1194
|
case 14 /* Map */:
|
|
@@ -1084,6 +1206,12 @@ function deserializeTree(ctx, node) {
|
|
|
1084
1206
|
return deserializePromise(ctx, node);
|
|
1085
1207
|
case 24 /* WKSymbol */:
|
|
1086
1208
|
return SYMBOL_REF[node.s];
|
|
1209
|
+
case 25 /* URL */:
|
|
1210
|
+
return assignIndexedValue(ctx, node.i, new URL(node.s));
|
|
1211
|
+
case 26 /* URLSearchParams */:
|
|
1212
|
+
return assignIndexedValue(ctx, node.i, new URLSearchParams(node.s));
|
|
1213
|
+
case 27 /* Reference */:
|
|
1214
|
+
return assignIndexedValue(ctx, node.i, getReference(invQuote(node.s)));
|
|
1087
1215
|
default:
|
|
1088
1216
|
throw new Error("Unsupported type");
|
|
1089
1217
|
}
|
|
@@ -1210,14 +1338,14 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
1210
1338
|
markRef(ctx, ref);
|
|
1211
1339
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1212
1340
|
}
|
|
1213
|
-
function
|
|
1341
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1214
1342
|
if (ctx.markedRefs.has(index)) {
|
|
1215
1343
|
return getRefParam(ctx, index) + "=" + value;
|
|
1216
1344
|
}
|
|
1217
1345
|
return value;
|
|
1218
1346
|
}
|
|
1219
|
-
function
|
|
1220
|
-
return node.t === 10 /*
|
|
1347
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1348
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1221
1349
|
}
|
|
1222
1350
|
function serializeNodeList(ctx, node) {
|
|
1223
1351
|
const size = node.l;
|
|
@@ -1230,7 +1358,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1230
1358
|
}
|
|
1231
1359
|
item = node.a[i];
|
|
1232
1360
|
if (item) {
|
|
1233
|
-
if (
|
|
1361
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1234
1362
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1235
1363
|
isHoley = true;
|
|
1236
1364
|
} else {
|
|
@@ -1247,7 +1375,7 @@ function serializeArray(ctx, node) {
|
|
|
1247
1375
|
ctx.stack.push(node.i);
|
|
1248
1376
|
const result = serializeNodeList(ctx, node);
|
|
1249
1377
|
ctx.stack.pop();
|
|
1250
|
-
return
|
|
1378
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1251
1379
|
}
|
|
1252
1380
|
function serializeProperties(ctx, sourceID, node) {
|
|
1253
1381
|
if (node.s === 0) {
|
|
@@ -1266,7 +1394,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1266
1394
|
val = node.v[i];
|
|
1267
1395
|
check = Number(key);
|
|
1268
1396
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1269
|
-
if (
|
|
1397
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1270
1398
|
refParam = getRefParam(ctx, val.i);
|
|
1271
1399
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1272
1400
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
@@ -1325,17 +1453,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1325
1453
|
markRef(ctx, i);
|
|
1326
1454
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1327
1455
|
if (assignments) {
|
|
1328
|
-
return "(" +
|
|
1456
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1329
1457
|
}
|
|
1330
1458
|
}
|
|
1331
1459
|
}
|
|
1332
|
-
return
|
|
1460
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1333
1461
|
}
|
|
1334
1462
|
function serializeNullConstructor(ctx, node) {
|
|
1335
1463
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1336
1464
|
}
|
|
1337
1465
|
function serializeObject(ctx, node) {
|
|
1338
|
-
return
|
|
1466
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1339
1467
|
}
|
|
1340
1468
|
function serializeSet(ctx, node) {
|
|
1341
1469
|
let serialized = "new Set";
|
|
@@ -1347,7 +1475,7 @@ function serializeSet(ctx, node) {
|
|
|
1347
1475
|
let hasPrev = false;
|
|
1348
1476
|
for (let i = 0; i < size; i++) {
|
|
1349
1477
|
item = node.a[i];
|
|
1350
|
-
if (
|
|
1478
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1351
1479
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1352
1480
|
} else {
|
|
1353
1481
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
@@ -1359,7 +1487,7 @@ function serializeSet(ctx, node) {
|
|
|
1359
1487
|
serialized += "([" + result + "])";
|
|
1360
1488
|
}
|
|
1361
1489
|
}
|
|
1362
|
-
return
|
|
1490
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1363
1491
|
}
|
|
1364
1492
|
function serializeMap(ctx, node) {
|
|
1365
1493
|
let serialized = "new Map";
|
|
@@ -1375,9 +1503,9 @@ function serializeMap(ctx, node) {
|
|
|
1375
1503
|
for (let i = 0; i < node.d.s; i++) {
|
|
1376
1504
|
key = node.d.k[i];
|
|
1377
1505
|
val = node.d.v[i];
|
|
1378
|
-
if (
|
|
1506
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1379
1507
|
keyRef = getRefParam(ctx, key.i);
|
|
1380
|
-
if (
|
|
1508
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1381
1509
|
valueRef = getRefParam(ctx, val.i);
|
|
1382
1510
|
createMapSet(ctx, node.i, keyRef, valueRef);
|
|
1383
1511
|
} else {
|
|
@@ -1386,7 +1514,7 @@ function serializeMap(ctx, node) {
|
|
|
1386
1514
|
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1387
1515
|
ctx.stack = parent;
|
|
1388
1516
|
}
|
|
1389
|
-
} else if (
|
|
1517
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1390
1518
|
valueRef = getRefParam(ctx, val.i);
|
|
1391
1519
|
parent = ctx.stack;
|
|
1392
1520
|
ctx.stack = [];
|
|
@@ -1402,7 +1530,7 @@ function serializeMap(ctx, node) {
|
|
|
1402
1530
|
serialized += "([" + result + "])";
|
|
1403
1531
|
}
|
|
1404
1532
|
}
|
|
1405
|
-
return
|
|
1533
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1406
1534
|
}
|
|
1407
1535
|
function serializeAggregateError(ctx, node) {
|
|
1408
1536
|
ctx.stack.push(node.i);
|
|
@@ -1416,7 +1544,7 @@ function serializeError(ctx, node) {
|
|
|
1416
1544
|
}
|
|
1417
1545
|
function serializePromise(ctx, node) {
|
|
1418
1546
|
let serialized;
|
|
1419
|
-
if (
|
|
1547
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1420
1548
|
const ref = getRefParam(ctx, node.f.i);
|
|
1421
1549
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1422
1550
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
@@ -1429,7 +1557,7 @@ function serializePromise(ctx, node) {
|
|
|
1429
1557
|
ctx.stack.pop();
|
|
1430
1558
|
serialized = "Promise.resolve(" + result + ")";
|
|
1431
1559
|
}
|
|
1432
|
-
return
|
|
1560
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1433
1561
|
}
|
|
1434
1562
|
function serializeTypedArray(ctx, node) {
|
|
1435
1563
|
let result = "";
|
|
@@ -1438,7 +1566,7 @@ function serializeTypedArray(ctx, node) {
|
|
|
1438
1566
|
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1439
1567
|
}
|
|
1440
1568
|
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1441
|
-
return
|
|
1569
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1442
1570
|
}
|
|
1443
1571
|
function serializeIterable(ctx, node) {
|
|
1444
1572
|
const parent = ctx.stack;
|
|
@@ -1482,7 +1610,7 @@ function serializeTree(ctx, node) {
|
|
|
1482
1610
|
return "NaN";
|
|
1483
1611
|
case 9 /* BigInt */:
|
|
1484
1612
|
return node.s + "n";
|
|
1485
|
-
case 10 /*
|
|
1613
|
+
case 10 /* IndexedValue */:
|
|
1486
1614
|
return getRefParam(ctx, node.i);
|
|
1487
1615
|
case 15 /* Array */:
|
|
1488
1616
|
return serializeArray(ctx, node);
|
|
@@ -1491,9 +1619,9 @@ function serializeTree(ctx, node) {
|
|
|
1491
1619
|
case 17 /* NullConstructor */:
|
|
1492
1620
|
return serializeNullConstructor(ctx, node);
|
|
1493
1621
|
case 11 /* Date */:
|
|
1494
|
-
return
|
|
1622
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1495
1623
|
case 12 /* RegExp */:
|
|
1496
|
-
return
|
|
1624
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1497
1625
|
case 13 /* Set */:
|
|
1498
1626
|
return serializeSet(ctx, node);
|
|
1499
1627
|
case 14 /* Map */:
|
|
@@ -1511,6 +1639,12 @@ function serializeTree(ctx, node) {
|
|
|
1511
1639
|
return serializePromise(ctx, node);
|
|
1512
1640
|
case 24 /* WKSymbol */:
|
|
1513
1641
|
return SYMBOL_STRING[node.s];
|
|
1642
|
+
case 25 /* URL */:
|
|
1643
|
+
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
1644
|
+
case 26 /* URLSearchParams */:
|
|
1645
|
+
return assignIndexedValue2(ctx, node.i, node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams");
|
|
1646
|
+
case 27 /* Reference */:
|
|
1647
|
+
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
1514
1648
|
default:
|
|
1515
1649
|
throw new Error("Unsupported type");
|
|
1516
1650
|
}
|
|
@@ -1691,7 +1825,7 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1691
1825
|
s: void 0,
|
|
1692
1826
|
l: current.errors.length,
|
|
1693
1827
|
c: void 0,
|
|
1694
|
-
m: current.message,
|
|
1828
|
+
m: quote(current.message),
|
|
1695
1829
|
d: optionsNode,
|
|
1696
1830
|
a: generateNodeList2(ctx, current.errors),
|
|
1697
1831
|
f: void 0
|
|
@@ -1706,7 +1840,7 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1706
1840
|
s: void 0,
|
|
1707
1841
|
l: void 0,
|
|
1708
1842
|
c: getErrorConstructorName(current),
|
|
1709
|
-
m: current.message,
|
|
1843
|
+
m: quote(current.message),
|
|
1710
1844
|
d: optionsNode,
|
|
1711
1845
|
a: void 0,
|
|
1712
1846
|
f: void 0
|
|
@@ -1727,24 +1861,26 @@ function parse2(ctx, current) {
|
|
|
1727
1861
|
case -Infinity:
|
|
1728
1862
|
return NEG_INFINITY_NODE;
|
|
1729
1863
|
default:
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1864
|
+
if (current !== current) {
|
|
1865
|
+
return NAN_NODE;
|
|
1866
|
+
}
|
|
1867
|
+
if (Object.is(current, -0)) {
|
|
1868
|
+
return NEG_ZERO_NODE;
|
|
1869
|
+
}
|
|
1870
|
+
return createNumberNode(current);
|
|
1737
1871
|
}
|
|
1738
|
-
return createNumberNode(current);
|
|
1739
1872
|
case "bigint":
|
|
1740
1873
|
return createBigIntNode(ctx, current);
|
|
1741
1874
|
case "object": {
|
|
1742
1875
|
if (!current) {
|
|
1743
1876
|
return NULL_NODE;
|
|
1744
1877
|
}
|
|
1745
|
-
const id =
|
|
1878
|
+
const id = createIndexedValue(ctx, current);
|
|
1746
1879
|
if (ctx.markedRefs.has(id)) {
|
|
1747
|
-
return
|
|
1880
|
+
return createIndexedValueNode(id);
|
|
1881
|
+
}
|
|
1882
|
+
if (hasReferenceID(current)) {
|
|
1883
|
+
return createReferenceNode(id, current);
|
|
1748
1884
|
}
|
|
1749
1885
|
if (Array.isArray(current)) {
|
|
1750
1886
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1772,9 +1908,19 @@ function parse2(ctx, current) {
|
|
|
1772
1908
|
case Set:
|
|
1773
1909
|
return generateSetNode2(ctx, id, current);
|
|
1774
1910
|
case Object:
|
|
1775
|
-
return generateObjectNode2(
|
|
1911
|
+
return generateObjectNode2(
|
|
1912
|
+
ctx,
|
|
1913
|
+
id,
|
|
1914
|
+
current,
|
|
1915
|
+
false
|
|
1916
|
+
);
|
|
1776
1917
|
case void 0:
|
|
1777
|
-
return generateObjectNode2(
|
|
1918
|
+
return generateObjectNode2(
|
|
1919
|
+
ctx,
|
|
1920
|
+
id,
|
|
1921
|
+
current,
|
|
1922
|
+
true
|
|
1923
|
+
);
|
|
1778
1924
|
case AggregateError:
|
|
1779
1925
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1780
1926
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1788,6 +1934,10 @@ function parse2(ctx, current) {
|
|
|
1788
1934
|
case TypeError:
|
|
1789
1935
|
case URIError:
|
|
1790
1936
|
return generateErrorNode2(ctx, id, current);
|
|
1937
|
+
case URL:
|
|
1938
|
+
return createURLNode(ctx, id, current);
|
|
1939
|
+
case URLSearchParams:
|
|
1940
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1791
1941
|
default:
|
|
1792
1942
|
break;
|
|
1793
1943
|
}
|
|
@@ -1806,9 +1956,22 @@ function parse2(ctx, current) {
|
|
|
1806
1956
|
throw new Error("Unsupported type");
|
|
1807
1957
|
}
|
|
1808
1958
|
case "symbol":
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1959
|
+
if (hasReferenceID(current)) {
|
|
1960
|
+
const id = createIndexedValue(ctx, current);
|
|
1961
|
+
if (ctx.markedRefs.has(id)) {
|
|
1962
|
+
return createIndexedValueNode(id);
|
|
1963
|
+
}
|
|
1964
|
+
return createReferenceNode(id, current);
|
|
1965
|
+
}
|
|
1966
|
+
return createWKSymbolNode(ctx, current);
|
|
1967
|
+
case "function": {
|
|
1968
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1969
|
+
const id = createIndexedValue(ctx, current);
|
|
1970
|
+
if (ctx.markedRefs.has(id)) {
|
|
1971
|
+
return createIndexedValueNode(id);
|
|
1972
|
+
}
|
|
1973
|
+
return createReferenceNode(id, current);
|
|
1974
|
+
}
|
|
1812
1975
|
default:
|
|
1813
1976
|
throw new Error("Unsupported type");
|
|
1814
1977
|
}
|
|
@@ -1901,6 +2064,7 @@ var src_default = serialize;
|
|
|
1901
2064
|
export {
|
|
1902
2065
|
Feature,
|
|
1903
2066
|
compileJSON,
|
|
2067
|
+
createReference,
|
|
1904
2068
|
src_default as default,
|
|
1905
2069
|
deserialize,
|
|
1906
2070
|
fromJSON,
|