seroval 0.4.0-alpha.13 → 0.4.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/development/index.cjs +639 -598
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +639 -598
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/context.d.ts +25 -23
- package/dist/types/tree/primitives.d.ts +10 -1
- package/dist/types/tree/serialize.d.ts +21 -2
- package/dist/types/tree/shared.d.ts +0 -3
- package/dist/types/tree/types.d.ts +38 -57
- package/package.json +2 -2
- package/src/context.ts +53 -49
- package/src/index.ts +37 -36
- package/src/tree/async.ts +112 -49
- package/src/tree/primitives.ts +143 -7
- package/src/tree/serialize.ts +359 -360
- package/src/tree/shared.ts +0 -13
- package/src/tree/sync.ts +95 -46
- package/src/tree/types.ts +53 -202
|
@@ -249,35 +249,27 @@ function getIdentifier(index) {
|
|
|
249
249
|
var DEFAULT_OPTIONS = {
|
|
250
250
|
target: "es2023"
|
|
251
251
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
// Supported features
|
|
272
|
-
__publicField(this, "features");
|
|
273
|
-
// Refs that are...referenced
|
|
274
|
-
__publicField(this, "markedRefs");
|
|
275
|
-
this.features = options.features;
|
|
276
|
-
this.markedRefs = options.markedRefs;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
252
|
+
function createParserContext(options = {}) {
|
|
253
|
+
const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
|
|
254
|
+
return {
|
|
255
|
+
markedRefs: /* @__PURE__ */ new Set(),
|
|
256
|
+
refs: /* @__PURE__ */ new Map(),
|
|
257
|
+
features: parseTargets(result.target)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function createSerializationContext(options) {
|
|
261
|
+
return {
|
|
262
|
+
stack: [],
|
|
263
|
+
vars: [],
|
|
264
|
+
assignments: [],
|
|
265
|
+
validRefs: [],
|
|
266
|
+
refSize: 0,
|
|
267
|
+
features: options.features,
|
|
268
|
+
markedRefs: new Set(options.markedRefs)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
279
271
|
function markRef(ctx, current) {
|
|
280
|
-
ctx.markedRefs
|
|
272
|
+
ctx.markedRefs.add(current);
|
|
281
273
|
}
|
|
282
274
|
function createValidRef(ctx, index) {
|
|
283
275
|
const current = ctx.validRefs[index];
|
|
@@ -359,198 +351,119 @@ function quote(str) {
|
|
|
359
351
|
return `"${result}"`;
|
|
360
352
|
}
|
|
361
353
|
|
|
362
|
-
// src/tree/types.ts
|
|
363
|
-
var SerovalObjectRecordNode = class {
|
|
364
|
-
constructor(k, v, s) {
|
|
365
|
-
__publicField(this, "k");
|
|
366
|
-
__publicField(this, "v");
|
|
367
|
-
__publicField(this, "s");
|
|
368
|
-
this.k = k;
|
|
369
|
-
this.v = v;
|
|
370
|
-
this.s = s;
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
var SerovalMapRecordNode = class {
|
|
374
|
-
constructor(k, v, s) {
|
|
375
|
-
__publicField(this, "k");
|
|
376
|
-
__publicField(this, "v");
|
|
377
|
-
__publicField(this, "s");
|
|
378
|
-
this.k = k;
|
|
379
|
-
this.v = v;
|
|
380
|
-
this.s = s;
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
var SerovalPrimitiveNode = class {
|
|
384
|
-
constructor(current) {
|
|
385
|
-
__publicField(this, "t", 0 /* Primitive */);
|
|
386
|
-
__publicField(this, "s");
|
|
387
|
-
this.s = current;
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
var SerovalReferenceNode = class {
|
|
391
|
-
constructor(id) {
|
|
392
|
-
__publicField(this, "t", 2 /* Reference */);
|
|
393
|
-
__publicField(this, "i");
|
|
394
|
-
this.i = id;
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
var SerovalBigIntNode = class {
|
|
398
|
-
constructor(current) {
|
|
399
|
-
__publicField(this, "t", 1 /* BigInt */);
|
|
400
|
-
__publicField(this, "s");
|
|
401
|
-
this.s = `${current}n`;
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
var SerovalDateNode = class {
|
|
405
|
-
constructor(id, current) {
|
|
406
|
-
__publicField(this, "t", 3 /* Date */);
|
|
407
|
-
__publicField(this, "i");
|
|
408
|
-
__publicField(this, "s");
|
|
409
|
-
this.i = id;
|
|
410
|
-
this.s = current.toISOString();
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
var SerovalRegExpNode = class {
|
|
414
|
-
constructor(id, current) {
|
|
415
|
-
__publicField(this, "t", 4 /* RegExp */);
|
|
416
|
-
__publicField(this, "i");
|
|
417
|
-
__publicField(this, "s");
|
|
418
|
-
this.i = id;
|
|
419
|
-
this.s = String(current);
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
var SerovalTypedArrayNode = class {
|
|
423
|
-
constructor(id, current) {
|
|
424
|
-
__publicField(this, "t", 14 /* TypedArray */);
|
|
425
|
-
__publicField(this, "i");
|
|
426
|
-
__publicField(this, "s");
|
|
427
|
-
__publicField(this, "l");
|
|
428
|
-
__publicField(this, "c");
|
|
429
|
-
this.i = id;
|
|
430
|
-
this.s = current.toString();
|
|
431
|
-
this.l = current.byteOffset;
|
|
432
|
-
this.c = current.constructor.name;
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
var SerovalBigIntTypedArrayNode = class {
|
|
436
|
-
constructor(id, current) {
|
|
437
|
-
__publicField(this, "t", 15 /* BigIntTypedArray */);
|
|
438
|
-
__publicField(this, "i");
|
|
439
|
-
__publicField(this, "s");
|
|
440
|
-
__publicField(this, "l");
|
|
441
|
-
__publicField(this, "c");
|
|
442
|
-
let result = "";
|
|
443
|
-
const cap = current.length - 1;
|
|
444
|
-
for (let i = 0; i < cap; i++) {
|
|
445
|
-
result += `${current[i]}n,`;
|
|
446
|
-
}
|
|
447
|
-
result += `"${current[cap]}"`;
|
|
448
|
-
this.i = id;
|
|
449
|
-
this.s = result;
|
|
450
|
-
this.l = current.byteOffset;
|
|
451
|
-
this.c = current.constructor.name;
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
var SerovalSetNode = class {
|
|
455
|
-
constructor(id, a) {
|
|
456
|
-
__publicField(this, "t", 5 /* Set */);
|
|
457
|
-
__publicField(this, "i");
|
|
458
|
-
__publicField(this, "a");
|
|
459
|
-
this.i = id;
|
|
460
|
-
this.a = a;
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
var SerovalMapNode = class {
|
|
464
|
-
constructor(id, d) {
|
|
465
|
-
__publicField(this, "t", 6 /* Map */);
|
|
466
|
-
__publicField(this, "i");
|
|
467
|
-
__publicField(this, "d");
|
|
468
|
-
this.i = id;
|
|
469
|
-
this.d = d;
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
var SerovalArrayNode = class {
|
|
473
|
-
constructor(id, a) {
|
|
474
|
-
__publicField(this, "t", 7 /* Array */);
|
|
475
|
-
__publicField(this, "i");
|
|
476
|
-
__publicField(this, "a");
|
|
477
|
-
this.i = id;
|
|
478
|
-
this.a = a;
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
var SerovalObjectNode = class {
|
|
482
|
-
constructor(id, d) {
|
|
483
|
-
__publicField(this, "t", 8 /* Object */);
|
|
484
|
-
__publicField(this, "i");
|
|
485
|
-
__publicField(this, "d");
|
|
486
|
-
this.i = id;
|
|
487
|
-
this.d = d;
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
var SerovalNullConstructorNode = class {
|
|
491
|
-
constructor(id, d) {
|
|
492
|
-
__publicField(this, "t", 9 /* NullConstructor */);
|
|
493
|
-
__publicField(this, "i");
|
|
494
|
-
__publicField(this, "d");
|
|
495
|
-
this.i = id;
|
|
496
|
-
this.d = d;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
var SerovalPromiseNode = class {
|
|
500
|
-
constructor(id, n) {
|
|
501
|
-
__publicField(this, "t", 10 /* Promise */);
|
|
502
|
-
__publicField(this, "i");
|
|
503
|
-
__publicField(this, "n");
|
|
504
|
-
this.i = id;
|
|
505
|
-
this.n = n;
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
var SerovalErrorNode = class {
|
|
509
|
-
constructor(id, c, m, d) {
|
|
510
|
-
__publicField(this, "t", 11 /* Error */);
|
|
511
|
-
__publicField(this, "i");
|
|
512
|
-
__publicField(this, "c");
|
|
513
|
-
__publicField(this, "m");
|
|
514
|
-
__publicField(this, "d");
|
|
515
|
-
this.i = id;
|
|
516
|
-
this.c = c;
|
|
517
|
-
this.m = m;
|
|
518
|
-
this.d = d;
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
var SerovalAggregateErrorNode = class {
|
|
522
|
-
constructor(id, m, d, n) {
|
|
523
|
-
__publicField(this, "t", 12 /* AggregateError */);
|
|
524
|
-
__publicField(this, "i");
|
|
525
|
-
__publicField(this, "m");
|
|
526
|
-
__publicField(this, "d");
|
|
527
|
-
__publicField(this, "n");
|
|
528
|
-
this.i = id;
|
|
529
|
-
this.m = m;
|
|
530
|
-
this.d = d;
|
|
531
|
-
this.n = n;
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
var SerovalIterableNode = class {
|
|
535
|
-
constructor(id, d, a) {
|
|
536
|
-
__publicField(this, "t", 13 /* Iterable */);
|
|
537
|
-
__publicField(this, "i");
|
|
538
|
-
__publicField(this, "d");
|
|
539
|
-
__publicField(this, "a");
|
|
540
|
-
this.i = id;
|
|
541
|
-
this.d = d;
|
|
542
|
-
this.a = a;
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
354
|
// src/tree/primitives.ts
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
355
|
+
function createPrimitiveNode(value) {
|
|
356
|
+
return {
|
|
357
|
+
t: 0 /* Primitive */,
|
|
358
|
+
i: void 0,
|
|
359
|
+
s: value,
|
|
360
|
+
l: void 0,
|
|
361
|
+
c: void 0,
|
|
362
|
+
m: void 0,
|
|
363
|
+
d: void 0,
|
|
364
|
+
a: void 0,
|
|
365
|
+
n: void 0
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
var TRUE_NODE = createPrimitiveNode("!0");
|
|
369
|
+
var FALSE_NODE = createPrimitiveNode("!1");
|
|
370
|
+
var UNDEFINED_NODE = createPrimitiveNode("void 0");
|
|
371
|
+
var NULL_NODE = createPrimitiveNode(null);
|
|
372
|
+
var NEG_ZERO_NODE = createPrimitiveNode("-0");
|
|
373
|
+
var INFINITY_NODE = createPrimitiveNode("1/0");
|
|
374
|
+
var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
|
|
375
|
+
function createBigIntNode(ctx, current) {
|
|
376
|
+
assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
377
|
+
return {
|
|
378
|
+
t: 1 /* BigInt */,
|
|
379
|
+
i: void 0,
|
|
380
|
+
s: `${current}n`,
|
|
381
|
+
l: void 0,
|
|
382
|
+
c: void 0,
|
|
383
|
+
m: void 0,
|
|
384
|
+
d: void 0,
|
|
385
|
+
a: void 0,
|
|
386
|
+
n: void 0
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function createReferenceNode(id) {
|
|
390
|
+
return {
|
|
391
|
+
t: 2 /* Reference */,
|
|
392
|
+
i: id,
|
|
393
|
+
s: void 0,
|
|
394
|
+
l: void 0,
|
|
395
|
+
c: void 0,
|
|
396
|
+
m: void 0,
|
|
397
|
+
d: void 0,
|
|
398
|
+
a: void 0,
|
|
399
|
+
n: void 0
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function createDateNode(id, current) {
|
|
403
|
+
return {
|
|
404
|
+
t: 3 /* Date */,
|
|
405
|
+
i: id,
|
|
406
|
+
s: current.toISOString(),
|
|
407
|
+
l: void 0,
|
|
408
|
+
c: void 0,
|
|
409
|
+
m: void 0,
|
|
410
|
+
d: void 0,
|
|
411
|
+
n: void 0,
|
|
412
|
+
a: void 0
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function createRegExpNode(id, current) {
|
|
416
|
+
return {
|
|
417
|
+
t: 4 /* RegExp */,
|
|
418
|
+
i: id,
|
|
419
|
+
s: String(current),
|
|
420
|
+
l: void 0,
|
|
421
|
+
c: void 0,
|
|
422
|
+
m: void 0,
|
|
423
|
+
d: void 0,
|
|
424
|
+
a: void 0,
|
|
425
|
+
n: void 0
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function createTypedArrayNode(ctx, id, current) {
|
|
429
|
+
const constructor = current.constructor.name;
|
|
430
|
+
assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
431
|
+
return {
|
|
432
|
+
t: 14 /* TypedArray */,
|
|
433
|
+
i: id,
|
|
434
|
+
s: current.toString(),
|
|
435
|
+
l: current.byteOffset,
|
|
436
|
+
c: constructor,
|
|
437
|
+
m: void 0,
|
|
438
|
+
d: void 0,
|
|
439
|
+
a: void 0,
|
|
440
|
+
n: void 0
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function createBigIntTypedArrayNode(ctx, id, current) {
|
|
444
|
+
const constructor = current.constructor.name;
|
|
445
|
+
assert(
|
|
446
|
+
ctx.features & 2048 /* BigIntTypedArray */,
|
|
447
|
+
`Unsupported value type "${constructor}"`
|
|
448
|
+
);
|
|
449
|
+
let result = "";
|
|
450
|
+
const cap = current.length - 1;
|
|
451
|
+
for (let i = 0; i < cap; i++) {
|
|
452
|
+
result += `${current[i]}n,`;
|
|
453
|
+
}
|
|
454
|
+
result += `"${current[cap]}"`;
|
|
455
|
+
return {
|
|
456
|
+
t: 15 /* BigIntTypedArray */,
|
|
457
|
+
i: id,
|
|
458
|
+
s: result,
|
|
459
|
+
l: current.byteOffset,
|
|
460
|
+
c: constructor,
|
|
461
|
+
m: void 0,
|
|
462
|
+
d: void 0,
|
|
463
|
+
a: void 0,
|
|
464
|
+
n: void 0
|
|
465
|
+
};
|
|
466
|
+
}
|
|
554
467
|
|
|
555
468
|
// src/tree/shared.ts
|
|
556
469
|
function getErrorConstructor(error) {
|
|
@@ -602,9 +515,6 @@ function getIterableOptions(obj) {
|
|
|
602
515
|
}
|
|
603
516
|
return void 0;
|
|
604
517
|
}
|
|
605
|
-
function isReferenceInStack(ctx, node) {
|
|
606
|
-
return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
|
|
607
|
-
}
|
|
608
518
|
function isIterable(value) {
|
|
609
519
|
if (!value || typeof value !== "object") {
|
|
610
520
|
return false;
|
|
@@ -662,7 +572,17 @@ var AsyncParser = class {
|
|
|
662
572
|
return nodes;
|
|
663
573
|
}
|
|
664
574
|
async generateArrayNode(id, current) {
|
|
665
|
-
return
|
|
575
|
+
return {
|
|
576
|
+
t: 7 /* Array */,
|
|
577
|
+
i: id,
|
|
578
|
+
s: void 0,
|
|
579
|
+
l: void 0,
|
|
580
|
+
c: void 0,
|
|
581
|
+
m: void 0,
|
|
582
|
+
d: void 0,
|
|
583
|
+
a: await this.generateNodeList(current),
|
|
584
|
+
n: void 0
|
|
585
|
+
};
|
|
666
586
|
}
|
|
667
587
|
async generateMapNode(id, current) {
|
|
668
588
|
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -688,7 +608,17 @@ var AsyncParser = class {
|
|
|
688
608
|
keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
|
|
689
609
|
valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
|
|
690
610
|
}
|
|
691
|
-
return
|
|
611
|
+
return {
|
|
612
|
+
t: 6 /* Map */,
|
|
613
|
+
i: id,
|
|
614
|
+
s: void 0,
|
|
615
|
+
l: void 0,
|
|
616
|
+
c: void 0,
|
|
617
|
+
m: void 0,
|
|
618
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
619
|
+
a: void 0,
|
|
620
|
+
n: void 0
|
|
621
|
+
};
|
|
692
622
|
}
|
|
693
623
|
async generateSetNode(id, current) {
|
|
694
624
|
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -707,7 +637,17 @@ var AsyncParser = class {
|
|
|
707
637
|
for (let i = 0; i < deferredSize; i++) {
|
|
708
638
|
nodes[nodeSize + i] = await this.parse(deferred[i]);
|
|
709
639
|
}
|
|
710
|
-
return
|
|
640
|
+
return {
|
|
641
|
+
t: 5 /* Set */,
|
|
642
|
+
i: id,
|
|
643
|
+
s: void 0,
|
|
644
|
+
l: void 0,
|
|
645
|
+
c: void 0,
|
|
646
|
+
m: void 0,
|
|
647
|
+
d: void 0,
|
|
648
|
+
a: nodes,
|
|
649
|
+
n: void 0
|
|
650
|
+
};
|
|
711
651
|
}
|
|
712
652
|
async generateProperties(properties) {
|
|
713
653
|
const keys = Object.keys(properties);
|
|
@@ -735,21 +675,42 @@ var AsyncParser = class {
|
|
|
735
675
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
736
676
|
valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
|
|
737
677
|
}
|
|
738
|
-
return
|
|
678
|
+
return {
|
|
679
|
+
k: keyNodes,
|
|
680
|
+
v: valueNodes,
|
|
681
|
+
s: size
|
|
682
|
+
};
|
|
739
683
|
}
|
|
740
684
|
async generateIterableNode(id, current) {
|
|
741
685
|
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
742
686
|
const options = getIterableOptions(current);
|
|
743
|
-
return
|
|
744
|
-
|
|
687
|
+
return {
|
|
688
|
+
t: 13 /* Iterable */,
|
|
689
|
+
i: id,
|
|
690
|
+
s: void 0,
|
|
691
|
+
l: void 0,
|
|
692
|
+
c: void 0,
|
|
693
|
+
m: void 0,
|
|
745
694
|
// Parse options first before the items
|
|
746
|
-
options ? await this.generateProperties(options) : void 0,
|
|
747
|
-
await this.generateNodeList(Array.from(current))
|
|
748
|
-
|
|
695
|
+
d: options ? await this.generateProperties(options) : void 0,
|
|
696
|
+
a: await this.generateNodeList(Array.from(current)),
|
|
697
|
+
n: void 0
|
|
698
|
+
};
|
|
749
699
|
}
|
|
750
700
|
async generatePromiseNode(id, current) {
|
|
751
701
|
assert(this.ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
|
|
752
|
-
return current.then(async (value) =>
|
|
702
|
+
return current.then(async (value) => ({
|
|
703
|
+
t: 10 /* Promise */,
|
|
704
|
+
i: id,
|
|
705
|
+
s: void 0,
|
|
706
|
+
l: void 0,
|
|
707
|
+
c: void 0,
|
|
708
|
+
m: void 0,
|
|
709
|
+
// Parse options first before the items
|
|
710
|
+
d: void 0,
|
|
711
|
+
a: void 0,
|
|
712
|
+
n: await this.parse(value)
|
|
713
|
+
}));
|
|
753
714
|
}
|
|
754
715
|
async generateObjectNode(id, current, empty) {
|
|
755
716
|
if (Symbol.iterator in current) {
|
|
@@ -758,26 +719,47 @@ var AsyncParser = class {
|
|
|
758
719
|
if ("then" in current && typeof current.then === "function") {
|
|
759
720
|
return this.generatePromiseNode(id, current);
|
|
760
721
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
722
|
+
return {
|
|
723
|
+
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
724
|
+
i: id,
|
|
725
|
+
s: void 0,
|
|
726
|
+
l: void 0,
|
|
727
|
+
c: void 0,
|
|
728
|
+
m: void 0,
|
|
729
|
+
d: await this.generateProperties(current),
|
|
730
|
+
a: void 0,
|
|
731
|
+
n: void 0
|
|
732
|
+
};
|
|
766
733
|
}
|
|
767
734
|
async generateAggregateErrorNode(id, current) {
|
|
768
735
|
const options = getErrorOptions(current);
|
|
769
736
|
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
770
|
-
return
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
737
|
+
return {
|
|
738
|
+
t: 12 /* AggregateError */,
|
|
739
|
+
i: id,
|
|
740
|
+
s: void 0,
|
|
741
|
+
l: void 0,
|
|
742
|
+
c: void 0,
|
|
743
|
+
m: current.message,
|
|
744
|
+
d: optionsNode,
|
|
745
|
+
a: void 0,
|
|
746
|
+
n: await this.parse(current.errors)
|
|
747
|
+
};
|
|
776
748
|
}
|
|
777
749
|
async generateErrorNode(id, current) {
|
|
778
750
|
const options = getErrorOptions(current);
|
|
779
751
|
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
780
|
-
return
|
|
752
|
+
return {
|
|
753
|
+
t: 11 /* Error */,
|
|
754
|
+
i: id,
|
|
755
|
+
s: void 0,
|
|
756
|
+
l: void 0,
|
|
757
|
+
c: getErrorConstructor(current),
|
|
758
|
+
m: current.message,
|
|
759
|
+
d: optionsNode,
|
|
760
|
+
a: void 0,
|
|
761
|
+
n: void 0
|
|
762
|
+
};
|
|
781
763
|
}
|
|
782
764
|
async parse(current) {
|
|
783
765
|
switch (typeof current) {
|
|
@@ -786,37 +768,36 @@ var AsyncParser = class {
|
|
|
786
768
|
case "undefined":
|
|
787
769
|
return UNDEFINED_NODE;
|
|
788
770
|
case "string":
|
|
789
|
-
return
|
|
771
|
+
return createPrimitiveNode(quote(current));
|
|
790
772
|
case "number":
|
|
791
773
|
if (Object.is(current, -0)) {
|
|
792
774
|
return NEG_ZERO_NODE;
|
|
793
775
|
}
|
|
794
776
|
if (Object.is(current, Infinity)) {
|
|
795
|
-
return
|
|
777
|
+
return createPrimitiveNode("1/0");
|
|
796
778
|
}
|
|
797
779
|
if (Object.is(current, -Infinity)) {
|
|
798
|
-
return
|
|
780
|
+
return createPrimitiveNode("-1/0");
|
|
799
781
|
}
|
|
800
|
-
return
|
|
782
|
+
return createPrimitiveNode(current);
|
|
801
783
|
case "bigint":
|
|
802
|
-
|
|
803
|
-
return new SerovalBigIntNode(current);
|
|
784
|
+
return createBigIntNode(this.ctx, current);
|
|
804
785
|
case "object": {
|
|
805
786
|
if (!current) {
|
|
806
787
|
return NULL_NODE;
|
|
807
788
|
}
|
|
808
789
|
const id = createRef(this.ctx, current, true);
|
|
809
|
-
if (this.ctx.markedRefs
|
|
810
|
-
return
|
|
790
|
+
if (this.ctx.markedRefs.has(id)) {
|
|
791
|
+
return createReferenceNode(id);
|
|
811
792
|
}
|
|
812
793
|
if (Array.isArray(current)) {
|
|
813
794
|
return this.generateArrayNode(id, current);
|
|
814
795
|
}
|
|
815
796
|
switch (current.constructor) {
|
|
816
797
|
case Date:
|
|
817
|
-
return
|
|
798
|
+
return createDateNode(id, current);
|
|
818
799
|
case RegExp:
|
|
819
|
-
return
|
|
800
|
+
return createRegExpNode(id, current);
|
|
820
801
|
case Promise:
|
|
821
802
|
return this.generatePromiseNode(id, current);
|
|
822
803
|
case Int8Array:
|
|
@@ -828,15 +809,10 @@ var AsyncParser = class {
|
|
|
828
809
|
case Uint8ClampedArray:
|
|
829
810
|
case Float32Array:
|
|
830
811
|
case Float64Array:
|
|
831
|
-
|
|
832
|
-
return new SerovalTypedArrayNode(id, current);
|
|
812
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
833
813
|
case BigInt64Array:
|
|
834
814
|
case BigUint64Array:
|
|
835
|
-
|
|
836
|
-
this.ctx.features & 2048 /* BigIntTypedArray */,
|
|
837
|
-
`Unsupported value type "${current.constructor.name}"`
|
|
838
|
-
);
|
|
839
|
-
return new SerovalBigIntTypedArrayNode(id, current);
|
|
815
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
840
816
|
case Map:
|
|
841
817
|
return this.generateMapNode(id, current);
|
|
842
818
|
case Set:
|
|
@@ -891,13 +867,13 @@ async function parseAsync(ctx, current) {
|
|
|
891
867
|
|
|
892
868
|
// src/tree/serialize.ts
|
|
893
869
|
function getAssignmentExpression(assignment) {
|
|
894
|
-
switch (assignment.
|
|
870
|
+
switch (assignment.t) {
|
|
895
871
|
case "index":
|
|
896
|
-
return `${assignment.
|
|
872
|
+
return `${assignment.s}=${assignment.v}`;
|
|
897
873
|
case "map":
|
|
898
|
-
return `${assignment.
|
|
874
|
+
return `${assignment.s}.set(${assignment.k},${assignment.v})`;
|
|
899
875
|
case "set":
|
|
900
|
-
return `${assignment.
|
|
876
|
+
return `${assignment.s}.add(${assignment.v})`;
|
|
901
877
|
default:
|
|
902
878
|
return "";
|
|
903
879
|
}
|
|
@@ -908,25 +884,27 @@ function mergeAssignments(assignments) {
|
|
|
908
884
|
let prev = current;
|
|
909
885
|
for (let i = 1, len = assignments.length; i < len; i++) {
|
|
910
886
|
const item = assignments[i];
|
|
911
|
-
if (item.
|
|
912
|
-
if (item.
|
|
887
|
+
if (item.t === prev.t) {
|
|
888
|
+
if (item.t === "index" && item.v === prev.v) {
|
|
913
889
|
current = {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
890
|
+
t: "index",
|
|
891
|
+
s: item.s,
|
|
892
|
+
k: void 0,
|
|
893
|
+
v: getAssignmentExpression(current)
|
|
917
894
|
};
|
|
918
|
-
} else if (item.
|
|
895
|
+
} else if (item.t === "map" && item.s === prev.s) {
|
|
919
896
|
current = {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
897
|
+
t: "map",
|
|
898
|
+
s: getAssignmentExpression(current),
|
|
899
|
+
k: item.k,
|
|
900
|
+
v: item.v
|
|
924
901
|
};
|
|
925
|
-
} else if (item.
|
|
902
|
+
} else if (item.t === "set" && item.s === prev.s) {
|
|
926
903
|
current = {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
904
|
+
t: "set",
|
|
905
|
+
s: getAssignmentExpression(current),
|
|
906
|
+
k: void 0,
|
|
907
|
+
v: item.v
|
|
930
908
|
};
|
|
931
909
|
} else {
|
|
932
910
|
newAssignments.push(current);
|
|
@@ -955,34 +933,30 @@ function resolveAssignments(assignments) {
|
|
|
955
933
|
function resolvePatches(ctx) {
|
|
956
934
|
return resolveAssignments(ctx.assignments);
|
|
957
935
|
}
|
|
958
|
-
function assignRef(ctx, index, value) {
|
|
959
|
-
if (ctx.markedRefs[index]) {
|
|
960
|
-
return `${getRefParam(ctx, index)}=${value}`;
|
|
961
|
-
}
|
|
962
|
-
return value;
|
|
963
|
-
}
|
|
964
936
|
function createAssignment(ctx, source, value) {
|
|
965
937
|
ctx.assignments.push({
|
|
966
|
-
|
|
967
|
-
source,
|
|
968
|
-
|
|
938
|
+
t: "index",
|
|
939
|
+
s: source,
|
|
940
|
+
k: void 0,
|
|
941
|
+
v: value
|
|
969
942
|
});
|
|
970
943
|
}
|
|
971
944
|
function createSetAdd(ctx, ref, value) {
|
|
972
945
|
markRef(ctx, ref);
|
|
973
946
|
ctx.assignments.push({
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
947
|
+
t: "set",
|
|
948
|
+
s: getRefParam(ctx, ref),
|
|
949
|
+
k: void 0,
|
|
950
|
+
v: value
|
|
977
951
|
});
|
|
978
952
|
}
|
|
979
953
|
function createMapSet(ctx, ref, key, value) {
|
|
980
954
|
markRef(ctx, ref);
|
|
981
955
|
ctx.assignments.push({
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
key,
|
|
985
|
-
value
|
|
956
|
+
t: "map",
|
|
957
|
+
s: getRefParam(ctx, ref),
|
|
958
|
+
k: key,
|
|
959
|
+
v: value
|
|
986
960
|
});
|
|
987
961
|
}
|
|
988
962
|
function createArrayAssign(ctx, ref, index, value) {
|
|
@@ -994,281 +968,296 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
994
968
|
createAssignment(ctx, `${getRefParam(ctx, ref)}.${key}`, value);
|
|
995
969
|
}
|
|
996
970
|
var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
|
|
997
|
-
|
|
998
|
-
ctx
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
const parentStack = ctx.stack;
|
|
1002
|
-
ctx.stack = [];
|
|
1003
|
-
const refParam = serializeTree(ctx, node.v[i]);
|
|
1004
|
-
ctx.stack = parentStack;
|
|
1005
|
-
const key = node.k[i];
|
|
1006
|
-
const check = Number(key);
|
|
1007
|
-
const parentAssignment = ctx.assignments;
|
|
1008
|
-
ctx.assignments = mainAssignments;
|
|
1009
|
-
const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
|
|
1010
|
-
if (isIdentifier && Number.isNaN(check)) {
|
|
1011
|
-
createObjectAssign(ctx, targetRef, key, refParam);
|
|
1012
|
-
} else {
|
|
1013
|
-
createArrayAssign(ctx, targetRef, isIdentifier ? key : quote(key), refParam);
|
|
1014
|
-
}
|
|
1015
|
-
ctx.assignments = parentAssignment;
|
|
1016
|
-
}
|
|
1017
|
-
ctx.stack.pop();
|
|
1018
|
-
return resolveAssignments(mainAssignments);
|
|
1019
|
-
}
|
|
1020
|
-
function serializeObject(ctx, sourceID, node) {
|
|
1021
|
-
if (node.s === 0) {
|
|
1022
|
-
return "{}";
|
|
971
|
+
var SerovalSerializer = class {
|
|
972
|
+
constructor(ctx) {
|
|
973
|
+
__publicField(this, "ctx");
|
|
974
|
+
this.ctx = ctx;
|
|
1023
975
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
const key = node.k[i];
|
|
1028
|
-
const val = node.v[i];
|
|
1029
|
-
const check = Number(key);
|
|
1030
|
-
const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
|
|
1031
|
-
if (isReferenceInStack(ctx, val)) {
|
|
1032
|
-
const refParam = getRefParam(ctx, val.i);
|
|
1033
|
-
if (isIdentifier && Number.isNaN(check)) {
|
|
1034
|
-
createObjectAssign(ctx, sourceID, key, refParam);
|
|
1035
|
-
} else {
|
|
1036
|
-
createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
|
|
1037
|
-
}
|
|
1038
|
-
} else {
|
|
1039
|
-
result += `${isIdentifier ? key : quote(key)}:${serializeTree(ctx, val)},`;
|
|
976
|
+
assignRef(index, value) {
|
|
977
|
+
if (this.ctx.markedRefs.has(index)) {
|
|
978
|
+
return `${getRefParam(this.ctx, index)}=${value}`;
|
|
1040
979
|
}
|
|
980
|
+
return value;
|
|
1041
981
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
function serializePromise(ctx, node) {
|
|
1046
|
-
let serialized;
|
|
1047
|
-
if (isReferenceInStack(ctx, node.n)) {
|
|
1048
|
-
serialized = `Promise.resolve().then(()=>${getRefParam(ctx, node.n.i)})`;
|
|
1049
|
-
} else {
|
|
1050
|
-
ctx.stack.push(node.i);
|
|
1051
|
-
const result = serializeTree(ctx, node.n);
|
|
1052
|
-
ctx.stack.pop();
|
|
1053
|
-
serialized = `Promise.resolve(${result})`;
|
|
982
|
+
isReferenceInStack(node) {
|
|
983
|
+
return node.t === 2 /* Reference */ && this.ctx.stack.includes(node.i);
|
|
1054
984
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
let args = `[${node.s}]`;
|
|
1059
|
-
if (node.l !== 0) {
|
|
1060
|
-
args += `,${node.l}`;
|
|
1061
|
-
}
|
|
1062
|
-
return assignRef(ctx, node.i, `new ${node.c}(${args})`);
|
|
1063
|
-
}
|
|
1064
|
-
function serializeSet(ctx, node) {
|
|
1065
|
-
let serialized = "new Set";
|
|
1066
|
-
const size = node.a.length;
|
|
1067
|
-
if (size) {
|
|
1068
|
-
let result = "";
|
|
1069
|
-
ctx.stack.push(node.i);
|
|
985
|
+
serializeNodeList(node) {
|
|
986
|
+
const size = node.a.length;
|
|
987
|
+
let values = "";
|
|
1070
988
|
for (let i = 0; i < size; i++) {
|
|
1071
989
|
const item = node.a[i];
|
|
1072
|
-
if (
|
|
1073
|
-
|
|
990
|
+
if (item) {
|
|
991
|
+
if (this.isReferenceInStack(item)) {
|
|
992
|
+
createArrayAssign(this.ctx, node.i, i, getRefParam(this.ctx, item.i));
|
|
993
|
+
values += ",";
|
|
994
|
+
} else {
|
|
995
|
+
values += this.serialize(item);
|
|
996
|
+
if (i < size - 1) {
|
|
997
|
+
values += ",";
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1074
1000
|
} else {
|
|
1075
|
-
|
|
1001
|
+
values += ",";
|
|
1076
1002
|
}
|
|
1077
1003
|
}
|
|
1078
|
-
|
|
1079
|
-
if (result) {
|
|
1080
|
-
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
1081
|
-
}
|
|
1004
|
+
return `[${values}]`;
|
|
1082
1005
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1006
|
+
serializeArray(node) {
|
|
1007
|
+
this.ctx.stack.push(node.i);
|
|
1008
|
+
const result = this.serializeNodeList(node);
|
|
1009
|
+
this.ctx.stack.pop();
|
|
1010
|
+
return this.assignRef(node.i, result);
|
|
1011
|
+
}
|
|
1012
|
+
serializeObject(sourceID, node) {
|
|
1013
|
+
if (node.s === 0) {
|
|
1014
|
+
return "{}";
|
|
1015
|
+
}
|
|
1088
1016
|
let result = "";
|
|
1089
|
-
ctx.stack.push(
|
|
1090
|
-
for (let i = 0; i < node.
|
|
1091
|
-
const key = node.
|
|
1092
|
-
const val = node.
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1017
|
+
this.ctx.stack.push(sourceID);
|
|
1018
|
+
for (let i = 0; i < node.s; i++) {
|
|
1019
|
+
const key = node.k[i];
|
|
1020
|
+
const val = node.v[i];
|
|
1021
|
+
const check = Number(key);
|
|
1022
|
+
const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
|
|
1023
|
+
if (this.isReferenceInStack(val)) {
|
|
1024
|
+
const refParam = getRefParam(this.ctx, val.i);
|
|
1025
|
+
if (isIdentifier && Number.isNaN(check)) {
|
|
1026
|
+
createObjectAssign(this.ctx, sourceID, key, refParam);
|
|
1098
1027
|
} else {
|
|
1099
|
-
|
|
1100
|
-
ctx.stack = [];
|
|
1101
|
-
createMapSet(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1102
|
-
ctx.stack = parent;
|
|
1028
|
+
createArrayAssign(this.ctx, sourceID, isIdentifier ? key : quote(key), refParam);
|
|
1103
1029
|
}
|
|
1104
|
-
} else if (isReferenceInStack(ctx, val)) {
|
|
1105
|
-
const valueRef = getRefParam(ctx, val.i);
|
|
1106
|
-
const parent = ctx.stack;
|
|
1107
|
-
ctx.stack = [];
|
|
1108
|
-
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1109
|
-
ctx.stack = parent;
|
|
1110
1030
|
} else {
|
|
1111
|
-
result +=
|
|
1031
|
+
result += `${isIdentifier ? key : quote(key)}:${this.serialize(val)},`;
|
|
1112
1032
|
}
|
|
1113
1033
|
}
|
|
1114
|
-
ctx.stack.pop();
|
|
1115
|
-
|
|
1116
|
-
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
1117
|
-
}
|
|
1034
|
+
this.ctx.stack.pop();
|
|
1035
|
+
return `{${result.substring(0, result.length - 1)}}`;
|
|
1118
1036
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1037
|
+
serializeWithObjectAssign(value, id, serialized) {
|
|
1038
|
+
const fields = this.serializeObject(id, value);
|
|
1039
|
+
if (fields !== "{}") {
|
|
1040
|
+
return `Object.assign(${serialized},${fields})`;
|
|
1041
|
+
}
|
|
1042
|
+
return serialized;
|
|
1043
|
+
}
|
|
1044
|
+
serializeAssignments(sourceID, node) {
|
|
1045
|
+
this.ctx.stack.push(sourceID);
|
|
1046
|
+
const mainAssignments = [];
|
|
1047
|
+
for (let i = 0; i < node.s; i++) {
|
|
1048
|
+
const parentStack = this.ctx.stack;
|
|
1049
|
+
this.ctx.stack = [];
|
|
1050
|
+
const refParam = this.serialize(node.v[i]);
|
|
1051
|
+
this.ctx.stack = parentStack;
|
|
1052
|
+
const key = node.k[i];
|
|
1053
|
+
const check = Number(key);
|
|
1054
|
+
const parentAssignment = this.ctx.assignments;
|
|
1055
|
+
this.ctx.assignments = mainAssignments;
|
|
1056
|
+
const isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
|
|
1057
|
+
if (isIdentifier && Number.isNaN(check)) {
|
|
1058
|
+
createObjectAssign(this.ctx, sourceID, key, refParam);
|
|
1130
1059
|
} else {
|
|
1131
|
-
|
|
1132
|
-
if (i < size - 1) {
|
|
1133
|
-
values += ",";
|
|
1134
|
-
}
|
|
1060
|
+
createArrayAssign(this.ctx, sourceID, isIdentifier ? key : quote(key), refParam);
|
|
1135
1061
|
}
|
|
1136
|
-
|
|
1137
|
-
values += ",";
|
|
1062
|
+
this.ctx.assignments = parentAssignment;
|
|
1138
1063
|
}
|
|
1064
|
+
this.ctx.stack.pop();
|
|
1065
|
+
return resolveAssignments(mainAssignments);
|
|
1139
1066
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
const result = serializeNodeList(ctx, node);
|
|
1145
|
-
ctx.stack.pop();
|
|
1146
|
-
return assignRef(ctx, node.i, result);
|
|
1147
|
-
}
|
|
1148
|
-
function serializeWithObjectAssign(ctx, value, id, serialized) {
|
|
1149
|
-
const fields = serializeObject(ctx, id, value);
|
|
1150
|
-
if (fields !== "{}") {
|
|
1151
|
-
return `Object.assign(${serialized},${fields})`;
|
|
1152
|
-
}
|
|
1153
|
-
return serialized;
|
|
1154
|
-
}
|
|
1155
|
-
function serializeAggregateError(ctx, node) {
|
|
1156
|
-
ctx.stack.push(node.i);
|
|
1157
|
-
let serialized = `new AggregateError(${serializeTree(ctx, node.n)},${quote(node.m)})`;
|
|
1158
|
-
ctx.stack.pop();
|
|
1159
|
-
if (node.d) {
|
|
1160
|
-
if (ctx.features & 64 /* ObjectAssign */) {
|
|
1161
|
-
serialized = serializeWithObjectAssign(ctx, node.d, node.i, serialized);
|
|
1067
|
+
serializeNullConstructor(node) {
|
|
1068
|
+
let serialized = "Object.create(null)";
|
|
1069
|
+
if (this.ctx.features & 64 /* ObjectAssign */) {
|
|
1070
|
+
serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
|
|
1162
1071
|
} else {
|
|
1163
|
-
markRef(ctx, node.i);
|
|
1164
|
-
const assignments = serializeAssignments(
|
|
1072
|
+
markRef(this.ctx, node.i);
|
|
1073
|
+
const assignments = this.serializeAssignments(node.i, node.d);
|
|
1165
1074
|
if (assignments) {
|
|
1166
|
-
const ref = getRefParam(ctx, node.i);
|
|
1167
|
-
return `(${assignRef(
|
|
1075
|
+
const ref = getRefParam(this.ctx, node.i);
|
|
1076
|
+
return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
|
|
1168
1077
|
}
|
|
1169
1078
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1079
|
+
return this.assignRef(node.i, serialized);
|
|
1080
|
+
}
|
|
1081
|
+
serializeSet(node) {
|
|
1082
|
+
let serialized = "new Set";
|
|
1083
|
+
const size = node.a.length;
|
|
1084
|
+
if (size) {
|
|
1085
|
+
let result = "";
|
|
1086
|
+
this.ctx.stack.push(node.i);
|
|
1087
|
+
for (let i = 0; i < size; i++) {
|
|
1088
|
+
const item = node.a[i];
|
|
1089
|
+
if (this.isReferenceInStack(item)) {
|
|
1090
|
+
createSetAdd(this.ctx, node.i, getRefParam(this.ctx, item.i));
|
|
1091
|
+
} else {
|
|
1092
|
+
result += `${this.serialize(item)},`;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
this.ctx.stack.pop();
|
|
1096
|
+
if (result) {
|
|
1097
|
+
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return this.assignRef(node.i, serialized);
|
|
1101
|
+
}
|
|
1102
|
+
serializeMap(node) {
|
|
1103
|
+
let serialized = "new Map";
|
|
1104
|
+
if (node.d.s) {
|
|
1105
|
+
let result = "";
|
|
1106
|
+
this.ctx.stack.push(node.i);
|
|
1107
|
+
for (let i = 0; i < node.d.s; i++) {
|
|
1108
|
+
const key = node.d.k[i];
|
|
1109
|
+
const val = node.d.v[i];
|
|
1110
|
+
if (this.isReferenceInStack(key)) {
|
|
1111
|
+
const keyRef = getRefParam(this.ctx, key.i);
|
|
1112
|
+
if (this.isReferenceInStack(val)) {
|
|
1113
|
+
const valueRef = getRefParam(this.ctx, val.i);
|
|
1114
|
+
createMapSet(this.ctx, node.i, keyRef, valueRef);
|
|
1115
|
+
} else {
|
|
1116
|
+
const parent = this.ctx.stack;
|
|
1117
|
+
this.ctx.stack = [];
|
|
1118
|
+
createMapSet(this.ctx, node.i, keyRef, this.serialize(val));
|
|
1119
|
+
this.ctx.stack = parent;
|
|
1120
|
+
}
|
|
1121
|
+
} else if (this.isReferenceInStack(val)) {
|
|
1122
|
+
const valueRef = getRefParam(this.ctx, val.i);
|
|
1123
|
+
const parent = this.ctx.stack;
|
|
1124
|
+
this.ctx.stack = [];
|
|
1125
|
+
createMapSet(this.ctx, node.i, this.serialize(key), valueRef);
|
|
1126
|
+
this.ctx.stack = parent;
|
|
1127
|
+
} else {
|
|
1128
|
+
result += `[${this.serialize(key)},${this.serialize(val)}],`;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
this.ctx.stack.pop();
|
|
1132
|
+
if (result) {
|
|
1133
|
+
serialized += `([${result.substring(0, result.length - 1)}])`;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return this.assignRef(node.i, serialized);
|
|
1137
|
+
}
|
|
1138
|
+
serializeAggregateError(node) {
|
|
1139
|
+
this.ctx.stack.push(node.i);
|
|
1140
|
+
let serialized = `new AggregateError(${this.serialize(node.n)},${quote(node.m)})`;
|
|
1141
|
+
this.ctx.stack.pop();
|
|
1142
|
+
if (node.d) {
|
|
1143
|
+
if (this.ctx.features & 64 /* ObjectAssign */) {
|
|
1144
|
+
serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
|
|
1145
|
+
} else {
|
|
1146
|
+
markRef(this.ctx, node.i);
|
|
1147
|
+
const assignments = this.serializeAssignments(node.i, node.d);
|
|
1148
|
+
if (assignments) {
|
|
1149
|
+
const ref = getRefParam(this.ctx, node.i);
|
|
1150
|
+
return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
|
|
1151
|
+
}
|
|
1184
1152
|
}
|
|
1185
1153
|
}
|
|
1154
|
+
return this.assignRef(node.i, serialized);
|
|
1186
1155
|
}
|
|
1187
|
-
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1156
|
+
serializeError(node) {
|
|
1157
|
+
let serialized = `new ${node.c}(${quote(node.m)})`;
|
|
1158
|
+
if (node.d) {
|
|
1159
|
+
if (this.ctx.features & 64 /* ObjectAssign */) {
|
|
1160
|
+
serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
|
|
1161
|
+
} else {
|
|
1162
|
+
markRef(this.ctx, node.i);
|
|
1163
|
+
const assignments = this.serializeAssignments(node.i, node.d);
|
|
1164
|
+
if (assignments) {
|
|
1165
|
+
const ref = getRefParam(this.ctx, node.i);
|
|
1166
|
+
return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
return this.assignRef(node.i, serialized);
|
|
1199
1171
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1172
|
+
serializePromise(node) {
|
|
1173
|
+
let serialized;
|
|
1174
|
+
if (this.isReferenceInStack(node.n)) {
|
|
1175
|
+
serialized = `Promise.resolve().then(()=>${getRefParam(this.ctx, node.n.i)})`;
|
|
1176
|
+
} else {
|
|
1177
|
+
this.ctx.stack.push(node.i);
|
|
1178
|
+
const result = this.serialize(node.n);
|
|
1179
|
+
this.ctx.stack.pop();
|
|
1180
|
+
serialized = `Promise.resolve(${result})`;
|
|
1181
|
+
}
|
|
1182
|
+
return this.assignRef(node.i, serialized);
|
|
1206
1183
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1184
|
+
serializeTypedArray(node) {
|
|
1185
|
+
let args = `[${node.s}]`;
|
|
1186
|
+
if (node.l !== 0) {
|
|
1187
|
+
args += `,${node.l}`;
|
|
1188
|
+
}
|
|
1189
|
+
return this.assignRef(node.i, `new ${node.c}(${args})`);
|
|
1190
|
+
}
|
|
1191
|
+
serializeIterable(node) {
|
|
1192
|
+
const parent = this.ctx.stack;
|
|
1193
|
+
this.ctx.stack = [];
|
|
1194
|
+
const values = this.serializeNodeList(node);
|
|
1195
|
+
this.ctx.stack = parent;
|
|
1196
|
+
let serialized;
|
|
1197
|
+
if (this.ctx.features & 2 /* ArrayPrototypeValues */) {
|
|
1198
|
+
serialized = `${values}.values()`;
|
|
1210
1199
|
} else {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1200
|
+
serialized = `${values}[Symbol.iterator]()`;
|
|
1201
|
+
}
|
|
1202
|
+
if (this.ctx.features & 4 /* ArrowFunction */) {
|
|
1203
|
+
serialized = `{[Symbol.iterator]:()=>${serialized}}`;
|
|
1204
|
+
} else if (this.ctx.features & 32 /* MethodShorthand */) {
|
|
1205
|
+
serialized = `{[Symbol.iterator](){return ${serialized}}}`;
|
|
1206
|
+
} else {
|
|
1207
|
+
serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
|
|
1208
|
+
}
|
|
1209
|
+
if (node.d) {
|
|
1210
|
+
if (this.ctx.features & 64 /* ObjectAssign */) {
|
|
1211
|
+
serialized = this.serializeWithObjectAssign(node.d, node.i, serialized);
|
|
1212
|
+
} else {
|
|
1213
|
+
markRef(this.ctx, node.i);
|
|
1214
|
+
const assignments = this.serializeAssignments(node.i, node.d);
|
|
1215
|
+
if (assignments) {
|
|
1216
|
+
const ref = getRefParam(this.ctx, node.i);
|
|
1217
|
+
return `(${this.assignRef(node.i, serialized)},${assignments}${ref})`;
|
|
1218
|
+
}
|
|
1216
1219
|
}
|
|
1217
1220
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1221
|
+
return this.assignRef(node.i, serialized);
|
|
1222
|
+
}
|
|
1223
|
+
serialize(node) {
|
|
1224
|
+
switch (node.t) {
|
|
1225
|
+
case 0 /* Primitive */:
|
|
1226
|
+
return String(node.s);
|
|
1227
|
+
case 1 /* BigInt */:
|
|
1228
|
+
return node.s;
|
|
1229
|
+
case 2 /* Reference */:
|
|
1230
|
+
return getRefParam(this.ctx, node.i);
|
|
1231
|
+
case 7 /* Array */:
|
|
1232
|
+
return this.serializeArray(node);
|
|
1233
|
+
case 8 /* Object */:
|
|
1234
|
+
return this.assignRef(node.i, this.serializeObject(node.i, node.d));
|
|
1235
|
+
case 9 /* NullConstructor */:
|
|
1236
|
+
return this.serializeNullConstructor(node);
|
|
1237
|
+
case 3 /* Date */:
|
|
1238
|
+
return this.assignRef(node.i, `new Date("${node.s}")`);
|
|
1239
|
+
case 4 /* RegExp */:
|
|
1240
|
+
return this.assignRef(node.i, node.s);
|
|
1241
|
+
case 5 /* Set */:
|
|
1242
|
+
return this.serializeSet(node);
|
|
1243
|
+
case 6 /* Map */:
|
|
1244
|
+
return this.serializeMap(node);
|
|
1245
|
+
case 15 /* BigIntTypedArray */:
|
|
1246
|
+
case 14 /* TypedArray */:
|
|
1247
|
+
return this.serializeTypedArray(node);
|
|
1248
|
+
case 12 /* AggregateError */:
|
|
1249
|
+
return this.serializeAggregateError(node);
|
|
1250
|
+
case 11 /* Error */:
|
|
1251
|
+
return this.serializeError(node);
|
|
1252
|
+
case 13 /* Iterable */:
|
|
1253
|
+
return this.serializeIterable(node);
|
|
1254
|
+
case 10 /* Promise */:
|
|
1255
|
+
return this.serializePromise(node);
|
|
1256
|
+
default:
|
|
1257
|
+
throw new Error("Unsupported type");
|
|
1231
1258
|
}
|
|
1232
1259
|
}
|
|
1233
|
-
|
|
1234
|
-
}
|
|
1235
|
-
function serializeTree(ctx, node) {
|
|
1236
|
-
switch (node.t) {
|
|
1237
|
-
case 0 /* Primitive */:
|
|
1238
|
-
return String(node.s);
|
|
1239
|
-
case 2 /* Reference */:
|
|
1240
|
-
return getRefParam(ctx, node.i);
|
|
1241
|
-
case 10 /* Promise */:
|
|
1242
|
-
return serializePromise(ctx, node);
|
|
1243
|
-
case 1 /* BigInt */:
|
|
1244
|
-
return node.s;
|
|
1245
|
-
case 3 /* Date */:
|
|
1246
|
-
return assignRef(ctx, node.i, `new Date("${node.s}")`);
|
|
1247
|
-
case 4 /* RegExp */:
|
|
1248
|
-
return assignRef(ctx, node.i, node.s);
|
|
1249
|
-
case 15 /* BigIntTypedArray */:
|
|
1250
|
-
case 14 /* TypedArray */:
|
|
1251
|
-
return serializeTypedArray(ctx, node);
|
|
1252
|
-
case 5 /* Set */:
|
|
1253
|
-
return serializeSet(ctx, node);
|
|
1254
|
-
case 6 /* Map */:
|
|
1255
|
-
return serializeMap(ctx, node);
|
|
1256
|
-
case 7 /* Array */:
|
|
1257
|
-
return serializeArray(ctx, node);
|
|
1258
|
-
case 12 /* AggregateError */:
|
|
1259
|
-
return serializeAggregateError(ctx, node);
|
|
1260
|
-
case 11 /* Error */:
|
|
1261
|
-
return serializeError(ctx, node);
|
|
1262
|
-
case 13 /* Iterable */:
|
|
1263
|
-
return serializeIterable(ctx, node);
|
|
1264
|
-
case 9 /* NullConstructor */:
|
|
1265
|
-
return serializeNullConstructor(ctx, node);
|
|
1266
|
-
case 8 /* Object */:
|
|
1267
|
-
return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
|
|
1268
|
-
default:
|
|
1269
|
-
throw new Error("Unsupported type");
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1260
|
+
};
|
|
1272
1261
|
|
|
1273
1262
|
// src/tree/sync.ts
|
|
1274
1263
|
var SyncParser = class {
|
|
@@ -1299,7 +1288,17 @@ var SyncParser = class {
|
|
|
1299
1288
|
return nodes;
|
|
1300
1289
|
}
|
|
1301
1290
|
generateArrayNode(id, current) {
|
|
1302
|
-
return
|
|
1291
|
+
return {
|
|
1292
|
+
t: 7 /* Array */,
|
|
1293
|
+
i: id,
|
|
1294
|
+
s: void 0,
|
|
1295
|
+
l: void 0,
|
|
1296
|
+
c: void 0,
|
|
1297
|
+
m: void 0,
|
|
1298
|
+
d: void 0,
|
|
1299
|
+
a: this.generateNodeList(current),
|
|
1300
|
+
n: void 0
|
|
1301
|
+
};
|
|
1303
1302
|
}
|
|
1304
1303
|
generateMapNode(id, current) {
|
|
1305
1304
|
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -1325,7 +1324,17 @@ var SyncParser = class {
|
|
|
1325
1324
|
keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
|
|
1326
1325
|
valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
|
|
1327
1326
|
}
|
|
1328
|
-
return
|
|
1327
|
+
return {
|
|
1328
|
+
t: 6 /* Map */,
|
|
1329
|
+
i: id,
|
|
1330
|
+
s: void 0,
|
|
1331
|
+
l: void 0,
|
|
1332
|
+
c: void 0,
|
|
1333
|
+
m: void 0,
|
|
1334
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1335
|
+
a: void 0,
|
|
1336
|
+
n: void 0
|
|
1337
|
+
};
|
|
1329
1338
|
}
|
|
1330
1339
|
generateSetNode(id, current) {
|
|
1331
1340
|
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -1344,7 +1353,17 @@ var SyncParser = class {
|
|
|
1344
1353
|
for (let i = 0; i < deferredSize; i++) {
|
|
1345
1354
|
nodes[nodeSize + i] = this.parse(deferred[i]);
|
|
1346
1355
|
}
|
|
1347
|
-
return
|
|
1356
|
+
return {
|
|
1357
|
+
t: 5 /* Set */,
|
|
1358
|
+
i: id,
|
|
1359
|
+
s: void 0,
|
|
1360
|
+
l: void 0,
|
|
1361
|
+
c: void 0,
|
|
1362
|
+
m: void 0,
|
|
1363
|
+
d: void 0,
|
|
1364
|
+
a: nodes,
|
|
1365
|
+
n: void 0
|
|
1366
|
+
};
|
|
1348
1367
|
}
|
|
1349
1368
|
generateProperties(properties) {
|
|
1350
1369
|
const keys = Object.keys(properties);
|
|
@@ -1381,36 +1400,64 @@ var SyncParser = class {
|
|
|
1381
1400
|
generateIterableNode(id, current) {
|
|
1382
1401
|
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1383
1402
|
const options = getIterableOptions(current);
|
|
1384
|
-
return
|
|
1385
|
-
|
|
1403
|
+
return {
|
|
1404
|
+
t: 13 /* Iterable */,
|
|
1405
|
+
i: id,
|
|
1406
|
+
s: void 0,
|
|
1407
|
+
l: void 0,
|
|
1408
|
+
c: void 0,
|
|
1409
|
+
m: void 0,
|
|
1386
1410
|
// Parse options first before the items
|
|
1387
|
-
options ? this.generateProperties(options) : void 0,
|
|
1388
|
-
this.generateNodeList(Array.from(current))
|
|
1389
|
-
|
|
1411
|
+
d: options ? this.generateProperties(options) : void 0,
|
|
1412
|
+
a: this.generateNodeList(Array.from(current)),
|
|
1413
|
+
n: void 0
|
|
1414
|
+
};
|
|
1390
1415
|
}
|
|
1391
1416
|
generateObjectNode(id, current, empty) {
|
|
1392
1417
|
if (Symbol.iterator in current) {
|
|
1393
1418
|
return this.generateIterableNode(id, current);
|
|
1394
1419
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1420
|
+
return {
|
|
1421
|
+
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
1422
|
+
i: id,
|
|
1423
|
+
s: void 0,
|
|
1424
|
+
l: void 0,
|
|
1425
|
+
c: void 0,
|
|
1426
|
+
m: void 0,
|
|
1427
|
+
d: this.generateProperties(current),
|
|
1428
|
+
a: void 0,
|
|
1429
|
+
n: void 0
|
|
1430
|
+
};
|
|
1399
1431
|
}
|
|
1400
1432
|
generateAggregateErrorNode(id, current) {
|
|
1401
1433
|
const options = getErrorOptions(current);
|
|
1402
1434
|
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1403
|
-
return
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1435
|
+
return {
|
|
1436
|
+
t: 12 /* AggregateError */,
|
|
1437
|
+
i: id,
|
|
1438
|
+
s: void 0,
|
|
1439
|
+
l: void 0,
|
|
1440
|
+
c: void 0,
|
|
1441
|
+
m: current.message,
|
|
1442
|
+
d: optionsNode,
|
|
1443
|
+
a: void 0,
|
|
1444
|
+
n: this.parse(current.errors)
|
|
1445
|
+
};
|
|
1409
1446
|
}
|
|
1410
1447
|
generateErrorNode(id, current) {
|
|
1411
1448
|
const options = getErrorOptions(current);
|
|
1412
1449
|
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1413
|
-
return
|
|
1450
|
+
return {
|
|
1451
|
+
t: 11 /* Error */,
|
|
1452
|
+
i: id,
|
|
1453
|
+
s: void 0,
|
|
1454
|
+
l: void 0,
|
|
1455
|
+
c: getErrorConstructor(current),
|
|
1456
|
+
m: current.message,
|
|
1457
|
+
d: optionsNode,
|
|
1458
|
+
a: void 0,
|
|
1459
|
+
n: void 0
|
|
1460
|
+
};
|
|
1414
1461
|
}
|
|
1415
1462
|
parse(current) {
|
|
1416
1463
|
switch (typeof current) {
|
|
@@ -1419,37 +1466,36 @@ var SyncParser = class {
|
|
|
1419
1466
|
case "undefined":
|
|
1420
1467
|
return UNDEFINED_NODE;
|
|
1421
1468
|
case "string":
|
|
1422
|
-
return
|
|
1469
|
+
return createPrimitiveNode(quote(current));
|
|
1423
1470
|
case "number":
|
|
1424
1471
|
if (Object.is(current, -0)) {
|
|
1425
1472
|
return NEG_ZERO_NODE;
|
|
1426
1473
|
}
|
|
1427
1474
|
if (Object.is(current, Infinity)) {
|
|
1428
|
-
return
|
|
1475
|
+
return createPrimitiveNode("1/0");
|
|
1429
1476
|
}
|
|
1430
1477
|
if (Object.is(current, -Infinity)) {
|
|
1431
|
-
return
|
|
1478
|
+
return createPrimitiveNode("-1/0");
|
|
1432
1479
|
}
|
|
1433
|
-
return
|
|
1480
|
+
return createPrimitiveNode(current);
|
|
1434
1481
|
case "bigint":
|
|
1435
|
-
|
|
1436
|
-
return new SerovalBigIntNode(current);
|
|
1482
|
+
return createBigIntNode(this.ctx, current);
|
|
1437
1483
|
case "object": {
|
|
1438
1484
|
if (!current) {
|
|
1439
1485
|
return NULL_NODE;
|
|
1440
1486
|
}
|
|
1441
1487
|
const id = createRef(this.ctx, current, true);
|
|
1442
|
-
if (this.ctx.markedRefs
|
|
1443
|
-
return
|
|
1488
|
+
if (this.ctx.markedRefs.has(id)) {
|
|
1489
|
+
return createReferenceNode(id);
|
|
1444
1490
|
}
|
|
1445
1491
|
if (Array.isArray(current)) {
|
|
1446
1492
|
return this.generateArrayNode(id, current);
|
|
1447
1493
|
}
|
|
1448
1494
|
switch (current.constructor) {
|
|
1449
1495
|
case Date:
|
|
1450
|
-
return
|
|
1496
|
+
return createDateNode(id, current);
|
|
1451
1497
|
case RegExp:
|
|
1452
|
-
return
|
|
1498
|
+
return createRegExpNode(id, current);
|
|
1453
1499
|
case Int8Array:
|
|
1454
1500
|
case Int16Array:
|
|
1455
1501
|
case Int32Array:
|
|
@@ -1459,15 +1505,10 @@ var SyncParser = class {
|
|
|
1459
1505
|
case Uint8ClampedArray:
|
|
1460
1506
|
case Float32Array:
|
|
1461
1507
|
case Float64Array:
|
|
1462
|
-
|
|
1463
|
-
return new SerovalTypedArrayNode(id, current);
|
|
1508
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
1464
1509
|
case BigInt64Array:
|
|
1465
1510
|
case BigUint64Array:
|
|
1466
|
-
|
|
1467
|
-
this.ctx.features & 2048 /* BigIntTypedArray */,
|
|
1468
|
-
`Unsupported value type "${current.constructor.name}"`
|
|
1469
|
-
);
|
|
1470
|
-
return new SerovalBigIntTypedArrayNode(id, current);
|
|
1511
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
1471
1512
|
case Map:
|
|
1472
1513
|
return this.generateMapNode(id, current);
|
|
1473
1514
|
case Set:
|
|
@@ -1540,52 +1581,52 @@ function finalize(ctx, rootID, isObject, result) {
|
|
|
1540
1581
|
return result;
|
|
1541
1582
|
}
|
|
1542
1583
|
function serialize(source, options) {
|
|
1543
|
-
const ctx =
|
|
1584
|
+
const ctx = createParserContext(options);
|
|
1544
1585
|
const [tree, rootID, isObject] = parseSync(ctx, source);
|
|
1545
|
-
const serial =
|
|
1546
|
-
const result =
|
|
1586
|
+
const serial = createSerializationContext(ctx);
|
|
1587
|
+
const result = new SerovalSerializer(serial).serialize(tree);
|
|
1547
1588
|
return finalize(serial, rootID, isObject, result);
|
|
1548
1589
|
}
|
|
1549
1590
|
async function serializeAsync(source, options) {
|
|
1550
|
-
const ctx =
|
|
1591
|
+
const ctx = createParserContext(options);
|
|
1551
1592
|
const [tree, rootID, isObject] = await parseAsync(ctx, source);
|
|
1552
|
-
const serial =
|
|
1553
|
-
const result =
|
|
1593
|
+
const serial = createSerializationContext(ctx);
|
|
1594
|
+
const result = new SerovalSerializer(serial).serialize(tree);
|
|
1554
1595
|
return finalize(serial, rootID, isObject, result);
|
|
1555
1596
|
}
|
|
1556
1597
|
function deserialize(source) {
|
|
1557
1598
|
return (0, eval)(source);
|
|
1558
1599
|
}
|
|
1559
1600
|
function toJSON(source, options) {
|
|
1560
|
-
const ctx =
|
|
1601
|
+
const ctx = createParserContext(options);
|
|
1561
1602
|
const [tree, root, isObject] = parseSync(ctx, source);
|
|
1562
|
-
return JSON.stringify(
|
|
1563
|
-
tree,
|
|
1564
|
-
root,
|
|
1565
|
-
isObject,
|
|
1566
|
-
ctx.features,
|
|
1567
|
-
ctx.markedRefs
|
|
1568
|
-
|
|
1603
|
+
return JSON.stringify({
|
|
1604
|
+
t: tree,
|
|
1605
|
+
r: root,
|
|
1606
|
+
i: isObject,
|
|
1607
|
+
f: ctx.features,
|
|
1608
|
+
m: Array.from(ctx.markedRefs)
|
|
1609
|
+
});
|
|
1569
1610
|
}
|
|
1570
1611
|
async function toJSONAsync(source, options) {
|
|
1571
|
-
const ctx =
|
|
1612
|
+
const ctx = createParserContext(options);
|
|
1572
1613
|
const [tree, root, isObject] = await parseAsync(ctx, source);
|
|
1573
|
-
return JSON.stringify(
|
|
1574
|
-
tree,
|
|
1575
|
-
root,
|
|
1576
|
-
isObject,
|
|
1577
|
-
ctx.features,
|
|
1578
|
-
ctx.markedRefs
|
|
1579
|
-
|
|
1614
|
+
return JSON.stringify({
|
|
1615
|
+
t: tree,
|
|
1616
|
+
r: root,
|
|
1617
|
+
i: isObject,
|
|
1618
|
+
f: ctx.features,
|
|
1619
|
+
m: Array.from(ctx.markedRefs)
|
|
1620
|
+
});
|
|
1580
1621
|
}
|
|
1581
1622
|
function compileJSON(source) {
|
|
1582
1623
|
const parsed = JSON.parse(source);
|
|
1583
|
-
const serial =
|
|
1584
|
-
features: parsed
|
|
1585
|
-
markedRefs: parsed
|
|
1624
|
+
const serial = createSerializationContext({
|
|
1625
|
+
features: parsed.f,
|
|
1626
|
+
markedRefs: parsed.m
|
|
1586
1627
|
});
|
|
1587
|
-
const result =
|
|
1588
|
-
return finalize(serial, parsed
|
|
1628
|
+
const result = new SerovalSerializer(serial).serialize(parsed.t);
|
|
1629
|
+
return finalize(serial, parsed.r, parsed.i, result);
|
|
1589
1630
|
}
|
|
1590
1631
|
function fromJSON(source) {
|
|
1591
1632
|
return deserialize(compileJSON(source));
|