seroval 0.5.0 → 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 +59 -9
- package/dist/cjs/development/index.cjs +372 -202
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +372 -202
- 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 -6
- 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 +25 -7
- 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 +37 -48
- package/src/index.ts +10 -16
- package/src/tree/async.ts +99 -74
- package/src/tree/deserialize.ts +32 -21
- package/src/tree/primitives.ts +46 -24
- package/src/tree/reference.ts +61 -0
- package/src/tree/serialize.ts +93 -86
- package/src/tree/sync.ts +104 -66
- package/src/tree/types.ts +32 -8
- 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$_";
|
|
@@ -61,35 +62,35 @@ function createSerializationContext(options) {
|
|
|
61
62
|
function markRef(ctx, current) {
|
|
62
63
|
ctx.markedRefs.add(current);
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
ctx.validRefs[index] =
|
|
69
|
-
|
|
65
|
+
function getRefParam(ctx, index) {
|
|
66
|
+
let actualIndex = ctx.validRefs[index];
|
|
67
|
+
if (actualIndex == null) {
|
|
68
|
+
actualIndex = ctx.refSize++;
|
|
69
|
+
ctx.validRefs[index] = actualIndex;
|
|
70
|
+
}
|
|
71
|
+
let identifier = ctx.vars[actualIndex];
|
|
72
|
+
if (identifier == null) {
|
|
73
|
+
identifier = getIdentifier(actualIndex);
|
|
74
|
+
ctx.vars[actualIndex] = identifier;
|
|
70
75
|
}
|
|
71
|
-
return
|
|
76
|
+
return identifier;
|
|
72
77
|
}
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return ctx.
|
|
78
|
+
function getRootID(ctx, current) {
|
|
79
|
+
const ref = ctx.refs.get(current);
|
|
80
|
+
if (ref == null) {
|
|
81
|
+
return ctx.refs.size;
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
ctx.vars[actualIndex] = result;
|
|
80
|
-
return result;
|
|
83
|
+
return ref;
|
|
81
84
|
}
|
|
82
|
-
function
|
|
85
|
+
function createIndexedValue(ctx, current) {
|
|
83
86
|
const ref = ctx.refs.get(current);
|
|
84
|
-
if (ref
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return ref;
|
|
87
|
+
if (ref == null) {
|
|
88
|
+
const id = ctx.refs.size;
|
|
89
|
+
ctx.refs.set(current, id);
|
|
90
|
+
return id;
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return id;
|
|
92
|
+
markRef(ctx, ref);
|
|
93
|
+
return ref;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
// src/assert.ts
|
|
@@ -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",
|
|
@@ -201,7 +255,7 @@ var TRUE_NODE = {
|
|
|
201
255
|
m: void 0,
|
|
202
256
|
d: void 0,
|
|
203
257
|
a: void 0,
|
|
204
|
-
|
|
258
|
+
f: void 0
|
|
205
259
|
};
|
|
206
260
|
var FALSE_NODE = {
|
|
207
261
|
t: 2 /* Boolean */,
|
|
@@ -212,7 +266,7 @@ var FALSE_NODE = {
|
|
|
212
266
|
m: void 0,
|
|
213
267
|
d: void 0,
|
|
214
268
|
a: void 0,
|
|
215
|
-
|
|
269
|
+
f: void 0
|
|
216
270
|
};
|
|
217
271
|
var UNDEFINED_NODE = {
|
|
218
272
|
t: 4 /* Undefined */,
|
|
@@ -223,7 +277,7 @@ var UNDEFINED_NODE = {
|
|
|
223
277
|
m: void 0,
|
|
224
278
|
d: void 0,
|
|
225
279
|
a: void 0,
|
|
226
|
-
|
|
280
|
+
f: void 0
|
|
227
281
|
};
|
|
228
282
|
var NULL_NODE = {
|
|
229
283
|
t: 3 /* Null */,
|
|
@@ -234,7 +288,7 @@ var NULL_NODE = {
|
|
|
234
288
|
m: void 0,
|
|
235
289
|
d: void 0,
|
|
236
290
|
a: void 0,
|
|
237
|
-
|
|
291
|
+
f: void 0
|
|
238
292
|
};
|
|
239
293
|
var NEG_ZERO_NODE = {
|
|
240
294
|
t: 5 /* NegativeZero */,
|
|
@@ -245,7 +299,7 @@ var NEG_ZERO_NODE = {
|
|
|
245
299
|
m: void 0,
|
|
246
300
|
d: void 0,
|
|
247
301
|
a: void 0,
|
|
248
|
-
|
|
302
|
+
f: void 0
|
|
249
303
|
};
|
|
250
304
|
var INFINITY_NODE = {
|
|
251
305
|
t: 6 /* Infinity */,
|
|
@@ -256,7 +310,7 @@ var INFINITY_NODE = {
|
|
|
256
310
|
m: void 0,
|
|
257
311
|
d: void 0,
|
|
258
312
|
a: void 0,
|
|
259
|
-
|
|
313
|
+
f: void 0
|
|
260
314
|
};
|
|
261
315
|
var NEG_INFINITY_NODE = {
|
|
262
316
|
t: 7 /* NegativeInfinity */,
|
|
@@ -267,7 +321,7 @@ var NEG_INFINITY_NODE = {
|
|
|
267
321
|
m: void 0,
|
|
268
322
|
d: void 0,
|
|
269
323
|
a: void 0,
|
|
270
|
-
|
|
324
|
+
f: void 0
|
|
271
325
|
};
|
|
272
326
|
var NAN_NODE = {
|
|
273
327
|
t: 8 /* NaN */,
|
|
@@ -278,7 +332,7 @@ var NAN_NODE = {
|
|
|
278
332
|
m: void 0,
|
|
279
333
|
d: void 0,
|
|
280
334
|
a: void 0,
|
|
281
|
-
|
|
335
|
+
f: void 0
|
|
282
336
|
};
|
|
283
337
|
function createNumberNode(value) {
|
|
284
338
|
return {
|
|
@@ -290,7 +344,7 @@ function createNumberNode(value) {
|
|
|
290
344
|
m: void 0,
|
|
291
345
|
d: void 0,
|
|
292
346
|
a: void 0,
|
|
293
|
-
|
|
347
|
+
f: void 0
|
|
294
348
|
};
|
|
295
349
|
}
|
|
296
350
|
function createStringNode(value) {
|
|
@@ -303,7 +357,7 @@ function createStringNode(value) {
|
|
|
303
357
|
m: void 0,
|
|
304
358
|
d: void 0,
|
|
305
359
|
a: void 0,
|
|
306
|
-
|
|
360
|
+
f: void 0
|
|
307
361
|
};
|
|
308
362
|
}
|
|
309
363
|
function createBigIntNode(ctx, current) {
|
|
@@ -311,18 +365,18 @@ function createBigIntNode(ctx, current) {
|
|
|
311
365
|
return {
|
|
312
366
|
t: 9 /* BigInt */,
|
|
313
367
|
i: void 0,
|
|
314
|
-
s: current
|
|
368
|
+
s: "" + current,
|
|
315
369
|
l: void 0,
|
|
316
370
|
c: void 0,
|
|
317
371
|
m: void 0,
|
|
318
372
|
d: void 0,
|
|
319
373
|
a: void 0,
|
|
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,
|
|
@@ -330,7 +384,7 @@ function createReferenceNode(id) {
|
|
|
330
384
|
m: void 0,
|
|
331
385
|
d: void 0,
|
|
332
386
|
a: void 0,
|
|
333
|
-
|
|
387
|
+
f: void 0
|
|
334
388
|
};
|
|
335
389
|
}
|
|
336
390
|
function createDateNode(id, current) {
|
|
@@ -342,7 +396,7 @@ function createDateNode(id, current) {
|
|
|
342
396
|
c: void 0,
|
|
343
397
|
m: void 0,
|
|
344
398
|
d: void 0,
|
|
345
|
-
|
|
399
|
+
f: void 0,
|
|
346
400
|
a: void 0
|
|
347
401
|
};
|
|
348
402
|
}
|
|
@@ -356,7 +410,7 @@ function createRegExpNode(id, current) {
|
|
|
356
410
|
m: current.flags,
|
|
357
411
|
d: void 0,
|
|
358
412
|
a: void 0,
|
|
359
|
-
|
|
413
|
+
f: void 0
|
|
360
414
|
};
|
|
361
415
|
}
|
|
362
416
|
function createTypedArrayNode(ctx, id, current) {
|
|
@@ -365,7 +419,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
365
419
|
const len = current.length;
|
|
366
420
|
const values = new Array(len);
|
|
367
421
|
for (let i = 0; i < len; i++) {
|
|
368
|
-
values[i] = current[i]
|
|
422
|
+
values[i] = "" + current[i];
|
|
369
423
|
}
|
|
370
424
|
return {
|
|
371
425
|
t: 22 /* TypedArray */,
|
|
@@ -376,7 +430,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
376
430
|
m: void 0,
|
|
377
431
|
d: void 0,
|
|
378
432
|
a: void 0,
|
|
379
|
-
|
|
433
|
+
f: void 0
|
|
380
434
|
};
|
|
381
435
|
}
|
|
382
436
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -389,7 +443,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
389
443
|
const len = current.length;
|
|
390
444
|
const values = new Array(len);
|
|
391
445
|
for (let i = 0; i < len; i++) {
|
|
392
|
-
values[i] = current[i]
|
|
446
|
+
values[i] = "" + current[i];
|
|
393
447
|
}
|
|
394
448
|
return {
|
|
395
449
|
t: 23 /* BigIntTypedArray */,
|
|
@@ -400,10 +454,12 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
400
454
|
m: void 0,
|
|
401
455
|
d: void 0,
|
|
402
456
|
a: void 0,
|
|
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,
|
|
@@ -413,7 +469,20 @@ function createWKSymbolNode(current) {
|
|
|
413
469
|
m: void 0,
|
|
414
470
|
d: void 0,
|
|
415
471
|
a: void 0,
|
|
416
|
-
|
|
472
|
+
f: void 0
|
|
473
|
+
};
|
|
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
|
|
417
486
|
};
|
|
418
487
|
}
|
|
419
488
|
|
|
@@ -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;
|
|
@@ -588,7 +687,7 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
588
687
|
m: void 0,
|
|
589
688
|
d: void 0,
|
|
590
689
|
a: await generateNodeList(ctx, current),
|
|
591
|
-
|
|
690
|
+
f: void 0
|
|
592
691
|
};
|
|
593
692
|
}
|
|
594
693
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -624,7 +723,7 @@ async function generateMapNode(ctx, id, current) {
|
|
|
624
723
|
m: void 0,
|
|
625
724
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
626
725
|
a: void 0,
|
|
627
|
-
|
|
726
|
+
f: void 0
|
|
628
727
|
};
|
|
629
728
|
}
|
|
630
729
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -653,7 +752,7 @@ async function generateSetNode(ctx, id, current) {
|
|
|
653
752
|
m: void 0,
|
|
654
753
|
d: void 0,
|
|
655
754
|
a: nodes,
|
|
656
|
-
|
|
755
|
+
f: void 0
|
|
657
756
|
};
|
|
658
757
|
}
|
|
659
758
|
async function generateProperties(ctx, properties) {
|
|
@@ -702,7 +801,7 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
702
801
|
// Parse options first before the items
|
|
703
802
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
704
803
|
a: await generateNodeList(ctx, array),
|
|
705
|
-
|
|
804
|
+
f: void 0
|
|
706
805
|
};
|
|
707
806
|
}
|
|
708
807
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -717,7 +816,7 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
717
816
|
// Parse options first before the items
|
|
718
817
|
d: void 0,
|
|
719
818
|
a: void 0,
|
|
720
|
-
|
|
819
|
+
f: await parse(ctx, value)
|
|
721
820
|
}));
|
|
722
821
|
}
|
|
723
822
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -736,7 +835,7 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
736
835
|
m: void 0,
|
|
737
836
|
d: await generateProperties(ctx, current),
|
|
738
837
|
a: void 0,
|
|
739
|
-
|
|
838
|
+
f: void 0
|
|
740
839
|
};
|
|
741
840
|
}
|
|
742
841
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -748,10 +847,10 @@ 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
|
|
755
854
|
};
|
|
756
855
|
}
|
|
757
856
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -763,10 +862,10 @@ 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
|
|
770
869
|
};
|
|
771
870
|
}
|
|
772
871
|
async function parse(ctx, current) {
|
|
@@ -778,28 +877,32 @@ async function parse(ctx, current) {
|
|
|
778
877
|
case "string":
|
|
779
878
|
return createStringNode(current);
|
|
780
879
|
case "number":
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
880
|
+
switch (current) {
|
|
881
|
+
case Infinity:
|
|
882
|
+
return INFINITY_NODE;
|
|
883
|
+
case -Infinity:
|
|
884
|
+
return NEG_INFINITY_NODE;
|
|
885
|
+
default:
|
|
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);
|
|
792
893
|
}
|
|
793
|
-
return createNumberNode(current);
|
|
794
894
|
case "bigint":
|
|
795
895
|
return createBigIntNode(ctx, current);
|
|
796
896
|
case "object": {
|
|
797
897
|
if (!current) {
|
|
798
898
|
return NULL_NODE;
|
|
799
899
|
}
|
|
800
|
-
const id =
|
|
900
|
+
const id = createIndexedValue(ctx, current);
|
|
801
901
|
if (ctx.markedRefs.has(id)) {
|
|
802
|
-
return
|
|
902
|
+
return createIndexedValueNode(id);
|
|
903
|
+
}
|
|
904
|
+
if (hasReferenceID(current)) {
|
|
905
|
+
return createReferenceNode(id, current);
|
|
803
906
|
}
|
|
804
907
|
if (Array.isArray(current)) {
|
|
805
908
|
return generateArrayNode(ctx, id, current);
|
|
@@ -863,11 +966,18 @@ async function parse(ctx, current) {
|
|
|
863
966
|
case TypeError:
|
|
864
967
|
case URIError:
|
|
865
968
|
return generateErrorNode(ctx, id, current);
|
|
969
|
+
case URL:
|
|
970
|
+
return createURLNode(ctx, id, current);
|
|
971
|
+
case URLSearchParams:
|
|
972
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
866
973
|
default:
|
|
867
974
|
break;
|
|
868
975
|
}
|
|
869
|
-
if (current instanceof AggregateError
|
|
870
|
-
|
|
976
|
+
if (current instanceof AggregateError) {
|
|
977
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
978
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
979
|
+
}
|
|
980
|
+
return generateErrorNode(ctx, id, current);
|
|
871
981
|
}
|
|
872
982
|
if (current instanceof Error) {
|
|
873
983
|
return generateErrorNode(ctx, id, current);
|
|
@@ -884,9 +994,22 @@ async function parse(ctx, current) {
|
|
|
884
994
|
throw new Error("Unsupported type");
|
|
885
995
|
}
|
|
886
996
|
case "symbol":
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
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
|
+
}
|
|
890
1013
|
default:
|
|
891
1014
|
throw new Error("Unsupported type");
|
|
892
1015
|
}
|
|
@@ -894,11 +1017,11 @@ async function parse(ctx, current) {
|
|
|
894
1017
|
async function parseAsync(ctx, current) {
|
|
895
1018
|
const result = await parse(ctx, current);
|
|
896
1019
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
897
|
-
return [result,
|
|
1020
|
+
return [result, getRootID(ctx, current), isObject];
|
|
898
1021
|
}
|
|
899
1022
|
|
|
900
1023
|
// src/tree/deserialize.ts
|
|
901
|
-
function
|
|
1024
|
+
function assignIndexedValue(ctx, index, value) {
|
|
902
1025
|
ctx.valueMap.set(index, value);
|
|
903
1026
|
return value;
|
|
904
1027
|
}
|
|
@@ -913,7 +1036,7 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
913
1036
|
return result;
|
|
914
1037
|
}
|
|
915
1038
|
function deserializeArray(ctx, node) {
|
|
916
|
-
const result =
|
|
1039
|
+
const result = assignIndexedValue(
|
|
917
1040
|
ctx,
|
|
918
1041
|
node.i,
|
|
919
1042
|
new Array(node.l)
|
|
@@ -933,21 +1056,25 @@ function deserializeProperties(ctx, node, result) {
|
|
|
933
1056
|
return result;
|
|
934
1057
|
}
|
|
935
1058
|
function deserializeNullConstructor(ctx, node) {
|
|
936
|
-
const result =
|
|
1059
|
+
const result = assignIndexedValue(
|
|
1060
|
+
ctx,
|
|
1061
|
+
node.i,
|
|
1062
|
+
/* @__PURE__ */ Object.create(null)
|
|
1063
|
+
);
|
|
937
1064
|
ctx.stack.push(node.i);
|
|
938
1065
|
deserializeProperties(ctx, node.d, result);
|
|
939
1066
|
ctx.stack.pop();
|
|
940
1067
|
return result;
|
|
941
1068
|
}
|
|
942
1069
|
function deserializeObject(ctx, node) {
|
|
943
|
-
const result =
|
|
1070
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
944
1071
|
ctx.stack.push(node.i);
|
|
945
1072
|
deserializeProperties(ctx, node.d, result);
|
|
946
1073
|
ctx.stack.pop();
|
|
947
1074
|
return result;
|
|
948
1075
|
}
|
|
949
1076
|
function deserializeSet(ctx, node) {
|
|
950
|
-
const result =
|
|
1077
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
951
1078
|
ctx.stack.push(node.i);
|
|
952
1079
|
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
953
1080
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
@@ -956,7 +1083,7 @@ function deserializeSet(ctx, node) {
|
|
|
956
1083
|
return result;
|
|
957
1084
|
}
|
|
958
1085
|
function deserializeMap(ctx, node) {
|
|
959
|
-
const result =
|
|
1086
|
+
const result = assignIndexedValue(
|
|
960
1087
|
ctx,
|
|
961
1088
|
node.i,
|
|
962
1089
|
/* @__PURE__ */ new Map()
|
|
@@ -981,7 +1108,7 @@ function deserializeDictionary(ctx, node, result) {
|
|
|
981
1108
|
return result;
|
|
982
1109
|
}
|
|
983
1110
|
function deserializeAggregateError(ctx, node) {
|
|
984
|
-
const result =
|
|
1111
|
+
const result = assignIndexedValue(ctx, node.i, new AggregateError([], invQuote(node.m)));
|
|
985
1112
|
ctx.stack.push(node.i);
|
|
986
1113
|
result.errors = deserializeNodeList(ctx, node, new Array(node.l));
|
|
987
1114
|
ctx.stack.pop();
|
|
@@ -989,7 +1116,7 @@ function deserializeAggregateError(ctx, node) {
|
|
|
989
1116
|
}
|
|
990
1117
|
function deserializeError(ctx, node) {
|
|
991
1118
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
992
|
-
const result =
|
|
1119
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(invQuote(node.m)));
|
|
993
1120
|
return deserializeDictionary(ctx, node, result);
|
|
994
1121
|
}
|
|
995
1122
|
function createDeferred() {
|
|
@@ -1005,14 +1132,14 @@ function createDeferred() {
|
|
|
1005
1132
|
}
|
|
1006
1133
|
function deserializePromise(ctx, node) {
|
|
1007
1134
|
const deferred = createDeferred();
|
|
1008
|
-
const result =
|
|
1009
|
-
deferred.resolve(deserializeTree(ctx, node.
|
|
1135
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1136
|
+
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1010
1137
|
return result;
|
|
1011
1138
|
}
|
|
1012
1139
|
function deserializeTypedArray(ctx, node) {
|
|
1013
1140
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1014
1141
|
const dummy = new TypedArray();
|
|
1015
|
-
const result =
|
|
1142
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1016
1143
|
dummy.buffer,
|
|
1017
1144
|
node.l
|
|
1018
1145
|
));
|
|
@@ -1024,7 +1151,7 @@ function deserializeTypedArray(ctx, node) {
|
|
|
1024
1151
|
function deserializeIterable(ctx, node) {
|
|
1025
1152
|
const values = [];
|
|
1026
1153
|
deserializeNodeList(ctx, node, values);
|
|
1027
|
-
const result =
|
|
1154
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1028
1155
|
[Symbol.iterator]: () => values.values()
|
|
1029
1156
|
});
|
|
1030
1157
|
return deserializeDictionary(ctx, node, result);
|
|
@@ -1050,7 +1177,7 @@ function deserializeTree(ctx, node) {
|
|
|
1050
1177
|
return NaN;
|
|
1051
1178
|
case 9 /* BigInt */:
|
|
1052
1179
|
return BigInt(node.s);
|
|
1053
|
-
case 10 /*
|
|
1180
|
+
case 10 /* IndexedValue */:
|
|
1054
1181
|
return ctx.valueMap.get(node.i);
|
|
1055
1182
|
case 15 /* Array */:
|
|
1056
1183
|
return deserializeArray(ctx, node);
|
|
@@ -1059,9 +1186,9 @@ function deserializeTree(ctx, node) {
|
|
|
1059
1186
|
case 17 /* NullConstructor */:
|
|
1060
1187
|
return deserializeNullConstructor(ctx, node);
|
|
1061
1188
|
case 11 /* Date */:
|
|
1062
|
-
return
|
|
1189
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1063
1190
|
case 12 /* RegExp */:
|
|
1064
|
-
return
|
|
1191
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1065
1192
|
case 13 /* Set */:
|
|
1066
1193
|
return deserializeSet(ctx, node);
|
|
1067
1194
|
case 14 /* Map */:
|
|
@@ -1079,6 +1206,12 @@ function deserializeTree(ctx, node) {
|
|
|
1079
1206
|
return deserializePromise(ctx, node);
|
|
1080
1207
|
case 24 /* WKSymbol */:
|
|
1081
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)));
|
|
1082
1215
|
default:
|
|
1083
1216
|
throw new Error("Unsupported type");
|
|
1084
1217
|
}
|
|
@@ -1105,30 +1238,48 @@ function mergeAssignments(assignments) {
|
|
|
1105
1238
|
for (let i = 1, len = assignments.length; i < len; i++) {
|
|
1106
1239
|
item = assignments[i];
|
|
1107
1240
|
if (item.t === prev.t) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1241
|
+
switch (item.t) {
|
|
1242
|
+
case "index":
|
|
1243
|
+
if (item.v === prev.v) {
|
|
1244
|
+
current = {
|
|
1245
|
+
t: "index",
|
|
1246
|
+
s: item.s,
|
|
1247
|
+
k: void 0,
|
|
1248
|
+
v: getAssignmentExpression(current)
|
|
1249
|
+
};
|
|
1250
|
+
} else {
|
|
1251
|
+
newAssignments.push(current);
|
|
1252
|
+
current = item;
|
|
1253
|
+
}
|
|
1254
|
+
break;
|
|
1255
|
+
case "map":
|
|
1256
|
+
if (item.s === prev.s) {
|
|
1257
|
+
current = {
|
|
1258
|
+
t: "map",
|
|
1259
|
+
s: getAssignmentExpression(current),
|
|
1260
|
+
k: item.k,
|
|
1261
|
+
v: item.v
|
|
1262
|
+
};
|
|
1263
|
+
} else {
|
|
1264
|
+
newAssignments.push(current);
|
|
1265
|
+
current = item;
|
|
1266
|
+
}
|
|
1267
|
+
break;
|
|
1268
|
+
case "set":
|
|
1269
|
+
if (item.s === prev.s) {
|
|
1270
|
+
current = {
|
|
1271
|
+
t: "set",
|
|
1272
|
+
s: getAssignmentExpression(current),
|
|
1273
|
+
k: void 0,
|
|
1274
|
+
v: item.v
|
|
1275
|
+
};
|
|
1276
|
+
} else {
|
|
1277
|
+
newAssignments.push(current);
|
|
1278
|
+
current = item;
|
|
1279
|
+
}
|
|
1280
|
+
break;
|
|
1281
|
+
default:
|
|
1282
|
+
break;
|
|
1132
1283
|
}
|
|
1133
1284
|
} else {
|
|
1134
1285
|
newAssignments.push(current);
|
|
@@ -1181,20 +1332,20 @@ function createMapSet(ctx, ref, key, value) {
|
|
|
1181
1332
|
}
|
|
1182
1333
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1183
1334
|
markRef(ctx, ref);
|
|
1184
|
-
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index
|
|
1335
|
+
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1185
1336
|
}
|
|
1186
1337
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1187
1338
|
markRef(ctx, ref);
|
|
1188
1339
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1189
1340
|
}
|
|
1190
|
-
function
|
|
1341
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1191
1342
|
if (ctx.markedRefs.has(index)) {
|
|
1192
1343
|
return getRefParam(ctx, index) + "=" + value;
|
|
1193
1344
|
}
|
|
1194
1345
|
return value;
|
|
1195
1346
|
}
|
|
1196
|
-
function
|
|
1197
|
-
return node.t === 10 /*
|
|
1347
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1348
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1198
1349
|
}
|
|
1199
1350
|
function serializeNodeList(ctx, node) {
|
|
1200
1351
|
const size = node.l;
|
|
@@ -1207,7 +1358,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1207
1358
|
}
|
|
1208
1359
|
item = node.a[i];
|
|
1209
1360
|
if (item) {
|
|
1210
|
-
if (
|
|
1361
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1211
1362
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1212
1363
|
isHoley = true;
|
|
1213
1364
|
} else {
|
|
@@ -1218,16 +1369,13 @@ function serializeNodeList(ctx, node) {
|
|
|
1218
1369
|
isHoley = true;
|
|
1219
1370
|
}
|
|
1220
1371
|
}
|
|
1221
|
-
|
|
1222
|
-
values += ",";
|
|
1223
|
-
}
|
|
1224
|
-
return "[" + values + "]";
|
|
1372
|
+
return "[" + values + (isHoley ? ",]" : "]");
|
|
1225
1373
|
}
|
|
1226
1374
|
function serializeArray(ctx, node) {
|
|
1227
1375
|
ctx.stack.push(node.i);
|
|
1228
1376
|
const result = serializeNodeList(ctx, node);
|
|
1229
1377
|
ctx.stack.pop();
|
|
1230
|
-
return
|
|
1378
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1231
1379
|
}
|
|
1232
1380
|
function serializeProperties(ctx, sourceID, node) {
|
|
1233
1381
|
if (node.s === 0) {
|
|
@@ -1246,7 +1394,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1246
1394
|
val = node.v[i];
|
|
1247
1395
|
check = Number(key);
|
|
1248
1396
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1249
|
-
if (
|
|
1397
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1250
1398
|
refParam = getRefParam(ctx, val.i);
|
|
1251
1399
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1252
1400
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
@@ -1254,11 +1402,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1254
1402
|
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
|
|
1255
1403
|
}
|
|
1256
1404
|
} else {
|
|
1257
|
-
|
|
1258
|
-
result += ",";
|
|
1259
|
-
}
|
|
1260
|
-
result += isIdentifier ? key : '"' + quote(key) + '"';
|
|
1261
|
-
result += ":" + serializeTree(ctx, val);
|
|
1405
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
|
|
1262
1406
|
hasPrev = true;
|
|
1263
1407
|
}
|
|
1264
1408
|
}
|
|
@@ -1309,18 +1453,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1309
1453
|
markRef(ctx, i);
|
|
1310
1454
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1311
1455
|
if (assignments) {
|
|
1312
|
-
|
|
1313
|
-
return "(" + assignRef2(ctx, i, init) + "," + assignments + ref + ")";
|
|
1456
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1314
1457
|
}
|
|
1315
1458
|
}
|
|
1316
1459
|
}
|
|
1317
|
-
return
|
|
1460
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1318
1461
|
}
|
|
1319
1462
|
function serializeNullConstructor(ctx, node) {
|
|
1320
1463
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1321
1464
|
}
|
|
1322
1465
|
function serializeObject(ctx, node) {
|
|
1323
|
-
return
|
|
1466
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1324
1467
|
}
|
|
1325
1468
|
function serializeSet(ctx, node) {
|
|
1326
1469
|
let serialized = "new Set";
|
|
@@ -1332,13 +1475,10 @@ function serializeSet(ctx, node) {
|
|
|
1332
1475
|
let hasPrev = false;
|
|
1333
1476
|
for (let i = 0; i < size; i++) {
|
|
1334
1477
|
item = node.a[i];
|
|
1335
|
-
if (
|
|
1478
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1336
1479
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1337
1480
|
} else {
|
|
1338
|
-
|
|
1339
|
-
result += ",";
|
|
1340
|
-
}
|
|
1341
|
-
result += serializeTree(ctx, item);
|
|
1481
|
+
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1342
1482
|
hasPrev = true;
|
|
1343
1483
|
}
|
|
1344
1484
|
}
|
|
@@ -1347,7 +1487,7 @@ function serializeSet(ctx, node) {
|
|
|
1347
1487
|
serialized += "([" + result + "])";
|
|
1348
1488
|
}
|
|
1349
1489
|
}
|
|
1350
|
-
return
|
|
1490
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1351
1491
|
}
|
|
1352
1492
|
function serializeMap(ctx, node) {
|
|
1353
1493
|
let serialized = "new Map";
|
|
@@ -1363,9 +1503,9 @@ function serializeMap(ctx, node) {
|
|
|
1363
1503
|
for (let i = 0; i < node.d.s; i++) {
|
|
1364
1504
|
key = node.d.k[i];
|
|
1365
1505
|
val = node.d.v[i];
|
|
1366
|
-
if (
|
|
1506
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1367
1507
|
keyRef = getRefParam(ctx, key.i);
|
|
1368
|
-
if (
|
|
1508
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1369
1509
|
valueRef = getRefParam(ctx, val.i);
|
|
1370
1510
|
createMapSet(ctx, node.i, keyRef, valueRef);
|
|
1371
1511
|
} else {
|
|
@@ -1374,17 +1514,14 @@ function serializeMap(ctx, node) {
|
|
|
1374
1514
|
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1375
1515
|
ctx.stack = parent;
|
|
1376
1516
|
}
|
|
1377
|
-
} else if (
|
|
1517
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1378
1518
|
valueRef = getRefParam(ctx, val.i);
|
|
1379
1519
|
parent = ctx.stack;
|
|
1380
1520
|
ctx.stack = [];
|
|
1381
1521
|
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1382
1522
|
ctx.stack = parent;
|
|
1383
1523
|
} else {
|
|
1384
|
-
|
|
1385
|
-
result += ",";
|
|
1386
|
-
}
|
|
1387
|
-
result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1524
|
+
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1388
1525
|
hasPrev = true;
|
|
1389
1526
|
}
|
|
1390
1527
|
}
|
|
@@ -1393,7 +1530,7 @@ function serializeMap(ctx, node) {
|
|
|
1393
1530
|
serialized += "([" + result + "])";
|
|
1394
1531
|
}
|
|
1395
1532
|
}
|
|
1396
|
-
return
|
|
1533
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1397
1534
|
}
|
|
1398
1535
|
function serializeAggregateError(ctx, node) {
|
|
1399
1536
|
ctx.stack.push(node.i);
|
|
@@ -1407,8 +1544,8 @@ function serializeError(ctx, node) {
|
|
|
1407
1544
|
}
|
|
1408
1545
|
function serializePromise(ctx, node) {
|
|
1409
1546
|
let serialized;
|
|
1410
|
-
if (
|
|
1411
|
-
const ref = getRefParam(ctx, node.
|
|
1547
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1548
|
+
const ref = getRefParam(ctx, node.f.i);
|
|
1412
1549
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1413
1550
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1414
1551
|
} else {
|
|
@@ -1416,28 +1553,20 @@ function serializePromise(ctx, node) {
|
|
|
1416
1553
|
}
|
|
1417
1554
|
} else {
|
|
1418
1555
|
ctx.stack.push(node.i);
|
|
1419
|
-
const result = serializeTree(ctx, node.
|
|
1556
|
+
const result = serializeTree(ctx, node.f);
|
|
1420
1557
|
ctx.stack.pop();
|
|
1421
1558
|
serialized = "Promise.resolve(" + result + ")";
|
|
1422
1559
|
}
|
|
1423
|
-
return
|
|
1560
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1424
1561
|
}
|
|
1425
1562
|
function serializeTypedArray(ctx, node) {
|
|
1426
1563
|
let result = "";
|
|
1564
|
+
const isBigInt = node.t === 23 /* BigIntTypedArray */;
|
|
1427
1565
|
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1428
|
-
|
|
1429
|
-
result += ",";
|
|
1430
|
-
}
|
|
1431
|
-
result += node.s[i];
|
|
1432
|
-
if (node.t === 23 /* BigIntTypedArray */) {
|
|
1433
|
-
result += "n";
|
|
1434
|
-
}
|
|
1566
|
+
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1435
1567
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
args += "," + node.l.toString();
|
|
1439
|
-
}
|
|
1440
|
-
return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1568
|
+
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1569
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1441
1570
|
}
|
|
1442
1571
|
function serializeIterable(ctx, node) {
|
|
1443
1572
|
const parent = ctx.stack;
|
|
@@ -1462,13 +1591,13 @@ function serializeIterable(ctx, node) {
|
|
|
1462
1591
|
function serializeTree(ctx, node) {
|
|
1463
1592
|
switch (node.t) {
|
|
1464
1593
|
case 0 /* Number */:
|
|
1465
|
-
return
|
|
1594
|
+
return "" + node.s;
|
|
1466
1595
|
case 1 /* String */:
|
|
1467
1596
|
return '"' + node.s + '"';
|
|
1468
1597
|
case 2 /* Boolean */:
|
|
1469
1598
|
return node.s ? "!0" : "!1";
|
|
1470
1599
|
case 4 /* Undefined */:
|
|
1471
|
-
return "
|
|
1600
|
+
return "void 0";
|
|
1472
1601
|
case 3 /* Null */:
|
|
1473
1602
|
return "null";
|
|
1474
1603
|
case 5 /* NegativeZero */:
|
|
@@ -1481,7 +1610,7 @@ function serializeTree(ctx, node) {
|
|
|
1481
1610
|
return "NaN";
|
|
1482
1611
|
case 9 /* BigInt */:
|
|
1483
1612
|
return node.s + "n";
|
|
1484
|
-
case 10 /*
|
|
1613
|
+
case 10 /* IndexedValue */:
|
|
1485
1614
|
return getRefParam(ctx, node.i);
|
|
1486
1615
|
case 15 /* Array */:
|
|
1487
1616
|
return serializeArray(ctx, node);
|
|
@@ -1490,9 +1619,9 @@ function serializeTree(ctx, node) {
|
|
|
1490
1619
|
case 17 /* NullConstructor */:
|
|
1491
1620
|
return serializeNullConstructor(ctx, node);
|
|
1492
1621
|
case 11 /* Date */:
|
|
1493
|
-
return
|
|
1622
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1494
1623
|
case 12 /* RegExp */:
|
|
1495
|
-
return
|
|
1624
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1496
1625
|
case 13 /* Set */:
|
|
1497
1626
|
return serializeSet(ctx, node);
|
|
1498
1627
|
case 14 /* Map */:
|
|
@@ -1510,6 +1639,12 @@ function serializeTree(ctx, node) {
|
|
|
1510
1639
|
return serializePromise(ctx, node);
|
|
1511
1640
|
case 24 /* WKSymbol */:
|
|
1512
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 + '")');
|
|
1513
1648
|
default:
|
|
1514
1649
|
throw new Error("Unsupported type");
|
|
1515
1650
|
}
|
|
@@ -1548,7 +1683,7 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1548
1683
|
m: void 0,
|
|
1549
1684
|
d: void 0,
|
|
1550
1685
|
a: generateNodeList2(ctx, current),
|
|
1551
|
-
|
|
1686
|
+
f: void 0
|
|
1552
1687
|
};
|
|
1553
1688
|
}
|
|
1554
1689
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1584,7 +1719,7 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1584
1719
|
m: void 0,
|
|
1585
1720
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1586
1721
|
a: void 0,
|
|
1587
|
-
|
|
1722
|
+
f: void 0
|
|
1588
1723
|
};
|
|
1589
1724
|
}
|
|
1590
1725
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1613,7 +1748,7 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1613
1748
|
m: void 0,
|
|
1614
1749
|
d: void 0,
|
|
1615
1750
|
a: nodes,
|
|
1616
|
-
|
|
1751
|
+
f: void 0
|
|
1617
1752
|
};
|
|
1618
1753
|
}
|
|
1619
1754
|
function generateProperties2(ctx, properties) {
|
|
@@ -1662,7 +1797,7 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1662
1797
|
// Parse options first before the items
|
|
1663
1798
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1664
1799
|
a: generateNodeList2(ctx, array),
|
|
1665
|
-
|
|
1800
|
+
f: void 0
|
|
1666
1801
|
};
|
|
1667
1802
|
}
|
|
1668
1803
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1678,7 +1813,7 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1678
1813
|
m: void 0,
|
|
1679
1814
|
d: generateProperties2(ctx, current),
|
|
1680
1815
|
a: void 0,
|
|
1681
|
-
|
|
1816
|
+
f: void 0
|
|
1682
1817
|
};
|
|
1683
1818
|
}
|
|
1684
1819
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1690,10 +1825,10 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1690
1825
|
s: void 0,
|
|
1691
1826
|
l: current.errors.length,
|
|
1692
1827
|
c: void 0,
|
|
1693
|
-
m: current.message,
|
|
1828
|
+
m: quote(current.message),
|
|
1694
1829
|
d: optionsNode,
|
|
1695
1830
|
a: generateNodeList2(ctx, current.errors),
|
|
1696
|
-
|
|
1831
|
+
f: void 0
|
|
1697
1832
|
};
|
|
1698
1833
|
}
|
|
1699
1834
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1705,10 +1840,10 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1705
1840
|
s: void 0,
|
|
1706
1841
|
l: void 0,
|
|
1707
1842
|
c: getErrorConstructorName(current),
|
|
1708
|
-
m: current.message,
|
|
1843
|
+
m: quote(current.message),
|
|
1709
1844
|
d: optionsNode,
|
|
1710
1845
|
a: void 0,
|
|
1711
|
-
|
|
1846
|
+
f: void 0
|
|
1712
1847
|
};
|
|
1713
1848
|
}
|
|
1714
1849
|
function parse2(ctx, current) {
|
|
@@ -1720,28 +1855,32 @@ function parse2(ctx, current) {
|
|
|
1720
1855
|
case "string":
|
|
1721
1856
|
return createStringNode(current);
|
|
1722
1857
|
case "number":
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1858
|
+
switch (current) {
|
|
1859
|
+
case Infinity:
|
|
1860
|
+
return INFINITY_NODE;
|
|
1861
|
+
case -Infinity:
|
|
1862
|
+
return NEG_INFINITY_NODE;
|
|
1863
|
+
default:
|
|
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);
|
|
1734
1871
|
}
|
|
1735
|
-
return createNumberNode(current);
|
|
1736
1872
|
case "bigint":
|
|
1737
1873
|
return createBigIntNode(ctx, current);
|
|
1738
1874
|
case "object": {
|
|
1739
1875
|
if (!current) {
|
|
1740
1876
|
return NULL_NODE;
|
|
1741
1877
|
}
|
|
1742
|
-
const id =
|
|
1878
|
+
const id = createIndexedValue(ctx, current);
|
|
1743
1879
|
if (ctx.markedRefs.has(id)) {
|
|
1744
|
-
return
|
|
1880
|
+
return createIndexedValueNode(id);
|
|
1881
|
+
}
|
|
1882
|
+
if (hasReferenceID(current)) {
|
|
1883
|
+
return createReferenceNode(id, current);
|
|
1745
1884
|
}
|
|
1746
1885
|
if (Array.isArray(current)) {
|
|
1747
1886
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1769,9 +1908,19 @@ function parse2(ctx, current) {
|
|
|
1769
1908
|
case Set:
|
|
1770
1909
|
return generateSetNode2(ctx, id, current);
|
|
1771
1910
|
case Object:
|
|
1772
|
-
return generateObjectNode2(
|
|
1911
|
+
return generateObjectNode2(
|
|
1912
|
+
ctx,
|
|
1913
|
+
id,
|
|
1914
|
+
current,
|
|
1915
|
+
false
|
|
1916
|
+
);
|
|
1773
1917
|
case void 0:
|
|
1774
|
-
return generateObjectNode2(
|
|
1918
|
+
return generateObjectNode2(
|
|
1919
|
+
ctx,
|
|
1920
|
+
id,
|
|
1921
|
+
current,
|
|
1922
|
+
true
|
|
1923
|
+
);
|
|
1775
1924
|
case AggregateError:
|
|
1776
1925
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1777
1926
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1785,11 +1934,18 @@ function parse2(ctx, current) {
|
|
|
1785
1934
|
case TypeError:
|
|
1786
1935
|
case URIError:
|
|
1787
1936
|
return generateErrorNode2(ctx, id, current);
|
|
1937
|
+
case URL:
|
|
1938
|
+
return createURLNode(ctx, id, current);
|
|
1939
|
+
case URLSearchParams:
|
|
1940
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1788
1941
|
default:
|
|
1789
1942
|
break;
|
|
1790
1943
|
}
|
|
1791
|
-
if (current instanceof AggregateError
|
|
1792
|
-
|
|
1944
|
+
if (current instanceof AggregateError) {
|
|
1945
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1946
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1947
|
+
}
|
|
1948
|
+
return generateErrorNode2(ctx, id, current);
|
|
1793
1949
|
}
|
|
1794
1950
|
if (current instanceof Error) {
|
|
1795
1951
|
return generateErrorNode2(ctx, id, current);
|
|
@@ -1800,9 +1956,22 @@ function parse2(ctx, current) {
|
|
|
1800
1956
|
throw new Error("Unsupported type");
|
|
1801
1957
|
}
|
|
1802
1958
|
case "symbol":
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
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
|
+
}
|
|
1806
1975
|
default:
|
|
1807
1976
|
throw new Error("Unsupported type");
|
|
1808
1977
|
}
|
|
@@ -1810,7 +1979,7 @@ function parse2(ctx, current) {
|
|
|
1810
1979
|
function parseSync(ctx, current) {
|
|
1811
1980
|
const result = parse2(ctx, current);
|
|
1812
1981
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
1813
|
-
return [result,
|
|
1982
|
+
return [result, getRootID(ctx, current), isObject];
|
|
1814
1983
|
}
|
|
1815
1984
|
|
|
1816
1985
|
// src/index.ts
|
|
@@ -1895,6 +2064,7 @@ var src_default = serialize;
|
|
|
1895
2064
|
export {
|
|
1896
2065
|
Feature,
|
|
1897
2066
|
compileJSON,
|
|
2067
|
+
createReference,
|
|
1898
2068
|
src_default as default,
|
|
1899
2069
|
deserialize,
|
|
1900
2070
|
fromJSON,
|