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
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Feature: () => Feature,
|
|
24
24
|
compileJSON: () => compileJSON,
|
|
25
|
+
createReference: () => createReference,
|
|
25
26
|
default: () => src_default,
|
|
26
27
|
deserialize: () => deserialize,
|
|
27
28
|
fromJSON: () => fromJSON,
|
|
@@ -47,9 +48,10 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
47
48
|
Feature2[Feature2["Symbol"] = 1024] = "Symbol";
|
|
48
49
|
Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
|
|
49
50
|
Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
|
|
51
|
+
Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
|
|
50
52
|
return Feature2;
|
|
51
53
|
})(Feature || {});
|
|
52
|
-
var ALL_ENABLED =
|
|
54
|
+
var ALL_ENABLED = 12287;
|
|
53
55
|
|
|
54
56
|
// src/get-identifier.ts
|
|
55
57
|
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
@@ -115,7 +117,7 @@ function getRootID(ctx, current) {
|
|
|
115
117
|
}
|
|
116
118
|
return ref;
|
|
117
119
|
}
|
|
118
|
-
function
|
|
120
|
+
function createIndexedValue(ctx, current) {
|
|
119
121
|
const ref = ctx.refs.get(current);
|
|
120
122
|
if (ref == null) {
|
|
121
123
|
const id = ctx.refs.size;
|
|
@@ -178,6 +180,59 @@ function invQuote(str) {
|
|
|
178
180
|
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");
|
|
179
181
|
}
|
|
180
182
|
|
|
183
|
+
// src/tree/reference.ts
|
|
184
|
+
var REFERENCE = /* @__PURE__ */ new Map();
|
|
185
|
+
var INV_REFERENCE = /* @__PURE__ */ new Map();
|
|
186
|
+
function createReference(id, value) {
|
|
187
|
+
REFERENCE.set(value, id);
|
|
188
|
+
INV_REFERENCE.set(id, value);
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
function hasReferenceID(value) {
|
|
192
|
+
return REFERENCE.has(value);
|
|
193
|
+
}
|
|
194
|
+
function hasReference(id) {
|
|
195
|
+
return INV_REFERENCE.has(id);
|
|
196
|
+
}
|
|
197
|
+
function getReferenceID(value) {
|
|
198
|
+
assert(hasReferenceID(value), "Missing reference id");
|
|
199
|
+
return REFERENCE.get(value);
|
|
200
|
+
}
|
|
201
|
+
function getReference(id) {
|
|
202
|
+
assert(hasReference(id), "Missing reference for id:" + id);
|
|
203
|
+
return INV_REFERENCE.get(id);
|
|
204
|
+
}
|
|
205
|
+
var GLOBAL_KEY = "__SEROVAL__";
|
|
206
|
+
if (typeof globalThis !== void 0) {
|
|
207
|
+
Object.defineProperty(globalThis, GLOBAL_KEY, {
|
|
208
|
+
value: INV_REFERENCE,
|
|
209
|
+
configurable: true,
|
|
210
|
+
writable: false,
|
|
211
|
+
enumerable: false
|
|
212
|
+
});
|
|
213
|
+
} else if (typeof window !== void 0) {
|
|
214
|
+
Object.defineProperty(window, GLOBAL_KEY, {
|
|
215
|
+
value: INV_REFERENCE,
|
|
216
|
+
configurable: true,
|
|
217
|
+
writable: false,
|
|
218
|
+
enumerable: false
|
|
219
|
+
});
|
|
220
|
+
} else if (typeof self !== void 0) {
|
|
221
|
+
Object.defineProperty(self, GLOBAL_KEY, {
|
|
222
|
+
value: INV_REFERENCE,
|
|
223
|
+
configurable: true,
|
|
224
|
+
writable: false,
|
|
225
|
+
enumerable: false
|
|
226
|
+
});
|
|
227
|
+
} else if (typeof global !== void 0) {
|
|
228
|
+
Object.defineProperty(global, GLOBAL_KEY, {
|
|
229
|
+
value: INV_REFERENCE,
|
|
230
|
+
configurable: true,
|
|
231
|
+
writable: false,
|
|
232
|
+
enumerable: false
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
181
236
|
// src/tree/symbols.ts
|
|
182
237
|
var SYMBOL_STRING = {
|
|
183
238
|
[0 /* AsyncIterator */]: "Symbol.asyncIterator",
|
|
@@ -354,9 +409,9 @@ function createBigIntNode(ctx, current) {
|
|
|
354
409
|
f: void 0
|
|
355
410
|
};
|
|
356
411
|
}
|
|
357
|
-
function
|
|
412
|
+
function createIndexedValueNode(id) {
|
|
358
413
|
return {
|
|
359
|
-
t: 10 /*
|
|
414
|
+
t: 10 /* IndexedValue */,
|
|
360
415
|
i: id,
|
|
361
416
|
s: void 0,
|
|
362
417
|
l: void 0,
|
|
@@ -437,7 +492,9 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
437
492
|
f: void 0
|
|
438
493
|
};
|
|
439
494
|
}
|
|
440
|
-
function createWKSymbolNode(current) {
|
|
495
|
+
function createWKSymbolNode(ctx, current) {
|
|
496
|
+
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
|
|
497
|
+
assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
|
|
441
498
|
return {
|
|
442
499
|
t: 24 /* WKSymbol */,
|
|
443
500
|
i: void 0,
|
|
@@ -450,6 +507,19 @@ function createWKSymbolNode(current) {
|
|
|
450
507
|
f: void 0
|
|
451
508
|
};
|
|
452
509
|
}
|
|
510
|
+
function createReferenceNode(id, ref) {
|
|
511
|
+
return {
|
|
512
|
+
t: 27 /* Reference */,
|
|
513
|
+
i: id,
|
|
514
|
+
s: quote(getReferenceID(ref)),
|
|
515
|
+
l: void 0,
|
|
516
|
+
c: void 0,
|
|
517
|
+
m: void 0,
|
|
518
|
+
d: void 0,
|
|
519
|
+
a: void 0,
|
|
520
|
+
f: void 0
|
|
521
|
+
};
|
|
522
|
+
}
|
|
453
523
|
|
|
454
524
|
// src/tree/shared.ts
|
|
455
525
|
function getErrorConstructorName(error) {
|
|
@@ -589,6 +659,36 @@ function isValidIdentifier(name) {
|
|
|
589
659
|
return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
|
|
590
660
|
}
|
|
591
661
|
|
|
662
|
+
// src/tree/web-api.ts
|
|
663
|
+
function createURLNode(ctx, id, current) {
|
|
664
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URL"');
|
|
665
|
+
return {
|
|
666
|
+
t: 25 /* URL */,
|
|
667
|
+
i: id,
|
|
668
|
+
s: current.href,
|
|
669
|
+
l: void 0,
|
|
670
|
+
c: void 0,
|
|
671
|
+
m: void 0,
|
|
672
|
+
d: void 0,
|
|
673
|
+
f: void 0,
|
|
674
|
+
a: void 0
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function createURLSearchParamsNode(ctx, id, current) {
|
|
678
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URLSearchParams"');
|
|
679
|
+
return {
|
|
680
|
+
t: 26 /* URLSearchParams */,
|
|
681
|
+
i: id,
|
|
682
|
+
s: current.toString(),
|
|
683
|
+
l: void 0,
|
|
684
|
+
c: void 0,
|
|
685
|
+
m: void 0,
|
|
686
|
+
d: void 0,
|
|
687
|
+
f: void 0,
|
|
688
|
+
a: void 0
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
592
692
|
// src/tree/async.ts
|
|
593
693
|
async function generateNodeList(ctx, current) {
|
|
594
694
|
const size = current.length;
|
|
@@ -782,7 +882,7 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
782
882
|
s: void 0,
|
|
783
883
|
l: current.errors.length,
|
|
784
884
|
c: void 0,
|
|
785
|
-
m: current.message,
|
|
885
|
+
m: quote(current.message),
|
|
786
886
|
d: optionsNode,
|
|
787
887
|
a: await generateNodeList(ctx, current.errors),
|
|
788
888
|
f: void 0
|
|
@@ -797,7 +897,7 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
797
897
|
s: void 0,
|
|
798
898
|
l: void 0,
|
|
799
899
|
c: getErrorConstructorName(current),
|
|
800
|
-
m: current.message,
|
|
900
|
+
m: quote(current.message),
|
|
801
901
|
d: optionsNode,
|
|
802
902
|
a: void 0,
|
|
803
903
|
f: void 0
|
|
@@ -818,24 +918,26 @@ async function parse(ctx, current) {
|
|
|
818
918
|
case -Infinity:
|
|
819
919
|
return NEG_INFINITY_NODE;
|
|
820
920
|
default:
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
921
|
+
if (current !== current) {
|
|
922
|
+
return NAN_NODE;
|
|
923
|
+
}
|
|
924
|
+
if (Object.is(current, -0)) {
|
|
925
|
+
return NEG_ZERO_NODE;
|
|
926
|
+
}
|
|
927
|
+
return createNumberNode(current);
|
|
828
928
|
}
|
|
829
|
-
return createNumberNode(current);
|
|
830
929
|
case "bigint":
|
|
831
930
|
return createBigIntNode(ctx, current);
|
|
832
931
|
case "object": {
|
|
833
932
|
if (!current) {
|
|
834
933
|
return NULL_NODE;
|
|
835
934
|
}
|
|
836
|
-
const id =
|
|
935
|
+
const id = createIndexedValue(ctx, current);
|
|
837
936
|
if (ctx.markedRefs.has(id)) {
|
|
838
|
-
return
|
|
937
|
+
return createIndexedValueNode(id);
|
|
938
|
+
}
|
|
939
|
+
if (hasReferenceID(current)) {
|
|
940
|
+
return createReferenceNode(id, current);
|
|
839
941
|
}
|
|
840
942
|
if (Array.isArray(current)) {
|
|
841
943
|
return generateArrayNode(ctx, id, current);
|
|
@@ -899,6 +1001,10 @@ async function parse(ctx, current) {
|
|
|
899
1001
|
case TypeError:
|
|
900
1002
|
case URIError:
|
|
901
1003
|
return generateErrorNode(ctx, id, current);
|
|
1004
|
+
case URL:
|
|
1005
|
+
return createURLNode(ctx, id, current);
|
|
1006
|
+
case URLSearchParams:
|
|
1007
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
902
1008
|
default:
|
|
903
1009
|
break;
|
|
904
1010
|
}
|
|
@@ -923,9 +1029,22 @@ async function parse(ctx, current) {
|
|
|
923
1029
|
throw new Error("Unsupported type");
|
|
924
1030
|
}
|
|
925
1031
|
case "symbol":
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1032
|
+
if (hasReferenceID(current)) {
|
|
1033
|
+
const id = createIndexedValue(ctx, current);
|
|
1034
|
+
if (ctx.markedRefs.has(id)) {
|
|
1035
|
+
return createIndexedValueNode(id);
|
|
1036
|
+
}
|
|
1037
|
+
return createReferenceNode(id, current);
|
|
1038
|
+
}
|
|
1039
|
+
return createWKSymbolNode(ctx, current);
|
|
1040
|
+
case "function": {
|
|
1041
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1042
|
+
const id = createIndexedValue(ctx, current);
|
|
1043
|
+
if (ctx.markedRefs.has(id)) {
|
|
1044
|
+
return createIndexedValueNode(id);
|
|
1045
|
+
}
|
|
1046
|
+
return createReferenceNode(id, current);
|
|
1047
|
+
}
|
|
929
1048
|
default:
|
|
930
1049
|
throw new Error("Unsupported type");
|
|
931
1050
|
}
|
|
@@ -937,7 +1056,7 @@ async function parseAsync(ctx, current) {
|
|
|
937
1056
|
}
|
|
938
1057
|
|
|
939
1058
|
// src/tree/deserialize.ts
|
|
940
|
-
function
|
|
1059
|
+
function assignIndexedValue(ctx, index, value) {
|
|
941
1060
|
ctx.valueMap.set(index, value);
|
|
942
1061
|
return value;
|
|
943
1062
|
}
|
|
@@ -952,7 +1071,7 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
952
1071
|
return result;
|
|
953
1072
|
}
|
|
954
1073
|
function deserializeArray(ctx, node) {
|
|
955
|
-
const result =
|
|
1074
|
+
const result = assignIndexedValue(
|
|
956
1075
|
ctx,
|
|
957
1076
|
node.i,
|
|
958
1077
|
new Array(node.l)
|
|
@@ -972,21 +1091,25 @@ function deserializeProperties(ctx, node, result) {
|
|
|
972
1091
|
return result;
|
|
973
1092
|
}
|
|
974
1093
|
function deserializeNullConstructor(ctx, node) {
|
|
975
|
-
const result =
|
|
1094
|
+
const result = assignIndexedValue(
|
|
1095
|
+
ctx,
|
|
1096
|
+
node.i,
|
|
1097
|
+
/* @__PURE__ */ Object.create(null)
|
|
1098
|
+
);
|
|
976
1099
|
ctx.stack.push(node.i);
|
|
977
1100
|
deserializeProperties(ctx, node.d, result);
|
|
978
1101
|
ctx.stack.pop();
|
|
979
1102
|
return result;
|
|
980
1103
|
}
|
|
981
1104
|
function deserializeObject(ctx, node) {
|
|
982
|
-
const result =
|
|
1105
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
983
1106
|
ctx.stack.push(node.i);
|
|
984
1107
|
deserializeProperties(ctx, node.d, result);
|
|
985
1108
|
ctx.stack.pop();
|
|
986
1109
|
return result;
|
|
987
1110
|
}
|
|
988
1111
|
function deserializeSet(ctx, node) {
|
|
989
|
-
const result =
|
|
1112
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
990
1113
|
ctx.stack.push(node.i);
|
|
991
1114
|
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
992
1115
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
@@ -995,7 +1118,7 @@ function deserializeSet(ctx, node) {
|
|
|
995
1118
|
return result;
|
|
996
1119
|
}
|
|
997
1120
|
function deserializeMap(ctx, node) {
|
|
998
|
-
const result =
|
|
1121
|
+
const result = assignIndexedValue(
|
|
999
1122
|
ctx,
|
|
1000
1123
|
node.i,
|
|
1001
1124
|
/* @__PURE__ */ new Map()
|
|
@@ -1020,7 +1143,7 @@ function deserializeDictionary(ctx, node, result) {
|
|
|
1020
1143
|
return result;
|
|
1021
1144
|
}
|
|
1022
1145
|
function deserializeAggregateError(ctx, node) {
|
|
1023
|
-
const result =
|
|
1146
|
+
const result = assignIndexedValue(ctx, node.i, new AggregateError([], invQuote(node.m)));
|
|
1024
1147
|
ctx.stack.push(node.i);
|
|
1025
1148
|
result.errors = deserializeNodeList(ctx, node, new Array(node.l));
|
|
1026
1149
|
ctx.stack.pop();
|
|
@@ -1028,7 +1151,7 @@ function deserializeAggregateError(ctx, node) {
|
|
|
1028
1151
|
}
|
|
1029
1152
|
function deserializeError(ctx, node) {
|
|
1030
1153
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
1031
|
-
const result =
|
|
1154
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(invQuote(node.m)));
|
|
1032
1155
|
return deserializeDictionary(ctx, node, result);
|
|
1033
1156
|
}
|
|
1034
1157
|
function createDeferred() {
|
|
@@ -1044,14 +1167,14 @@ function createDeferred() {
|
|
|
1044
1167
|
}
|
|
1045
1168
|
function deserializePromise(ctx, node) {
|
|
1046
1169
|
const deferred = createDeferred();
|
|
1047
|
-
const result =
|
|
1170
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1048
1171
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1049
1172
|
return result;
|
|
1050
1173
|
}
|
|
1051
1174
|
function deserializeTypedArray(ctx, node) {
|
|
1052
1175
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1053
1176
|
const dummy = new TypedArray();
|
|
1054
|
-
const result =
|
|
1177
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1055
1178
|
dummy.buffer,
|
|
1056
1179
|
node.l
|
|
1057
1180
|
));
|
|
@@ -1063,7 +1186,7 @@ function deserializeTypedArray(ctx, node) {
|
|
|
1063
1186
|
function deserializeIterable(ctx, node) {
|
|
1064
1187
|
const values = [];
|
|
1065
1188
|
deserializeNodeList(ctx, node, values);
|
|
1066
|
-
const result =
|
|
1189
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1067
1190
|
[Symbol.iterator]: () => values.values()
|
|
1068
1191
|
});
|
|
1069
1192
|
return deserializeDictionary(ctx, node, result);
|
|
@@ -1089,7 +1212,7 @@ function deserializeTree(ctx, node) {
|
|
|
1089
1212
|
return NaN;
|
|
1090
1213
|
case 9 /* BigInt */:
|
|
1091
1214
|
return BigInt(node.s);
|
|
1092
|
-
case 10 /*
|
|
1215
|
+
case 10 /* IndexedValue */:
|
|
1093
1216
|
return ctx.valueMap.get(node.i);
|
|
1094
1217
|
case 15 /* Array */:
|
|
1095
1218
|
return deserializeArray(ctx, node);
|
|
@@ -1098,9 +1221,9 @@ function deserializeTree(ctx, node) {
|
|
|
1098
1221
|
case 17 /* NullConstructor */:
|
|
1099
1222
|
return deserializeNullConstructor(ctx, node);
|
|
1100
1223
|
case 11 /* Date */:
|
|
1101
|
-
return
|
|
1224
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1102
1225
|
case 12 /* RegExp */:
|
|
1103
|
-
return
|
|
1226
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1104
1227
|
case 13 /* Set */:
|
|
1105
1228
|
return deserializeSet(ctx, node);
|
|
1106
1229
|
case 14 /* Map */:
|
|
@@ -1118,6 +1241,12 @@ function deserializeTree(ctx, node) {
|
|
|
1118
1241
|
return deserializePromise(ctx, node);
|
|
1119
1242
|
case 24 /* WKSymbol */:
|
|
1120
1243
|
return SYMBOL_REF[node.s];
|
|
1244
|
+
case 25 /* URL */:
|
|
1245
|
+
return assignIndexedValue(ctx, node.i, new URL(node.s));
|
|
1246
|
+
case 26 /* URLSearchParams */:
|
|
1247
|
+
return assignIndexedValue(ctx, node.i, new URLSearchParams(node.s));
|
|
1248
|
+
case 27 /* Reference */:
|
|
1249
|
+
return assignIndexedValue(ctx, node.i, getReference(invQuote(node.s)));
|
|
1121
1250
|
default:
|
|
1122
1251
|
throw new Error("Unsupported type");
|
|
1123
1252
|
}
|
|
@@ -1244,14 +1373,14 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
1244
1373
|
markRef(ctx, ref);
|
|
1245
1374
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1246
1375
|
}
|
|
1247
|
-
function
|
|
1376
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1248
1377
|
if (ctx.markedRefs.has(index)) {
|
|
1249
1378
|
return getRefParam(ctx, index) + "=" + value;
|
|
1250
1379
|
}
|
|
1251
1380
|
return value;
|
|
1252
1381
|
}
|
|
1253
|
-
function
|
|
1254
|
-
return node.t === 10 /*
|
|
1382
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1383
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1255
1384
|
}
|
|
1256
1385
|
function serializeNodeList(ctx, node) {
|
|
1257
1386
|
const size = node.l;
|
|
@@ -1264,7 +1393,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1264
1393
|
}
|
|
1265
1394
|
item = node.a[i];
|
|
1266
1395
|
if (item) {
|
|
1267
|
-
if (
|
|
1396
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1268
1397
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1269
1398
|
isHoley = true;
|
|
1270
1399
|
} else {
|
|
@@ -1281,7 +1410,7 @@ function serializeArray(ctx, node) {
|
|
|
1281
1410
|
ctx.stack.push(node.i);
|
|
1282
1411
|
const result = serializeNodeList(ctx, node);
|
|
1283
1412
|
ctx.stack.pop();
|
|
1284
|
-
return
|
|
1413
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1285
1414
|
}
|
|
1286
1415
|
function serializeProperties(ctx, sourceID, node) {
|
|
1287
1416
|
if (node.s === 0) {
|
|
@@ -1300,7 +1429,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1300
1429
|
val = node.v[i];
|
|
1301
1430
|
check = Number(key);
|
|
1302
1431
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1303
|
-
if (
|
|
1432
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1304
1433
|
refParam = getRefParam(ctx, val.i);
|
|
1305
1434
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1306
1435
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
@@ -1359,17 +1488,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1359
1488
|
markRef(ctx, i);
|
|
1360
1489
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1361
1490
|
if (assignments) {
|
|
1362
|
-
return "(" +
|
|
1491
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1363
1492
|
}
|
|
1364
1493
|
}
|
|
1365
1494
|
}
|
|
1366
|
-
return
|
|
1495
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1367
1496
|
}
|
|
1368
1497
|
function serializeNullConstructor(ctx, node) {
|
|
1369
1498
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1370
1499
|
}
|
|
1371
1500
|
function serializeObject(ctx, node) {
|
|
1372
|
-
return
|
|
1501
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1373
1502
|
}
|
|
1374
1503
|
function serializeSet(ctx, node) {
|
|
1375
1504
|
let serialized = "new Set";
|
|
@@ -1381,7 +1510,7 @@ function serializeSet(ctx, node) {
|
|
|
1381
1510
|
let hasPrev = false;
|
|
1382
1511
|
for (let i = 0; i < size; i++) {
|
|
1383
1512
|
item = node.a[i];
|
|
1384
|
-
if (
|
|
1513
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1385
1514
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1386
1515
|
} else {
|
|
1387
1516
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
@@ -1393,7 +1522,7 @@ function serializeSet(ctx, node) {
|
|
|
1393
1522
|
serialized += "([" + result + "])";
|
|
1394
1523
|
}
|
|
1395
1524
|
}
|
|
1396
|
-
return
|
|
1525
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1397
1526
|
}
|
|
1398
1527
|
function serializeMap(ctx, node) {
|
|
1399
1528
|
let serialized = "new Map";
|
|
@@ -1409,9 +1538,9 @@ function serializeMap(ctx, node) {
|
|
|
1409
1538
|
for (let i = 0; i < node.d.s; i++) {
|
|
1410
1539
|
key = node.d.k[i];
|
|
1411
1540
|
val = node.d.v[i];
|
|
1412
|
-
if (
|
|
1541
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1413
1542
|
keyRef = getRefParam(ctx, key.i);
|
|
1414
|
-
if (
|
|
1543
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1415
1544
|
valueRef = getRefParam(ctx, val.i);
|
|
1416
1545
|
createMapSet(ctx, node.i, keyRef, valueRef);
|
|
1417
1546
|
} else {
|
|
@@ -1420,7 +1549,7 @@ function serializeMap(ctx, node) {
|
|
|
1420
1549
|
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1421
1550
|
ctx.stack = parent;
|
|
1422
1551
|
}
|
|
1423
|
-
} else if (
|
|
1552
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1424
1553
|
valueRef = getRefParam(ctx, val.i);
|
|
1425
1554
|
parent = ctx.stack;
|
|
1426
1555
|
ctx.stack = [];
|
|
@@ -1436,7 +1565,7 @@ function serializeMap(ctx, node) {
|
|
|
1436
1565
|
serialized += "([" + result + "])";
|
|
1437
1566
|
}
|
|
1438
1567
|
}
|
|
1439
|
-
return
|
|
1568
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1440
1569
|
}
|
|
1441
1570
|
function serializeAggregateError(ctx, node) {
|
|
1442
1571
|
ctx.stack.push(node.i);
|
|
@@ -1450,7 +1579,7 @@ function serializeError(ctx, node) {
|
|
|
1450
1579
|
}
|
|
1451
1580
|
function serializePromise(ctx, node) {
|
|
1452
1581
|
let serialized;
|
|
1453
|
-
if (
|
|
1582
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1454
1583
|
const ref = getRefParam(ctx, node.f.i);
|
|
1455
1584
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1456
1585
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
@@ -1463,7 +1592,7 @@ function serializePromise(ctx, node) {
|
|
|
1463
1592
|
ctx.stack.pop();
|
|
1464
1593
|
serialized = "Promise.resolve(" + result + ")";
|
|
1465
1594
|
}
|
|
1466
|
-
return
|
|
1595
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1467
1596
|
}
|
|
1468
1597
|
function serializeTypedArray(ctx, node) {
|
|
1469
1598
|
let result = "";
|
|
@@ -1472,7 +1601,7 @@ function serializeTypedArray(ctx, node) {
|
|
|
1472
1601
|
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1473
1602
|
}
|
|
1474
1603
|
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1475
|
-
return
|
|
1604
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1476
1605
|
}
|
|
1477
1606
|
function serializeIterable(ctx, node) {
|
|
1478
1607
|
const parent = ctx.stack;
|
|
@@ -1516,7 +1645,7 @@ function serializeTree(ctx, node) {
|
|
|
1516
1645
|
return "NaN";
|
|
1517
1646
|
case 9 /* BigInt */:
|
|
1518
1647
|
return node.s + "n";
|
|
1519
|
-
case 10 /*
|
|
1648
|
+
case 10 /* IndexedValue */:
|
|
1520
1649
|
return getRefParam(ctx, node.i);
|
|
1521
1650
|
case 15 /* Array */:
|
|
1522
1651
|
return serializeArray(ctx, node);
|
|
@@ -1525,9 +1654,9 @@ function serializeTree(ctx, node) {
|
|
|
1525
1654
|
case 17 /* NullConstructor */:
|
|
1526
1655
|
return serializeNullConstructor(ctx, node);
|
|
1527
1656
|
case 11 /* Date */:
|
|
1528
|
-
return
|
|
1657
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1529
1658
|
case 12 /* RegExp */:
|
|
1530
|
-
return
|
|
1659
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1531
1660
|
case 13 /* Set */:
|
|
1532
1661
|
return serializeSet(ctx, node);
|
|
1533
1662
|
case 14 /* Map */:
|
|
@@ -1545,6 +1674,12 @@ function serializeTree(ctx, node) {
|
|
|
1545
1674
|
return serializePromise(ctx, node);
|
|
1546
1675
|
case 24 /* WKSymbol */:
|
|
1547
1676
|
return SYMBOL_STRING[node.s];
|
|
1677
|
+
case 25 /* URL */:
|
|
1678
|
+
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
1679
|
+
case 26 /* URLSearchParams */:
|
|
1680
|
+
return assignIndexedValue2(ctx, node.i, node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams");
|
|
1681
|
+
case 27 /* Reference */:
|
|
1682
|
+
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
1548
1683
|
default:
|
|
1549
1684
|
throw new Error("Unsupported type");
|
|
1550
1685
|
}
|
|
@@ -1725,7 +1860,7 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1725
1860
|
s: void 0,
|
|
1726
1861
|
l: current.errors.length,
|
|
1727
1862
|
c: void 0,
|
|
1728
|
-
m: current.message,
|
|
1863
|
+
m: quote(current.message),
|
|
1729
1864
|
d: optionsNode,
|
|
1730
1865
|
a: generateNodeList2(ctx, current.errors),
|
|
1731
1866
|
f: void 0
|
|
@@ -1740,7 +1875,7 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1740
1875
|
s: void 0,
|
|
1741
1876
|
l: void 0,
|
|
1742
1877
|
c: getErrorConstructorName(current),
|
|
1743
|
-
m: current.message,
|
|
1878
|
+
m: quote(current.message),
|
|
1744
1879
|
d: optionsNode,
|
|
1745
1880
|
a: void 0,
|
|
1746
1881
|
f: void 0
|
|
@@ -1761,24 +1896,26 @@ function parse2(ctx, current) {
|
|
|
1761
1896
|
case -Infinity:
|
|
1762
1897
|
return NEG_INFINITY_NODE;
|
|
1763
1898
|
default:
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1899
|
+
if (current !== current) {
|
|
1900
|
+
return NAN_NODE;
|
|
1901
|
+
}
|
|
1902
|
+
if (Object.is(current, -0)) {
|
|
1903
|
+
return NEG_ZERO_NODE;
|
|
1904
|
+
}
|
|
1905
|
+
return createNumberNode(current);
|
|
1771
1906
|
}
|
|
1772
|
-
return createNumberNode(current);
|
|
1773
1907
|
case "bigint":
|
|
1774
1908
|
return createBigIntNode(ctx, current);
|
|
1775
1909
|
case "object": {
|
|
1776
1910
|
if (!current) {
|
|
1777
1911
|
return NULL_NODE;
|
|
1778
1912
|
}
|
|
1779
|
-
const id =
|
|
1913
|
+
const id = createIndexedValue(ctx, current);
|
|
1780
1914
|
if (ctx.markedRefs.has(id)) {
|
|
1781
|
-
return
|
|
1915
|
+
return createIndexedValueNode(id);
|
|
1916
|
+
}
|
|
1917
|
+
if (hasReferenceID(current)) {
|
|
1918
|
+
return createReferenceNode(id, current);
|
|
1782
1919
|
}
|
|
1783
1920
|
if (Array.isArray(current)) {
|
|
1784
1921
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1806,9 +1943,19 @@ function parse2(ctx, current) {
|
|
|
1806
1943
|
case Set:
|
|
1807
1944
|
return generateSetNode2(ctx, id, current);
|
|
1808
1945
|
case Object:
|
|
1809
|
-
return generateObjectNode2(
|
|
1946
|
+
return generateObjectNode2(
|
|
1947
|
+
ctx,
|
|
1948
|
+
id,
|
|
1949
|
+
current,
|
|
1950
|
+
false
|
|
1951
|
+
);
|
|
1810
1952
|
case void 0:
|
|
1811
|
-
return generateObjectNode2(
|
|
1953
|
+
return generateObjectNode2(
|
|
1954
|
+
ctx,
|
|
1955
|
+
id,
|
|
1956
|
+
current,
|
|
1957
|
+
true
|
|
1958
|
+
);
|
|
1812
1959
|
case AggregateError:
|
|
1813
1960
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1814
1961
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1822,6 +1969,10 @@ function parse2(ctx, current) {
|
|
|
1822
1969
|
case TypeError:
|
|
1823
1970
|
case URIError:
|
|
1824
1971
|
return generateErrorNode2(ctx, id, current);
|
|
1972
|
+
case URL:
|
|
1973
|
+
return createURLNode(ctx, id, current);
|
|
1974
|
+
case URLSearchParams:
|
|
1975
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1825
1976
|
default:
|
|
1826
1977
|
break;
|
|
1827
1978
|
}
|
|
@@ -1840,9 +1991,22 @@ function parse2(ctx, current) {
|
|
|
1840
1991
|
throw new Error("Unsupported type");
|
|
1841
1992
|
}
|
|
1842
1993
|
case "symbol":
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1994
|
+
if (hasReferenceID(current)) {
|
|
1995
|
+
const id = createIndexedValue(ctx, current);
|
|
1996
|
+
if (ctx.markedRefs.has(id)) {
|
|
1997
|
+
return createIndexedValueNode(id);
|
|
1998
|
+
}
|
|
1999
|
+
return createReferenceNode(id, current);
|
|
2000
|
+
}
|
|
2001
|
+
return createWKSymbolNode(ctx, current);
|
|
2002
|
+
case "function": {
|
|
2003
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
2004
|
+
const id = createIndexedValue(ctx, current);
|
|
2005
|
+
if (ctx.markedRefs.has(id)) {
|
|
2006
|
+
return createIndexedValueNode(id);
|
|
2007
|
+
}
|
|
2008
|
+
return createReferenceNode(id, current);
|
|
2009
|
+
}
|
|
1846
2010
|
default:
|
|
1847
2011
|
throw new Error("Unsupported type");
|
|
1848
2012
|
}
|