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
|
@@ -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$_";
|
|
@@ -95,35 +97,35 @@ function createSerializationContext(options) {
|
|
|
95
97
|
function markRef(ctx, current) {
|
|
96
98
|
ctx.markedRefs.add(current);
|
|
97
99
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
ctx.validRefs[index] =
|
|
103
|
-
|
|
100
|
+
function getRefParam(ctx, index) {
|
|
101
|
+
let actualIndex = ctx.validRefs[index];
|
|
102
|
+
if (actualIndex == null) {
|
|
103
|
+
actualIndex = ctx.refSize++;
|
|
104
|
+
ctx.validRefs[index] = actualIndex;
|
|
105
|
+
}
|
|
106
|
+
let identifier = ctx.vars[actualIndex];
|
|
107
|
+
if (identifier == null) {
|
|
108
|
+
identifier = getIdentifier(actualIndex);
|
|
109
|
+
ctx.vars[actualIndex] = identifier;
|
|
104
110
|
}
|
|
105
|
-
return
|
|
111
|
+
return identifier;
|
|
106
112
|
}
|
|
107
|
-
function
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
return ctx.
|
|
113
|
+
function getRootID(ctx, current) {
|
|
114
|
+
const ref = ctx.refs.get(current);
|
|
115
|
+
if (ref == null) {
|
|
116
|
+
return ctx.refs.size;
|
|
111
117
|
}
|
|
112
|
-
|
|
113
|
-
ctx.vars[actualIndex] = result;
|
|
114
|
-
return result;
|
|
118
|
+
return ref;
|
|
115
119
|
}
|
|
116
|
-
function
|
|
120
|
+
function createIndexedValue(ctx, current) {
|
|
117
121
|
const ref = ctx.refs.get(current);
|
|
118
|
-
if (ref
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return ref;
|
|
122
|
+
if (ref == null) {
|
|
123
|
+
const id = ctx.refs.size;
|
|
124
|
+
ctx.refs.set(current, id);
|
|
125
|
+
return id;
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return id;
|
|
127
|
+
markRef(ctx, ref);
|
|
128
|
+
return ref;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
// src/assert.ts
|
|
@@ -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",
|
|
@@ -235,7 +290,7 @@ var TRUE_NODE = {
|
|
|
235
290
|
m: void 0,
|
|
236
291
|
d: void 0,
|
|
237
292
|
a: void 0,
|
|
238
|
-
|
|
293
|
+
f: void 0
|
|
239
294
|
};
|
|
240
295
|
var FALSE_NODE = {
|
|
241
296
|
t: 2 /* Boolean */,
|
|
@@ -246,7 +301,7 @@ var FALSE_NODE = {
|
|
|
246
301
|
m: void 0,
|
|
247
302
|
d: void 0,
|
|
248
303
|
a: void 0,
|
|
249
|
-
|
|
304
|
+
f: void 0
|
|
250
305
|
};
|
|
251
306
|
var UNDEFINED_NODE = {
|
|
252
307
|
t: 4 /* Undefined */,
|
|
@@ -257,7 +312,7 @@ var UNDEFINED_NODE = {
|
|
|
257
312
|
m: void 0,
|
|
258
313
|
d: void 0,
|
|
259
314
|
a: void 0,
|
|
260
|
-
|
|
315
|
+
f: void 0
|
|
261
316
|
};
|
|
262
317
|
var NULL_NODE = {
|
|
263
318
|
t: 3 /* Null */,
|
|
@@ -268,7 +323,7 @@ var NULL_NODE = {
|
|
|
268
323
|
m: void 0,
|
|
269
324
|
d: void 0,
|
|
270
325
|
a: void 0,
|
|
271
|
-
|
|
326
|
+
f: void 0
|
|
272
327
|
};
|
|
273
328
|
var NEG_ZERO_NODE = {
|
|
274
329
|
t: 5 /* NegativeZero */,
|
|
@@ -279,7 +334,7 @@ var NEG_ZERO_NODE = {
|
|
|
279
334
|
m: void 0,
|
|
280
335
|
d: void 0,
|
|
281
336
|
a: void 0,
|
|
282
|
-
|
|
337
|
+
f: void 0
|
|
283
338
|
};
|
|
284
339
|
var INFINITY_NODE = {
|
|
285
340
|
t: 6 /* Infinity */,
|
|
@@ -290,7 +345,7 @@ var INFINITY_NODE = {
|
|
|
290
345
|
m: void 0,
|
|
291
346
|
d: void 0,
|
|
292
347
|
a: void 0,
|
|
293
|
-
|
|
348
|
+
f: void 0
|
|
294
349
|
};
|
|
295
350
|
var NEG_INFINITY_NODE = {
|
|
296
351
|
t: 7 /* NegativeInfinity */,
|
|
@@ -301,7 +356,7 @@ var NEG_INFINITY_NODE = {
|
|
|
301
356
|
m: void 0,
|
|
302
357
|
d: void 0,
|
|
303
358
|
a: void 0,
|
|
304
|
-
|
|
359
|
+
f: void 0
|
|
305
360
|
};
|
|
306
361
|
var NAN_NODE = {
|
|
307
362
|
t: 8 /* NaN */,
|
|
@@ -312,7 +367,7 @@ var NAN_NODE = {
|
|
|
312
367
|
m: void 0,
|
|
313
368
|
d: void 0,
|
|
314
369
|
a: void 0,
|
|
315
|
-
|
|
370
|
+
f: void 0
|
|
316
371
|
};
|
|
317
372
|
function createNumberNode(value) {
|
|
318
373
|
return {
|
|
@@ -324,7 +379,7 @@ function createNumberNode(value) {
|
|
|
324
379
|
m: void 0,
|
|
325
380
|
d: void 0,
|
|
326
381
|
a: void 0,
|
|
327
|
-
|
|
382
|
+
f: void 0
|
|
328
383
|
};
|
|
329
384
|
}
|
|
330
385
|
function createStringNode(value) {
|
|
@@ -337,7 +392,7 @@ function createStringNode(value) {
|
|
|
337
392
|
m: void 0,
|
|
338
393
|
d: void 0,
|
|
339
394
|
a: void 0,
|
|
340
|
-
|
|
395
|
+
f: void 0
|
|
341
396
|
};
|
|
342
397
|
}
|
|
343
398
|
function createBigIntNode(ctx, current) {
|
|
@@ -345,18 +400,18 @@ function createBigIntNode(ctx, current) {
|
|
|
345
400
|
return {
|
|
346
401
|
t: 9 /* BigInt */,
|
|
347
402
|
i: void 0,
|
|
348
|
-
s: current
|
|
403
|
+
s: "" + current,
|
|
349
404
|
l: void 0,
|
|
350
405
|
c: void 0,
|
|
351
406
|
m: void 0,
|
|
352
407
|
d: void 0,
|
|
353
408
|
a: void 0,
|
|
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,
|
|
@@ -364,7 +419,7 @@ function createReferenceNode(id) {
|
|
|
364
419
|
m: void 0,
|
|
365
420
|
d: void 0,
|
|
366
421
|
a: void 0,
|
|
367
|
-
|
|
422
|
+
f: void 0
|
|
368
423
|
};
|
|
369
424
|
}
|
|
370
425
|
function createDateNode(id, current) {
|
|
@@ -376,7 +431,7 @@ function createDateNode(id, current) {
|
|
|
376
431
|
c: void 0,
|
|
377
432
|
m: void 0,
|
|
378
433
|
d: void 0,
|
|
379
|
-
|
|
434
|
+
f: void 0,
|
|
380
435
|
a: void 0
|
|
381
436
|
};
|
|
382
437
|
}
|
|
@@ -390,7 +445,7 @@ function createRegExpNode(id, current) {
|
|
|
390
445
|
m: current.flags,
|
|
391
446
|
d: void 0,
|
|
392
447
|
a: void 0,
|
|
393
|
-
|
|
448
|
+
f: void 0
|
|
394
449
|
};
|
|
395
450
|
}
|
|
396
451
|
function createTypedArrayNode(ctx, id, current) {
|
|
@@ -399,7 +454,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
399
454
|
const len = current.length;
|
|
400
455
|
const values = new Array(len);
|
|
401
456
|
for (let i = 0; i < len; i++) {
|
|
402
|
-
values[i] = current[i]
|
|
457
|
+
values[i] = "" + current[i];
|
|
403
458
|
}
|
|
404
459
|
return {
|
|
405
460
|
t: 22 /* TypedArray */,
|
|
@@ -410,7 +465,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
410
465
|
m: void 0,
|
|
411
466
|
d: void 0,
|
|
412
467
|
a: void 0,
|
|
413
|
-
|
|
468
|
+
f: void 0
|
|
414
469
|
};
|
|
415
470
|
}
|
|
416
471
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -423,7 +478,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
423
478
|
const len = current.length;
|
|
424
479
|
const values = new Array(len);
|
|
425
480
|
for (let i = 0; i < len; i++) {
|
|
426
|
-
values[i] = current[i]
|
|
481
|
+
values[i] = "" + current[i];
|
|
427
482
|
}
|
|
428
483
|
return {
|
|
429
484
|
t: 23 /* BigIntTypedArray */,
|
|
@@ -434,10 +489,12 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
434
489
|
m: void 0,
|
|
435
490
|
d: void 0,
|
|
436
491
|
a: void 0,
|
|
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,
|
|
@@ -447,7 +504,20 @@ function createWKSymbolNode(current) {
|
|
|
447
504
|
m: void 0,
|
|
448
505
|
d: void 0,
|
|
449
506
|
a: void 0,
|
|
450
|
-
|
|
507
|
+
f: void 0
|
|
508
|
+
};
|
|
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
|
|
451
521
|
};
|
|
452
522
|
}
|
|
453
523
|
|
|
@@ -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;
|
|
@@ -622,7 +722,7 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
622
722
|
m: void 0,
|
|
623
723
|
d: void 0,
|
|
624
724
|
a: await generateNodeList(ctx, current),
|
|
625
|
-
|
|
725
|
+
f: void 0
|
|
626
726
|
};
|
|
627
727
|
}
|
|
628
728
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -658,7 +758,7 @@ async function generateMapNode(ctx, id, current) {
|
|
|
658
758
|
m: void 0,
|
|
659
759
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
660
760
|
a: void 0,
|
|
661
|
-
|
|
761
|
+
f: void 0
|
|
662
762
|
};
|
|
663
763
|
}
|
|
664
764
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -687,7 +787,7 @@ async function generateSetNode(ctx, id, current) {
|
|
|
687
787
|
m: void 0,
|
|
688
788
|
d: void 0,
|
|
689
789
|
a: nodes,
|
|
690
|
-
|
|
790
|
+
f: void 0
|
|
691
791
|
};
|
|
692
792
|
}
|
|
693
793
|
async function generateProperties(ctx, properties) {
|
|
@@ -736,7 +836,7 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
736
836
|
// Parse options first before the items
|
|
737
837
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
738
838
|
a: await generateNodeList(ctx, array),
|
|
739
|
-
|
|
839
|
+
f: void 0
|
|
740
840
|
};
|
|
741
841
|
}
|
|
742
842
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -751,7 +851,7 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
751
851
|
// Parse options first before the items
|
|
752
852
|
d: void 0,
|
|
753
853
|
a: void 0,
|
|
754
|
-
|
|
854
|
+
f: await parse(ctx, value)
|
|
755
855
|
}));
|
|
756
856
|
}
|
|
757
857
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -770,7 +870,7 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
770
870
|
m: void 0,
|
|
771
871
|
d: await generateProperties(ctx, current),
|
|
772
872
|
a: void 0,
|
|
773
|
-
|
|
873
|
+
f: void 0
|
|
774
874
|
};
|
|
775
875
|
}
|
|
776
876
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -782,10 +882,10 @@ 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
|
|
789
889
|
};
|
|
790
890
|
}
|
|
791
891
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -797,10 +897,10 @@ 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
|
|
804
904
|
};
|
|
805
905
|
}
|
|
806
906
|
async function parse(ctx, current) {
|
|
@@ -812,28 +912,32 @@ async function parse(ctx, current) {
|
|
|
812
912
|
case "string":
|
|
813
913
|
return createStringNode(current);
|
|
814
914
|
case "number":
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
915
|
+
switch (current) {
|
|
916
|
+
case Infinity:
|
|
917
|
+
return INFINITY_NODE;
|
|
918
|
+
case -Infinity:
|
|
919
|
+
return NEG_INFINITY_NODE;
|
|
920
|
+
default:
|
|
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);
|
|
826
928
|
}
|
|
827
|
-
return createNumberNode(current);
|
|
828
929
|
case "bigint":
|
|
829
930
|
return createBigIntNode(ctx, current);
|
|
830
931
|
case "object": {
|
|
831
932
|
if (!current) {
|
|
832
933
|
return NULL_NODE;
|
|
833
934
|
}
|
|
834
|
-
const id =
|
|
935
|
+
const id = createIndexedValue(ctx, current);
|
|
835
936
|
if (ctx.markedRefs.has(id)) {
|
|
836
|
-
return
|
|
937
|
+
return createIndexedValueNode(id);
|
|
938
|
+
}
|
|
939
|
+
if (hasReferenceID(current)) {
|
|
940
|
+
return createReferenceNode(id, current);
|
|
837
941
|
}
|
|
838
942
|
if (Array.isArray(current)) {
|
|
839
943
|
return generateArrayNode(ctx, id, current);
|
|
@@ -897,11 +1001,18 @@ async function parse(ctx, current) {
|
|
|
897
1001
|
case TypeError:
|
|
898
1002
|
case URIError:
|
|
899
1003
|
return generateErrorNode(ctx, id, current);
|
|
1004
|
+
case URL:
|
|
1005
|
+
return createURLNode(ctx, id, current);
|
|
1006
|
+
case URLSearchParams:
|
|
1007
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
900
1008
|
default:
|
|
901
1009
|
break;
|
|
902
1010
|
}
|
|
903
|
-
if (current instanceof AggregateError
|
|
904
|
-
|
|
1011
|
+
if (current instanceof AggregateError) {
|
|
1012
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1013
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
1014
|
+
}
|
|
1015
|
+
return generateErrorNode(ctx, id, current);
|
|
905
1016
|
}
|
|
906
1017
|
if (current instanceof Error) {
|
|
907
1018
|
return generateErrorNode(ctx, id, current);
|
|
@@ -918,9 +1029,22 @@ async function parse(ctx, current) {
|
|
|
918
1029
|
throw new Error("Unsupported type");
|
|
919
1030
|
}
|
|
920
1031
|
case "symbol":
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
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
|
+
}
|
|
924
1048
|
default:
|
|
925
1049
|
throw new Error("Unsupported type");
|
|
926
1050
|
}
|
|
@@ -928,11 +1052,11 @@ async function parse(ctx, current) {
|
|
|
928
1052
|
async function parseAsync(ctx, current) {
|
|
929
1053
|
const result = await parse(ctx, current);
|
|
930
1054
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
931
|
-
return [result,
|
|
1055
|
+
return [result, getRootID(ctx, current), isObject];
|
|
932
1056
|
}
|
|
933
1057
|
|
|
934
1058
|
// src/tree/deserialize.ts
|
|
935
|
-
function
|
|
1059
|
+
function assignIndexedValue(ctx, index, value) {
|
|
936
1060
|
ctx.valueMap.set(index, value);
|
|
937
1061
|
return value;
|
|
938
1062
|
}
|
|
@@ -947,7 +1071,7 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
947
1071
|
return result;
|
|
948
1072
|
}
|
|
949
1073
|
function deserializeArray(ctx, node) {
|
|
950
|
-
const result =
|
|
1074
|
+
const result = assignIndexedValue(
|
|
951
1075
|
ctx,
|
|
952
1076
|
node.i,
|
|
953
1077
|
new Array(node.l)
|
|
@@ -967,21 +1091,25 @@ function deserializeProperties(ctx, node, result) {
|
|
|
967
1091
|
return result;
|
|
968
1092
|
}
|
|
969
1093
|
function deserializeNullConstructor(ctx, node) {
|
|
970
|
-
const result =
|
|
1094
|
+
const result = assignIndexedValue(
|
|
1095
|
+
ctx,
|
|
1096
|
+
node.i,
|
|
1097
|
+
/* @__PURE__ */ Object.create(null)
|
|
1098
|
+
);
|
|
971
1099
|
ctx.stack.push(node.i);
|
|
972
1100
|
deserializeProperties(ctx, node.d, result);
|
|
973
1101
|
ctx.stack.pop();
|
|
974
1102
|
return result;
|
|
975
1103
|
}
|
|
976
1104
|
function deserializeObject(ctx, node) {
|
|
977
|
-
const result =
|
|
1105
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
978
1106
|
ctx.stack.push(node.i);
|
|
979
1107
|
deserializeProperties(ctx, node.d, result);
|
|
980
1108
|
ctx.stack.pop();
|
|
981
1109
|
return result;
|
|
982
1110
|
}
|
|
983
1111
|
function deserializeSet(ctx, node) {
|
|
984
|
-
const result =
|
|
1112
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
985
1113
|
ctx.stack.push(node.i);
|
|
986
1114
|
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
987
1115
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
@@ -990,7 +1118,7 @@ function deserializeSet(ctx, node) {
|
|
|
990
1118
|
return result;
|
|
991
1119
|
}
|
|
992
1120
|
function deserializeMap(ctx, node) {
|
|
993
|
-
const result =
|
|
1121
|
+
const result = assignIndexedValue(
|
|
994
1122
|
ctx,
|
|
995
1123
|
node.i,
|
|
996
1124
|
/* @__PURE__ */ new Map()
|
|
@@ -1015,7 +1143,7 @@ function deserializeDictionary(ctx, node, result) {
|
|
|
1015
1143
|
return result;
|
|
1016
1144
|
}
|
|
1017
1145
|
function deserializeAggregateError(ctx, node) {
|
|
1018
|
-
const result =
|
|
1146
|
+
const result = assignIndexedValue(ctx, node.i, new AggregateError([], invQuote(node.m)));
|
|
1019
1147
|
ctx.stack.push(node.i);
|
|
1020
1148
|
result.errors = deserializeNodeList(ctx, node, new Array(node.l));
|
|
1021
1149
|
ctx.stack.pop();
|
|
@@ -1023,7 +1151,7 @@ function deserializeAggregateError(ctx, node) {
|
|
|
1023
1151
|
}
|
|
1024
1152
|
function deserializeError(ctx, node) {
|
|
1025
1153
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
1026
|
-
const result =
|
|
1154
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(invQuote(node.m)));
|
|
1027
1155
|
return deserializeDictionary(ctx, node, result);
|
|
1028
1156
|
}
|
|
1029
1157
|
function createDeferred() {
|
|
@@ -1039,14 +1167,14 @@ function createDeferred() {
|
|
|
1039
1167
|
}
|
|
1040
1168
|
function deserializePromise(ctx, node) {
|
|
1041
1169
|
const deferred = createDeferred();
|
|
1042
|
-
const result =
|
|
1043
|
-
deferred.resolve(deserializeTree(ctx, node.
|
|
1170
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1171
|
+
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1044
1172
|
return result;
|
|
1045
1173
|
}
|
|
1046
1174
|
function deserializeTypedArray(ctx, node) {
|
|
1047
1175
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1048
1176
|
const dummy = new TypedArray();
|
|
1049
|
-
const result =
|
|
1177
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1050
1178
|
dummy.buffer,
|
|
1051
1179
|
node.l
|
|
1052
1180
|
));
|
|
@@ -1058,7 +1186,7 @@ function deserializeTypedArray(ctx, node) {
|
|
|
1058
1186
|
function deserializeIterable(ctx, node) {
|
|
1059
1187
|
const values = [];
|
|
1060
1188
|
deserializeNodeList(ctx, node, values);
|
|
1061
|
-
const result =
|
|
1189
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1062
1190
|
[Symbol.iterator]: () => values.values()
|
|
1063
1191
|
});
|
|
1064
1192
|
return deserializeDictionary(ctx, node, result);
|
|
@@ -1084,7 +1212,7 @@ function deserializeTree(ctx, node) {
|
|
|
1084
1212
|
return NaN;
|
|
1085
1213
|
case 9 /* BigInt */:
|
|
1086
1214
|
return BigInt(node.s);
|
|
1087
|
-
case 10 /*
|
|
1215
|
+
case 10 /* IndexedValue */:
|
|
1088
1216
|
return ctx.valueMap.get(node.i);
|
|
1089
1217
|
case 15 /* Array */:
|
|
1090
1218
|
return deserializeArray(ctx, node);
|
|
@@ -1093,9 +1221,9 @@ function deserializeTree(ctx, node) {
|
|
|
1093
1221
|
case 17 /* NullConstructor */:
|
|
1094
1222
|
return deserializeNullConstructor(ctx, node);
|
|
1095
1223
|
case 11 /* Date */:
|
|
1096
|
-
return
|
|
1224
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1097
1225
|
case 12 /* RegExp */:
|
|
1098
|
-
return
|
|
1226
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1099
1227
|
case 13 /* Set */:
|
|
1100
1228
|
return deserializeSet(ctx, node);
|
|
1101
1229
|
case 14 /* Map */:
|
|
@@ -1113,6 +1241,12 @@ function deserializeTree(ctx, node) {
|
|
|
1113
1241
|
return deserializePromise(ctx, node);
|
|
1114
1242
|
case 24 /* WKSymbol */:
|
|
1115
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)));
|
|
1116
1250
|
default:
|
|
1117
1251
|
throw new Error("Unsupported type");
|
|
1118
1252
|
}
|
|
@@ -1139,30 +1273,48 @@ function mergeAssignments(assignments) {
|
|
|
1139
1273
|
for (let i = 1, len = assignments.length; i < len; i++) {
|
|
1140
1274
|
item = assignments[i];
|
|
1141
1275
|
if (item.t === prev.t) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1276
|
+
switch (item.t) {
|
|
1277
|
+
case "index":
|
|
1278
|
+
if (item.v === prev.v) {
|
|
1279
|
+
current = {
|
|
1280
|
+
t: "index",
|
|
1281
|
+
s: item.s,
|
|
1282
|
+
k: void 0,
|
|
1283
|
+
v: getAssignmentExpression(current)
|
|
1284
|
+
};
|
|
1285
|
+
} else {
|
|
1286
|
+
newAssignments.push(current);
|
|
1287
|
+
current = item;
|
|
1288
|
+
}
|
|
1289
|
+
break;
|
|
1290
|
+
case "map":
|
|
1291
|
+
if (item.s === prev.s) {
|
|
1292
|
+
current = {
|
|
1293
|
+
t: "map",
|
|
1294
|
+
s: getAssignmentExpression(current),
|
|
1295
|
+
k: item.k,
|
|
1296
|
+
v: item.v
|
|
1297
|
+
};
|
|
1298
|
+
} else {
|
|
1299
|
+
newAssignments.push(current);
|
|
1300
|
+
current = item;
|
|
1301
|
+
}
|
|
1302
|
+
break;
|
|
1303
|
+
case "set":
|
|
1304
|
+
if (item.s === prev.s) {
|
|
1305
|
+
current = {
|
|
1306
|
+
t: "set",
|
|
1307
|
+
s: getAssignmentExpression(current),
|
|
1308
|
+
k: void 0,
|
|
1309
|
+
v: item.v
|
|
1310
|
+
};
|
|
1311
|
+
} else {
|
|
1312
|
+
newAssignments.push(current);
|
|
1313
|
+
current = item;
|
|
1314
|
+
}
|
|
1315
|
+
break;
|
|
1316
|
+
default:
|
|
1317
|
+
break;
|
|
1166
1318
|
}
|
|
1167
1319
|
} else {
|
|
1168
1320
|
newAssignments.push(current);
|
|
@@ -1215,20 +1367,20 @@ function createMapSet(ctx, ref, key, value) {
|
|
|
1215
1367
|
}
|
|
1216
1368
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1217
1369
|
markRef(ctx, ref);
|
|
1218
|
-
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index
|
|
1370
|
+
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1219
1371
|
}
|
|
1220
1372
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1221
1373
|
markRef(ctx, ref);
|
|
1222
1374
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1223
1375
|
}
|
|
1224
|
-
function
|
|
1376
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1225
1377
|
if (ctx.markedRefs.has(index)) {
|
|
1226
1378
|
return getRefParam(ctx, index) + "=" + value;
|
|
1227
1379
|
}
|
|
1228
1380
|
return value;
|
|
1229
1381
|
}
|
|
1230
|
-
function
|
|
1231
|
-
return node.t === 10 /*
|
|
1382
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1383
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1232
1384
|
}
|
|
1233
1385
|
function serializeNodeList(ctx, node) {
|
|
1234
1386
|
const size = node.l;
|
|
@@ -1241,7 +1393,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1241
1393
|
}
|
|
1242
1394
|
item = node.a[i];
|
|
1243
1395
|
if (item) {
|
|
1244
|
-
if (
|
|
1396
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1245
1397
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1246
1398
|
isHoley = true;
|
|
1247
1399
|
} else {
|
|
@@ -1252,16 +1404,13 @@ function serializeNodeList(ctx, node) {
|
|
|
1252
1404
|
isHoley = true;
|
|
1253
1405
|
}
|
|
1254
1406
|
}
|
|
1255
|
-
|
|
1256
|
-
values += ",";
|
|
1257
|
-
}
|
|
1258
|
-
return "[" + values + "]";
|
|
1407
|
+
return "[" + values + (isHoley ? ",]" : "]");
|
|
1259
1408
|
}
|
|
1260
1409
|
function serializeArray(ctx, node) {
|
|
1261
1410
|
ctx.stack.push(node.i);
|
|
1262
1411
|
const result = serializeNodeList(ctx, node);
|
|
1263
1412
|
ctx.stack.pop();
|
|
1264
|
-
return
|
|
1413
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1265
1414
|
}
|
|
1266
1415
|
function serializeProperties(ctx, sourceID, node) {
|
|
1267
1416
|
if (node.s === 0) {
|
|
@@ -1280,7 +1429,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1280
1429
|
val = node.v[i];
|
|
1281
1430
|
check = Number(key);
|
|
1282
1431
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1283
|
-
if (
|
|
1432
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1284
1433
|
refParam = getRefParam(ctx, val.i);
|
|
1285
1434
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1286
1435
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
@@ -1288,11 +1437,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1288
1437
|
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
|
|
1289
1438
|
}
|
|
1290
1439
|
} else {
|
|
1291
|
-
|
|
1292
|
-
result += ",";
|
|
1293
|
-
}
|
|
1294
|
-
result += isIdentifier ? key : '"' + quote(key) + '"';
|
|
1295
|
-
result += ":" + serializeTree(ctx, val);
|
|
1440
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
|
|
1296
1441
|
hasPrev = true;
|
|
1297
1442
|
}
|
|
1298
1443
|
}
|
|
@@ -1343,18 +1488,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1343
1488
|
markRef(ctx, i);
|
|
1344
1489
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1345
1490
|
if (assignments) {
|
|
1346
|
-
|
|
1347
|
-
return "(" + assignRef2(ctx, i, init) + "," + assignments + ref + ")";
|
|
1491
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1348
1492
|
}
|
|
1349
1493
|
}
|
|
1350
1494
|
}
|
|
1351
|
-
return
|
|
1495
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1352
1496
|
}
|
|
1353
1497
|
function serializeNullConstructor(ctx, node) {
|
|
1354
1498
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1355
1499
|
}
|
|
1356
1500
|
function serializeObject(ctx, node) {
|
|
1357
|
-
return
|
|
1501
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1358
1502
|
}
|
|
1359
1503
|
function serializeSet(ctx, node) {
|
|
1360
1504
|
let serialized = "new Set";
|
|
@@ -1366,13 +1510,10 @@ function serializeSet(ctx, node) {
|
|
|
1366
1510
|
let hasPrev = false;
|
|
1367
1511
|
for (let i = 0; i < size; i++) {
|
|
1368
1512
|
item = node.a[i];
|
|
1369
|
-
if (
|
|
1513
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1370
1514
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1371
1515
|
} else {
|
|
1372
|
-
|
|
1373
|
-
result += ",";
|
|
1374
|
-
}
|
|
1375
|
-
result += serializeTree(ctx, item);
|
|
1516
|
+
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1376
1517
|
hasPrev = true;
|
|
1377
1518
|
}
|
|
1378
1519
|
}
|
|
@@ -1381,7 +1522,7 @@ function serializeSet(ctx, node) {
|
|
|
1381
1522
|
serialized += "([" + result + "])";
|
|
1382
1523
|
}
|
|
1383
1524
|
}
|
|
1384
|
-
return
|
|
1525
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1385
1526
|
}
|
|
1386
1527
|
function serializeMap(ctx, node) {
|
|
1387
1528
|
let serialized = "new Map";
|
|
@@ -1397,9 +1538,9 @@ function serializeMap(ctx, node) {
|
|
|
1397
1538
|
for (let i = 0; i < node.d.s; i++) {
|
|
1398
1539
|
key = node.d.k[i];
|
|
1399
1540
|
val = node.d.v[i];
|
|
1400
|
-
if (
|
|
1541
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1401
1542
|
keyRef = getRefParam(ctx, key.i);
|
|
1402
|
-
if (
|
|
1543
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1403
1544
|
valueRef = getRefParam(ctx, val.i);
|
|
1404
1545
|
createMapSet(ctx, node.i, keyRef, valueRef);
|
|
1405
1546
|
} else {
|
|
@@ -1408,17 +1549,14 @@ function serializeMap(ctx, node) {
|
|
|
1408
1549
|
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1409
1550
|
ctx.stack = parent;
|
|
1410
1551
|
}
|
|
1411
|
-
} else if (
|
|
1552
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1412
1553
|
valueRef = getRefParam(ctx, val.i);
|
|
1413
1554
|
parent = ctx.stack;
|
|
1414
1555
|
ctx.stack = [];
|
|
1415
1556
|
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1416
1557
|
ctx.stack = parent;
|
|
1417
1558
|
} else {
|
|
1418
|
-
|
|
1419
|
-
result += ",";
|
|
1420
|
-
}
|
|
1421
|
-
result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1559
|
+
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1422
1560
|
hasPrev = true;
|
|
1423
1561
|
}
|
|
1424
1562
|
}
|
|
@@ -1427,7 +1565,7 @@ function serializeMap(ctx, node) {
|
|
|
1427
1565
|
serialized += "([" + result + "])";
|
|
1428
1566
|
}
|
|
1429
1567
|
}
|
|
1430
|
-
return
|
|
1568
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1431
1569
|
}
|
|
1432
1570
|
function serializeAggregateError(ctx, node) {
|
|
1433
1571
|
ctx.stack.push(node.i);
|
|
@@ -1441,8 +1579,8 @@ function serializeError(ctx, node) {
|
|
|
1441
1579
|
}
|
|
1442
1580
|
function serializePromise(ctx, node) {
|
|
1443
1581
|
let serialized;
|
|
1444
|
-
if (
|
|
1445
|
-
const ref = getRefParam(ctx, node.
|
|
1582
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1583
|
+
const ref = getRefParam(ctx, node.f.i);
|
|
1446
1584
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1447
1585
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1448
1586
|
} else {
|
|
@@ -1450,28 +1588,20 @@ function serializePromise(ctx, node) {
|
|
|
1450
1588
|
}
|
|
1451
1589
|
} else {
|
|
1452
1590
|
ctx.stack.push(node.i);
|
|
1453
|
-
const result = serializeTree(ctx, node.
|
|
1591
|
+
const result = serializeTree(ctx, node.f);
|
|
1454
1592
|
ctx.stack.pop();
|
|
1455
1593
|
serialized = "Promise.resolve(" + result + ")";
|
|
1456
1594
|
}
|
|
1457
|
-
return
|
|
1595
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1458
1596
|
}
|
|
1459
1597
|
function serializeTypedArray(ctx, node) {
|
|
1460
1598
|
let result = "";
|
|
1599
|
+
const isBigInt = node.t === 23 /* BigIntTypedArray */;
|
|
1461
1600
|
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1462
|
-
|
|
1463
|
-
result += ",";
|
|
1464
|
-
}
|
|
1465
|
-
result += node.s[i];
|
|
1466
|
-
if (node.t === 23 /* BigIntTypedArray */) {
|
|
1467
|
-
result += "n";
|
|
1468
|
-
}
|
|
1601
|
+
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1469
1602
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
args += "," + node.l.toString();
|
|
1473
|
-
}
|
|
1474
|
-
return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1603
|
+
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1604
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1475
1605
|
}
|
|
1476
1606
|
function serializeIterable(ctx, node) {
|
|
1477
1607
|
const parent = ctx.stack;
|
|
@@ -1496,13 +1626,13 @@ function serializeIterable(ctx, node) {
|
|
|
1496
1626
|
function serializeTree(ctx, node) {
|
|
1497
1627
|
switch (node.t) {
|
|
1498
1628
|
case 0 /* Number */:
|
|
1499
|
-
return
|
|
1629
|
+
return "" + node.s;
|
|
1500
1630
|
case 1 /* String */:
|
|
1501
1631
|
return '"' + node.s + '"';
|
|
1502
1632
|
case 2 /* Boolean */:
|
|
1503
1633
|
return node.s ? "!0" : "!1";
|
|
1504
1634
|
case 4 /* Undefined */:
|
|
1505
|
-
return "
|
|
1635
|
+
return "void 0";
|
|
1506
1636
|
case 3 /* Null */:
|
|
1507
1637
|
return "null";
|
|
1508
1638
|
case 5 /* NegativeZero */:
|
|
@@ -1515,7 +1645,7 @@ function serializeTree(ctx, node) {
|
|
|
1515
1645
|
return "NaN";
|
|
1516
1646
|
case 9 /* BigInt */:
|
|
1517
1647
|
return node.s + "n";
|
|
1518
|
-
case 10 /*
|
|
1648
|
+
case 10 /* IndexedValue */:
|
|
1519
1649
|
return getRefParam(ctx, node.i);
|
|
1520
1650
|
case 15 /* Array */:
|
|
1521
1651
|
return serializeArray(ctx, node);
|
|
@@ -1524,9 +1654,9 @@ function serializeTree(ctx, node) {
|
|
|
1524
1654
|
case 17 /* NullConstructor */:
|
|
1525
1655
|
return serializeNullConstructor(ctx, node);
|
|
1526
1656
|
case 11 /* Date */:
|
|
1527
|
-
return
|
|
1657
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1528
1658
|
case 12 /* RegExp */:
|
|
1529
|
-
return
|
|
1659
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1530
1660
|
case 13 /* Set */:
|
|
1531
1661
|
return serializeSet(ctx, node);
|
|
1532
1662
|
case 14 /* Map */:
|
|
@@ -1544,6 +1674,12 @@ function serializeTree(ctx, node) {
|
|
|
1544
1674
|
return serializePromise(ctx, node);
|
|
1545
1675
|
case 24 /* WKSymbol */:
|
|
1546
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 + '")');
|
|
1547
1683
|
default:
|
|
1548
1684
|
throw new Error("Unsupported type");
|
|
1549
1685
|
}
|
|
@@ -1582,7 +1718,7 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1582
1718
|
m: void 0,
|
|
1583
1719
|
d: void 0,
|
|
1584
1720
|
a: generateNodeList2(ctx, current),
|
|
1585
|
-
|
|
1721
|
+
f: void 0
|
|
1586
1722
|
};
|
|
1587
1723
|
}
|
|
1588
1724
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1618,7 +1754,7 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1618
1754
|
m: void 0,
|
|
1619
1755
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1620
1756
|
a: void 0,
|
|
1621
|
-
|
|
1757
|
+
f: void 0
|
|
1622
1758
|
};
|
|
1623
1759
|
}
|
|
1624
1760
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1647,7 +1783,7 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1647
1783
|
m: void 0,
|
|
1648
1784
|
d: void 0,
|
|
1649
1785
|
a: nodes,
|
|
1650
|
-
|
|
1786
|
+
f: void 0
|
|
1651
1787
|
};
|
|
1652
1788
|
}
|
|
1653
1789
|
function generateProperties2(ctx, properties) {
|
|
@@ -1696,7 +1832,7 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1696
1832
|
// Parse options first before the items
|
|
1697
1833
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1698
1834
|
a: generateNodeList2(ctx, array),
|
|
1699
|
-
|
|
1835
|
+
f: void 0
|
|
1700
1836
|
};
|
|
1701
1837
|
}
|
|
1702
1838
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1712,7 +1848,7 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1712
1848
|
m: void 0,
|
|
1713
1849
|
d: generateProperties2(ctx, current),
|
|
1714
1850
|
a: void 0,
|
|
1715
|
-
|
|
1851
|
+
f: void 0
|
|
1716
1852
|
};
|
|
1717
1853
|
}
|
|
1718
1854
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1724,10 +1860,10 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1724
1860
|
s: void 0,
|
|
1725
1861
|
l: current.errors.length,
|
|
1726
1862
|
c: void 0,
|
|
1727
|
-
m: current.message,
|
|
1863
|
+
m: quote(current.message),
|
|
1728
1864
|
d: optionsNode,
|
|
1729
1865
|
a: generateNodeList2(ctx, current.errors),
|
|
1730
|
-
|
|
1866
|
+
f: void 0
|
|
1731
1867
|
};
|
|
1732
1868
|
}
|
|
1733
1869
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1739,10 +1875,10 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1739
1875
|
s: void 0,
|
|
1740
1876
|
l: void 0,
|
|
1741
1877
|
c: getErrorConstructorName(current),
|
|
1742
|
-
m: current.message,
|
|
1878
|
+
m: quote(current.message),
|
|
1743
1879
|
d: optionsNode,
|
|
1744
1880
|
a: void 0,
|
|
1745
|
-
|
|
1881
|
+
f: void 0
|
|
1746
1882
|
};
|
|
1747
1883
|
}
|
|
1748
1884
|
function parse2(ctx, current) {
|
|
@@ -1754,28 +1890,32 @@ function parse2(ctx, current) {
|
|
|
1754
1890
|
case "string":
|
|
1755
1891
|
return createStringNode(current);
|
|
1756
1892
|
case "number":
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1893
|
+
switch (current) {
|
|
1894
|
+
case Infinity:
|
|
1895
|
+
return INFINITY_NODE;
|
|
1896
|
+
case -Infinity:
|
|
1897
|
+
return NEG_INFINITY_NODE;
|
|
1898
|
+
default:
|
|
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);
|
|
1768
1906
|
}
|
|
1769
|
-
return createNumberNode(current);
|
|
1770
1907
|
case "bigint":
|
|
1771
1908
|
return createBigIntNode(ctx, current);
|
|
1772
1909
|
case "object": {
|
|
1773
1910
|
if (!current) {
|
|
1774
1911
|
return NULL_NODE;
|
|
1775
1912
|
}
|
|
1776
|
-
const id =
|
|
1913
|
+
const id = createIndexedValue(ctx, current);
|
|
1777
1914
|
if (ctx.markedRefs.has(id)) {
|
|
1778
|
-
return
|
|
1915
|
+
return createIndexedValueNode(id);
|
|
1916
|
+
}
|
|
1917
|
+
if (hasReferenceID(current)) {
|
|
1918
|
+
return createReferenceNode(id, current);
|
|
1779
1919
|
}
|
|
1780
1920
|
if (Array.isArray(current)) {
|
|
1781
1921
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1803,9 +1943,19 @@ function parse2(ctx, current) {
|
|
|
1803
1943
|
case Set:
|
|
1804
1944
|
return generateSetNode2(ctx, id, current);
|
|
1805
1945
|
case Object:
|
|
1806
|
-
return generateObjectNode2(
|
|
1946
|
+
return generateObjectNode2(
|
|
1947
|
+
ctx,
|
|
1948
|
+
id,
|
|
1949
|
+
current,
|
|
1950
|
+
false
|
|
1951
|
+
);
|
|
1807
1952
|
case void 0:
|
|
1808
|
-
return generateObjectNode2(
|
|
1953
|
+
return generateObjectNode2(
|
|
1954
|
+
ctx,
|
|
1955
|
+
id,
|
|
1956
|
+
current,
|
|
1957
|
+
true
|
|
1958
|
+
);
|
|
1809
1959
|
case AggregateError:
|
|
1810
1960
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1811
1961
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1819,11 +1969,18 @@ function parse2(ctx, current) {
|
|
|
1819
1969
|
case TypeError:
|
|
1820
1970
|
case URIError:
|
|
1821
1971
|
return generateErrorNode2(ctx, id, current);
|
|
1972
|
+
case URL:
|
|
1973
|
+
return createURLNode(ctx, id, current);
|
|
1974
|
+
case URLSearchParams:
|
|
1975
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1822
1976
|
default:
|
|
1823
1977
|
break;
|
|
1824
1978
|
}
|
|
1825
|
-
if (current instanceof AggregateError
|
|
1826
|
-
|
|
1979
|
+
if (current instanceof AggregateError) {
|
|
1980
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1981
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1982
|
+
}
|
|
1983
|
+
return generateErrorNode2(ctx, id, current);
|
|
1827
1984
|
}
|
|
1828
1985
|
if (current instanceof Error) {
|
|
1829
1986
|
return generateErrorNode2(ctx, id, current);
|
|
@@ -1834,9 +1991,22 @@ function parse2(ctx, current) {
|
|
|
1834
1991
|
throw new Error("Unsupported type");
|
|
1835
1992
|
}
|
|
1836
1993
|
case "symbol":
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
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
|
+
}
|
|
1840
2010
|
default:
|
|
1841
2011
|
throw new Error("Unsupported type");
|
|
1842
2012
|
}
|
|
@@ -1844,7 +2014,7 @@ function parse2(ctx, current) {
|
|
|
1844
2014
|
function parseSync(ctx, current) {
|
|
1845
2015
|
const result = parse2(ctx, current);
|
|
1846
2016
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
1847
|
-
return [result,
|
|
2017
|
+
return [result, getRootID(ctx, current), isObject];
|
|
1848
2018
|
}
|
|
1849
2019
|
|
|
1850
2020
|
// src/index.ts
|