seroval 0.4.0-alpha.10 → 0.4.0-alpha.12
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 +641 -558
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +642 -557
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/tree/primitives.d.ts +17 -0
- package/dist/types/tree/shared.d.ts +3 -4
- package/dist/types/types.d.ts +3 -2
- package/package.json +2 -2
- package/src/index.ts +0 -8
- package/src/tree/async.ts +347 -276
- package/src/tree/primitives.ts +147 -0
- package/src/tree/shared.ts +23 -110
- package/src/tree/sync.ts +303 -265
- package/src/types.ts +4 -1
- package/dist/types/checks.d.ts +0 -4
- package/src/checks.ts +0 -37
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => {
|
|
21
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
// src/index.ts
|
|
21
26
|
var src_exports = {};
|
|
@@ -31,28 +36,6 @@ __export(src_exports, {
|
|
|
31
36
|
});
|
|
32
37
|
module.exports = __toCommonJS(src_exports);
|
|
33
38
|
|
|
34
|
-
// src/checks.ts
|
|
35
|
-
function isPrimitive(current) {
|
|
36
|
-
if (!current || current === true) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
const type = typeof current;
|
|
40
|
-
return type === "number" || type === "string";
|
|
41
|
-
}
|
|
42
|
-
function isPromise(obj) {
|
|
43
|
-
return !!obj && (typeof obj === "object" || typeof obj === "function") && "then" in obj && typeof obj.then === "function";
|
|
44
|
-
}
|
|
45
|
-
function isIterableBuiltin(obj) {
|
|
46
|
-
if (!!obj && typeof obj === "object") {
|
|
47
|
-
const cons = obj.constructor;
|
|
48
|
-
return Array.isArray(obj) || cons === Set || cons === Map;
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
function isIterable(obj) {
|
|
53
|
-
return !!obj && typeof obj === "object" && !isIterableBuiltin(obj) && Symbol.iterator in obj && typeof obj[Symbol.iterator] === "function";
|
|
54
|
-
}
|
|
55
|
-
|
|
56
39
|
// src/compat.ts
|
|
57
40
|
function compareVersion(left, right) {
|
|
58
41
|
let diff = left[0] - right[0];
|
|
@@ -399,6 +382,120 @@ function quote(str) {
|
|
|
399
382
|
return `"${result}"`;
|
|
400
383
|
}
|
|
401
384
|
|
|
385
|
+
// src/tree/primitives.ts
|
|
386
|
+
function createPrimitiveNode(value) {
|
|
387
|
+
return {
|
|
388
|
+
t: 0 /* Primitive */,
|
|
389
|
+
i: void 0,
|
|
390
|
+
s: value,
|
|
391
|
+
l: void 0,
|
|
392
|
+
m: void 0,
|
|
393
|
+
c: void 0,
|
|
394
|
+
d: void 0,
|
|
395
|
+
a: void 0,
|
|
396
|
+
n: void 0
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
var TRUE_NODE = createPrimitiveNode("!0");
|
|
400
|
+
var FALSE_NODE = createPrimitiveNode("!1");
|
|
401
|
+
var UNDEFINED_NODE = createPrimitiveNode("void 0");
|
|
402
|
+
var NULL_NODE = createPrimitiveNode(null);
|
|
403
|
+
var NEG_ZERO_NODE = createPrimitiveNode("-0");
|
|
404
|
+
var INFINITY_NODE = createPrimitiveNode("1/0");
|
|
405
|
+
var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
|
|
406
|
+
function createBigIntNode(ctx, current) {
|
|
407
|
+
assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
408
|
+
return {
|
|
409
|
+
t: 1 /* BigInt */,
|
|
410
|
+
i: void 0,
|
|
411
|
+
a: void 0,
|
|
412
|
+
s: `${current}n`,
|
|
413
|
+
l: void 0,
|
|
414
|
+
m: void 0,
|
|
415
|
+
c: void 0,
|
|
416
|
+
d: void 0,
|
|
417
|
+
n: void 0
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function createReferenceNode(id) {
|
|
421
|
+
return {
|
|
422
|
+
t: 2 /* Reference */,
|
|
423
|
+
i: id,
|
|
424
|
+
a: void 0,
|
|
425
|
+
s: void 0,
|
|
426
|
+
l: void 0,
|
|
427
|
+
m: void 0,
|
|
428
|
+
c: void 0,
|
|
429
|
+
d: void 0,
|
|
430
|
+
n: void 0
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function createDateNode(id, current) {
|
|
434
|
+
return {
|
|
435
|
+
t: 3 /* Date */,
|
|
436
|
+
i: id,
|
|
437
|
+
a: void 0,
|
|
438
|
+
s: current.toISOString(),
|
|
439
|
+
l: void 0,
|
|
440
|
+
m: void 0,
|
|
441
|
+
c: void 0,
|
|
442
|
+
d: void 0,
|
|
443
|
+
n: void 0
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function createRegExpNode(id, current) {
|
|
447
|
+
return {
|
|
448
|
+
t: 4 /* RegExp */,
|
|
449
|
+
i: id,
|
|
450
|
+
a: void 0,
|
|
451
|
+
s: String(current),
|
|
452
|
+
l: void 0,
|
|
453
|
+
m: void 0,
|
|
454
|
+
c: void 0,
|
|
455
|
+
d: void 0,
|
|
456
|
+
n: void 0
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function createTypedArrayNode(ctx, id, current) {
|
|
460
|
+
const constructor = current.constructor.name;
|
|
461
|
+
assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
462
|
+
return {
|
|
463
|
+
t: 14 /* TypedArray */,
|
|
464
|
+
i: id,
|
|
465
|
+
a: void 0,
|
|
466
|
+
s: current.toString(),
|
|
467
|
+
l: current.byteOffset,
|
|
468
|
+
m: void 0,
|
|
469
|
+
c: constructor,
|
|
470
|
+
d: void 0,
|
|
471
|
+
n: void 0
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function createBigIntTypedArrayNode(ctx, id, current) {
|
|
475
|
+
const constructor = current.constructor.name;
|
|
476
|
+
assert(
|
|
477
|
+
ctx.features & 2048 /* BigIntTypedArray */,
|
|
478
|
+
`Unsupported value type "${constructor}"`
|
|
479
|
+
);
|
|
480
|
+
let result = "";
|
|
481
|
+
const cap = current.length - 1;
|
|
482
|
+
for (let i = 0; i < cap; i++) {
|
|
483
|
+
result += `${current[i]}n,`;
|
|
484
|
+
}
|
|
485
|
+
result += `"${current[cap]}"`;
|
|
486
|
+
return {
|
|
487
|
+
t: 15 /* BigIntTypedArray */,
|
|
488
|
+
i: id,
|
|
489
|
+
a: void 0,
|
|
490
|
+
s: result,
|
|
491
|
+
l: current.byteOffset,
|
|
492
|
+
m: void 0,
|
|
493
|
+
c: constructor,
|
|
494
|
+
d: void 0,
|
|
495
|
+
n: void 0
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
402
499
|
// src/tree/shared.ts
|
|
403
500
|
function getErrorConstructor(error) {
|
|
404
501
|
if (error instanceof EvalError) {
|
|
@@ -452,33 +549,16 @@ function getIterableOptions(obj) {
|
|
|
452
549
|
function isReferenceInStack(ctx, node) {
|
|
453
550
|
return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
|
|
454
551
|
}
|
|
455
|
-
function
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
m: void 0,
|
|
466
|
-
c: void 0,
|
|
467
|
-
d: void 0,
|
|
468
|
-
n: void 0
|
|
469
|
-
};
|
|
470
|
-
case RegExp:
|
|
471
|
-
return {
|
|
472
|
-
t: 4 /* RegExp */,
|
|
473
|
-
i: id,
|
|
474
|
-
a: void 0,
|
|
475
|
-
s: String(current),
|
|
476
|
-
l: void 0,
|
|
477
|
-
m: void 0,
|
|
478
|
-
c: void 0,
|
|
479
|
-
d: void 0,
|
|
480
|
-
n: void 0
|
|
481
|
-
};
|
|
552
|
+
function isIterable(value) {
|
|
553
|
+
if (!value || typeof value !== "object") {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
if (Array.isArray(value)) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
switch (value.constructor) {
|
|
560
|
+
case Map:
|
|
561
|
+
case Set:
|
|
482
562
|
case Int8Array:
|
|
483
563
|
case Int16Array:
|
|
484
564
|
case Int32Array:
|
|
@@ -487,288 +567,114 @@ function generateSemiPrimitiveValue(ctx, current, id) {
|
|
|
487
567
|
case Uint32Array:
|
|
488
568
|
case Uint8ClampedArray:
|
|
489
569
|
case Float32Array:
|
|
490
|
-
case Float64Array:
|
|
491
|
-
const constructor = cs.name;
|
|
492
|
-
assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
493
|
-
return {
|
|
494
|
-
t: 14 /* TypedArray */,
|
|
495
|
-
i: id,
|
|
496
|
-
a: void 0,
|
|
497
|
-
s: current.toString(),
|
|
498
|
-
l: current.byteOffset,
|
|
499
|
-
m: void 0,
|
|
500
|
-
c: constructor,
|
|
501
|
-
d: void 0,
|
|
502
|
-
n: void 0
|
|
503
|
-
};
|
|
504
|
-
}
|
|
570
|
+
case Float64Array:
|
|
505
571
|
case BigInt64Array:
|
|
506
|
-
case BigUint64Array:
|
|
507
|
-
|
|
508
|
-
assert(
|
|
509
|
-
ctx.features & 2048 /* BigIntTypedArray */,
|
|
510
|
-
`Unsupported value type "${constructor}"`
|
|
511
|
-
);
|
|
512
|
-
let result = "";
|
|
513
|
-
const cap = current.length - 1;
|
|
514
|
-
for (let i = 0; i < cap; i++) {
|
|
515
|
-
result += `${current[i]}n,`;
|
|
516
|
-
}
|
|
517
|
-
result += `"${current[cap]}"`;
|
|
518
|
-
return {
|
|
519
|
-
t: 14 /* TypedArray */,
|
|
520
|
-
i: id,
|
|
521
|
-
a: void 0,
|
|
522
|
-
s: result,
|
|
523
|
-
l: current.byteOffset,
|
|
524
|
-
m: void 0,
|
|
525
|
-
c: constructor,
|
|
526
|
-
d: void 0,
|
|
527
|
-
n: void 0
|
|
528
|
-
};
|
|
529
|
-
}
|
|
572
|
+
case BigUint64Array:
|
|
573
|
+
return false;
|
|
530
574
|
default:
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
function serializePrimitive(value) {
|
|
535
|
-
if (value === true) {
|
|
536
|
-
return "!0";
|
|
537
|
-
}
|
|
538
|
-
if (value === false) {
|
|
539
|
-
return "!1";
|
|
540
|
-
}
|
|
541
|
-
if (value === void 0) {
|
|
542
|
-
return "void 0";
|
|
543
|
-
}
|
|
544
|
-
if (value === null) {
|
|
545
|
-
return null;
|
|
575
|
+
break;
|
|
546
576
|
}
|
|
547
|
-
|
|
548
|
-
return quote(value);
|
|
549
|
-
}
|
|
550
|
-
if (Object.is(value, -0)) {
|
|
551
|
-
return "-0";
|
|
552
|
-
}
|
|
553
|
-
if (Object.is(value, Infinity)) {
|
|
554
|
-
return "1/0";
|
|
555
|
-
}
|
|
556
|
-
if (Object.is(value, -Infinity)) {
|
|
557
|
-
return "-1/0";
|
|
558
|
-
}
|
|
559
|
-
return value;
|
|
577
|
+
return Symbol.iterator in value;
|
|
560
578
|
}
|
|
561
579
|
|
|
562
580
|
// src/tree/async.ts
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
584
|
-
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
585
|
-
valueNodes[nodesSize + i] = await generateTreeAsync(ctx, deferredValues[i]);
|
|
586
|
-
}
|
|
587
|
-
return {
|
|
588
|
-
k: keyNodes,
|
|
589
|
-
v: valueNodes,
|
|
590
|
-
s: size
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
async function generateSetNode(ctx, current, id) {
|
|
594
|
-
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
595
|
-
const len = current.size;
|
|
596
|
-
const nodes = new Array(len);
|
|
597
|
-
const deferred = new Array(len);
|
|
598
|
-
let deferredSize = 0;
|
|
599
|
-
let nodeSize = 0;
|
|
600
|
-
for (const item of current.keys()) {
|
|
601
|
-
if (isIterable(item)) {
|
|
602
|
-
deferred[deferredSize++] = item;
|
|
603
|
-
} else {
|
|
604
|
-
nodes[nodeSize++] = await generateTreeAsync(ctx, item);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
608
|
-
nodes[nodeSize + i] = await generateTreeAsync(ctx, deferred[i]);
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
t: 5 /* Set */,
|
|
612
|
-
i: id,
|
|
613
|
-
a: nodes,
|
|
614
|
-
s: void 0,
|
|
615
|
-
l: void 0,
|
|
616
|
-
m: void 0,
|
|
617
|
-
c: void 0,
|
|
618
|
-
d: void 0,
|
|
619
|
-
n: void 0
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
async function generateMapNode(ctx, current, id) {
|
|
623
|
-
assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
624
|
-
const len = current.size;
|
|
625
|
-
const keyNodes = new Array(len);
|
|
626
|
-
const valueNodes = new Array(len);
|
|
627
|
-
const deferredKey = new Array(len);
|
|
628
|
-
const deferredValue = new Array(len);
|
|
629
|
-
let deferredSize = 0;
|
|
630
|
-
let nodeSize = 0;
|
|
631
|
-
for (const [key, value] of current.entries()) {
|
|
632
|
-
if (isIterable(key) || isIterable(value)) {
|
|
633
|
-
deferredKey[deferredSize] = key;
|
|
634
|
-
deferredValue[deferredSize] = value;
|
|
635
|
-
deferredSize++;
|
|
636
|
-
} else {
|
|
637
|
-
keyNodes[nodeSize] = await generateTreeAsync(ctx, key);
|
|
638
|
-
valueNodes[nodeSize] = await generateTreeAsync(ctx, value);
|
|
639
|
-
nodeSize++;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
643
|
-
keyNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredKey[i]);
|
|
644
|
-
valueNodes[nodeSize + i] = await generateTreeAsync(ctx, deferredValue[i]);
|
|
645
|
-
}
|
|
646
|
-
return {
|
|
647
|
-
t: 6 /* Map */,
|
|
648
|
-
i: id,
|
|
649
|
-
a: void 0,
|
|
650
|
-
s: void 0,
|
|
651
|
-
l: void 0,
|
|
652
|
-
m: void 0,
|
|
653
|
-
c: void 0,
|
|
654
|
-
d: { k: keyNodes, v: valueNodes, s: len },
|
|
655
|
-
n: void 0
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
async function generateNodeList(ctx, current) {
|
|
659
|
-
const size = current.length;
|
|
660
|
-
const nodes = new Array(size);
|
|
661
|
-
const deferred = new Array(size);
|
|
662
|
-
for (let i = 0; i < size; i++) {
|
|
663
|
-
if (i in current) {
|
|
664
|
-
if (isIterable(current[i])) {
|
|
665
|
-
deferred[i] = current[i];
|
|
666
|
-
} else {
|
|
667
|
-
nodes[i] = await generateTreeAsync(ctx, current[i]);
|
|
581
|
+
var AsyncParser = class {
|
|
582
|
+
constructor(ctx) {
|
|
583
|
+
__publicField(this, "ctx");
|
|
584
|
+
this.ctx = ctx;
|
|
585
|
+
}
|
|
586
|
+
async generateNodeList(current) {
|
|
587
|
+
const size = current.length;
|
|
588
|
+
const nodes = new Array(size);
|
|
589
|
+
const deferred = new Array(size);
|
|
590
|
+
let item;
|
|
591
|
+
for (let i = 0; i < size; i++) {
|
|
592
|
+
if (i in current) {
|
|
593
|
+
item = current[i];
|
|
594
|
+
if (isIterable(item)) {
|
|
595
|
+
deferred[i] = item;
|
|
596
|
+
} else {
|
|
597
|
+
nodes[i] = await this.parse(item);
|
|
598
|
+
}
|
|
668
599
|
}
|
|
669
600
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
601
|
+
for (let i = 0; i < size; i++) {
|
|
602
|
+
if (i in deferred) {
|
|
603
|
+
nodes[i] = await this.parse(deferred[i]);
|
|
604
|
+
}
|
|
674
605
|
}
|
|
606
|
+
return nodes;
|
|
675
607
|
}
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
async function generateArrayNode(ctx, current, id) {
|
|
679
|
-
return {
|
|
680
|
-
t: 7 /* Array */,
|
|
681
|
-
i: id,
|
|
682
|
-
a: await generateNodeList(ctx, current),
|
|
683
|
-
s: void 0,
|
|
684
|
-
l: void 0,
|
|
685
|
-
m: void 0,
|
|
686
|
-
c: void 0,
|
|
687
|
-
d: void 0,
|
|
688
|
-
n: void 0
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
async function generateAggregateErrorNode(ctx, current, id) {
|
|
692
|
-
const options = getErrorOptions(current);
|
|
693
|
-
const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
|
|
694
|
-
return {
|
|
695
|
-
t: 12 /* AggregateError */,
|
|
696
|
-
i: id,
|
|
697
|
-
a: void 0,
|
|
698
|
-
s: void 0,
|
|
699
|
-
l: void 0,
|
|
700
|
-
m: current.message,
|
|
701
|
-
c: void 0,
|
|
702
|
-
d: optionsNode,
|
|
703
|
-
n: await generateTreeAsync(ctx, current.errors)
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
async function generateErrorNode(ctx, current, id) {
|
|
707
|
-
const options = getErrorOptions(current);
|
|
708
|
-
const optionsNode = options ? await serializePropertiesAsync(ctx, options) : void 0;
|
|
709
|
-
return {
|
|
710
|
-
t: 11 /* Error */,
|
|
711
|
-
i: id,
|
|
712
|
-
a: void 0,
|
|
713
|
-
s: void 0,
|
|
714
|
-
l: void 0,
|
|
715
|
-
m: current.message,
|
|
716
|
-
c: getErrorConstructor(current),
|
|
717
|
-
d: optionsNode,
|
|
718
|
-
n: void 0
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
async function generateIterableNode(ctx, current, id) {
|
|
722
|
-
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
723
|
-
const options = getIterableOptions(current);
|
|
724
|
-
return {
|
|
725
|
-
t: 13 /* Iterable */,
|
|
726
|
-
i: id,
|
|
727
|
-
s: void 0,
|
|
728
|
-
l: void 0,
|
|
729
|
-
m: void 0,
|
|
730
|
-
c: void 0,
|
|
731
|
-
// Parse options first before the items
|
|
732
|
-
d: options ? await serializePropertiesAsync(ctx, options) : void 0,
|
|
733
|
-
a: await generateNodeList(ctx, Array.from(current)),
|
|
734
|
-
n: void 0
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
async function generateTreeAsync(ctx, current) {
|
|
738
|
-
if (isPrimitive(current)) {
|
|
608
|
+
async generateArrayNode(id, current) {
|
|
739
609
|
return {
|
|
740
|
-
t:
|
|
741
|
-
i:
|
|
742
|
-
|
|
610
|
+
t: 7 /* Array */,
|
|
611
|
+
i: id,
|
|
612
|
+
a: await this.generateNodeList(current),
|
|
613
|
+
s: void 0,
|
|
743
614
|
l: void 0,
|
|
744
615
|
m: void 0,
|
|
745
616
|
c: void 0,
|
|
746
|
-
// Parse options first before the items
|
|
747
617
|
d: void 0,
|
|
748
|
-
a: void 0,
|
|
749
618
|
n: void 0
|
|
750
619
|
};
|
|
751
620
|
}
|
|
752
|
-
|
|
753
|
-
assert(ctx.features &
|
|
621
|
+
async generateMapNode(id, current) {
|
|
622
|
+
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
623
|
+
const len = current.size;
|
|
624
|
+
const keyNodes = new Array(len);
|
|
625
|
+
const valueNodes = new Array(len);
|
|
626
|
+
const deferredKey = new Array(len);
|
|
627
|
+
const deferredValue = new Array(len);
|
|
628
|
+
let deferredSize = 0;
|
|
629
|
+
let nodeSize = 0;
|
|
630
|
+
for (const [key, value] of current.entries()) {
|
|
631
|
+
if (isIterable(key) || isIterable(value)) {
|
|
632
|
+
deferredKey[deferredSize] = key;
|
|
633
|
+
deferredValue[deferredSize] = value;
|
|
634
|
+
deferredSize++;
|
|
635
|
+
} else {
|
|
636
|
+
keyNodes[nodeSize] = await this.parse(key);
|
|
637
|
+
valueNodes[nodeSize] = await this.parse(value);
|
|
638
|
+
nodeSize++;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
642
|
+
keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
|
|
643
|
+
valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
|
|
644
|
+
}
|
|
754
645
|
return {
|
|
755
|
-
t:
|
|
756
|
-
i:
|
|
646
|
+
t: 6 /* Map */,
|
|
647
|
+
i: id,
|
|
757
648
|
a: void 0,
|
|
758
|
-
s:
|
|
649
|
+
s: void 0,
|
|
759
650
|
l: void 0,
|
|
760
651
|
m: void 0,
|
|
761
652
|
c: void 0,
|
|
762
|
-
d:
|
|
653
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
763
654
|
n: void 0
|
|
764
655
|
};
|
|
765
656
|
}
|
|
766
|
-
|
|
767
|
-
|
|
657
|
+
async generateSetNode(id, current) {
|
|
658
|
+
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
659
|
+
const len = current.size;
|
|
660
|
+
const nodes = new Array(len);
|
|
661
|
+
const deferred = new Array(len);
|
|
662
|
+
let deferredSize = 0;
|
|
663
|
+
let nodeSize = 0;
|
|
664
|
+
for (const item of current.keys()) {
|
|
665
|
+
if (isIterable(item)) {
|
|
666
|
+
deferred[deferredSize++] = item;
|
|
667
|
+
} else {
|
|
668
|
+
nodes[nodeSize++] = await this.parse(item);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
672
|
+
nodes[nodeSize + i] = await this.parse(deferred[i]);
|
|
673
|
+
}
|
|
768
674
|
return {
|
|
769
|
-
t:
|
|
675
|
+
t: 5 /* Set */,
|
|
770
676
|
i: id,
|
|
771
|
-
a:
|
|
677
|
+
a: nodes,
|
|
772
678
|
s: void 0,
|
|
773
679
|
l: void 0,
|
|
774
680
|
m: void 0,
|
|
@@ -777,43 +683,56 @@ async function generateTreeAsync(ctx, current) {
|
|
|
777
683
|
n: void 0
|
|
778
684
|
};
|
|
779
685
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
686
|
+
async generateProperties(properties) {
|
|
687
|
+
const keys = Object.keys(properties);
|
|
688
|
+
const size = keys.length;
|
|
689
|
+
const keyNodes = new Array(size);
|
|
690
|
+
const valueNodes = new Array(size);
|
|
691
|
+
const deferredKeys = new Array(size);
|
|
692
|
+
const deferredValues = new Array(size);
|
|
693
|
+
let deferredSize = 0;
|
|
694
|
+
let nodesSize = 0;
|
|
695
|
+
let item;
|
|
696
|
+
for (const key of keys) {
|
|
697
|
+
item = properties[key];
|
|
698
|
+
if (isIterable(item)) {
|
|
699
|
+
deferredKeys[deferredSize] = key;
|
|
700
|
+
deferredValues[deferredSize] = item;
|
|
701
|
+
deferredSize++;
|
|
702
|
+
} else {
|
|
703
|
+
keyNodes[nodesSize] = key;
|
|
704
|
+
valueNodes[nodesSize] = await this.parse(item);
|
|
705
|
+
nodesSize++;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
709
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
710
|
+
valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
|
|
788
711
|
}
|
|
789
712
|
return {
|
|
790
|
-
|
|
713
|
+
k: keyNodes,
|
|
714
|
+
v: valueNodes,
|
|
715
|
+
s: size
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
async generateIterableNode(id, current) {
|
|
719
|
+
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
720
|
+
const options = getIterableOptions(current);
|
|
721
|
+
return {
|
|
722
|
+
t: 13 /* Iterable */,
|
|
791
723
|
i: id,
|
|
792
724
|
s: void 0,
|
|
793
725
|
l: void 0,
|
|
794
726
|
m: void 0,
|
|
795
727
|
c: void 0,
|
|
796
728
|
// Parse options first before the items
|
|
797
|
-
d: await
|
|
798
|
-
a:
|
|
729
|
+
d: options ? await this.generateProperties(options) : void 0,
|
|
730
|
+
a: await this.generateNodeList(Array.from(current)),
|
|
799
731
|
n: void 0
|
|
800
732
|
};
|
|
801
733
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
if (cs === Map) {
|
|
806
|
-
return generateMapNode(ctx, current, id);
|
|
807
|
-
}
|
|
808
|
-
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
|
|
809
|
-
if (semiPrimitive) {
|
|
810
|
-
return semiPrimitive;
|
|
811
|
-
}
|
|
812
|
-
if (Symbol.iterator in current) {
|
|
813
|
-
return generateIterableNode(ctx, current, id);
|
|
814
|
-
}
|
|
815
|
-
if (isPromise(current)) {
|
|
816
|
-
assert(ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
|
|
734
|
+
async generatePromiseNode(id, current) {
|
|
735
|
+
assert(this.ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
|
|
817
736
|
return current.then(async (value) => ({
|
|
818
737
|
t: 10 /* Promise */,
|
|
819
738
|
i: id,
|
|
@@ -824,20 +743,160 @@ async function generateTreeAsync(ctx, current) {
|
|
|
824
743
|
// Parse options first before the items
|
|
825
744
|
d: void 0,
|
|
826
745
|
a: void 0,
|
|
827
|
-
n: await
|
|
746
|
+
n: await this.parse(value)
|
|
828
747
|
}));
|
|
829
748
|
}
|
|
830
|
-
|
|
831
|
-
|
|
749
|
+
async generateObjectNode(id, current, empty) {
|
|
750
|
+
if (Symbol.iterator in current) {
|
|
751
|
+
return this.generateIterableNode(id, current);
|
|
752
|
+
}
|
|
753
|
+
if ("then" in current && typeof current.then === "function") {
|
|
754
|
+
return this.generatePromiseNode(id, current);
|
|
755
|
+
}
|
|
756
|
+
return {
|
|
757
|
+
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
758
|
+
i: id,
|
|
759
|
+
s: void 0,
|
|
760
|
+
l: void 0,
|
|
761
|
+
m: void 0,
|
|
762
|
+
c: void 0,
|
|
763
|
+
d: await this.generateProperties(current),
|
|
764
|
+
a: void 0,
|
|
765
|
+
n: void 0
|
|
766
|
+
};
|
|
832
767
|
}
|
|
833
|
-
|
|
834
|
-
|
|
768
|
+
async generateAggregateErrorNode(id, current) {
|
|
769
|
+
const options = getErrorOptions(current);
|
|
770
|
+
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
771
|
+
return {
|
|
772
|
+
t: 12 /* AggregateError */,
|
|
773
|
+
i: id,
|
|
774
|
+
a: void 0,
|
|
775
|
+
s: void 0,
|
|
776
|
+
l: void 0,
|
|
777
|
+
m: current.message,
|
|
778
|
+
c: void 0,
|
|
779
|
+
d: optionsNode,
|
|
780
|
+
n: await this.parse(current.errors)
|
|
781
|
+
};
|
|
835
782
|
}
|
|
836
|
-
|
|
837
|
-
|
|
783
|
+
async generateErrorNode(id, current) {
|
|
784
|
+
const options = getErrorOptions(current);
|
|
785
|
+
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
786
|
+
return {
|
|
787
|
+
t: 11 /* Error */,
|
|
788
|
+
i: id,
|
|
789
|
+
a: void 0,
|
|
790
|
+
s: void 0,
|
|
791
|
+
l: void 0,
|
|
792
|
+
m: current.message,
|
|
793
|
+
c: getErrorConstructor(current),
|
|
794
|
+
d: optionsNode,
|
|
795
|
+
n: void 0
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
async parse(current) {
|
|
799
|
+
switch (typeof current) {
|
|
800
|
+
case "boolean":
|
|
801
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
802
|
+
case "undefined":
|
|
803
|
+
return UNDEFINED_NODE;
|
|
804
|
+
case "string":
|
|
805
|
+
return createPrimitiveNode(quote(current));
|
|
806
|
+
case "number":
|
|
807
|
+
if (Object.is(current, -0)) {
|
|
808
|
+
return NEG_ZERO_NODE;
|
|
809
|
+
}
|
|
810
|
+
if (Object.is(current, Infinity)) {
|
|
811
|
+
return createPrimitiveNode("1/0");
|
|
812
|
+
}
|
|
813
|
+
if (Object.is(current, -Infinity)) {
|
|
814
|
+
return createPrimitiveNode("-1/0");
|
|
815
|
+
}
|
|
816
|
+
return createPrimitiveNode(current);
|
|
817
|
+
case "bigint":
|
|
818
|
+
return createBigIntNode(this.ctx, current);
|
|
819
|
+
case "object": {
|
|
820
|
+
if (!current) {
|
|
821
|
+
return NULL_NODE;
|
|
822
|
+
}
|
|
823
|
+
const id = createRef(this.ctx, current, true);
|
|
824
|
+
if (this.ctx.markedRefs[id]) {
|
|
825
|
+
return createReferenceNode(id);
|
|
826
|
+
}
|
|
827
|
+
if (Array.isArray(current)) {
|
|
828
|
+
return this.generateArrayNode(id, current);
|
|
829
|
+
}
|
|
830
|
+
switch (current.constructor) {
|
|
831
|
+
case Date:
|
|
832
|
+
return createDateNode(id, current);
|
|
833
|
+
case RegExp:
|
|
834
|
+
return createRegExpNode(id, current);
|
|
835
|
+
case Promise:
|
|
836
|
+
return this.generatePromiseNode(id, current);
|
|
837
|
+
case Int8Array:
|
|
838
|
+
case Int16Array:
|
|
839
|
+
case Int32Array:
|
|
840
|
+
case Uint8Array:
|
|
841
|
+
case Uint16Array:
|
|
842
|
+
case Uint32Array:
|
|
843
|
+
case Uint8ClampedArray:
|
|
844
|
+
case Float32Array:
|
|
845
|
+
case Float64Array:
|
|
846
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
847
|
+
case BigInt64Array:
|
|
848
|
+
case BigUint64Array:
|
|
849
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
850
|
+
case Map:
|
|
851
|
+
return this.generateMapNode(id, current);
|
|
852
|
+
case Set:
|
|
853
|
+
return this.generateSetNode(id, current);
|
|
854
|
+
case Object:
|
|
855
|
+
return this.generateObjectNode(id, current, false);
|
|
856
|
+
case void 0:
|
|
857
|
+
return this.generateObjectNode(id, current, true);
|
|
858
|
+
case AggregateError:
|
|
859
|
+
if (this.ctx.features & 1 /* AggregateError */) {
|
|
860
|
+
return this.generateAggregateErrorNode(id, current);
|
|
861
|
+
}
|
|
862
|
+
return this.generateErrorNode(id, current);
|
|
863
|
+
case Error:
|
|
864
|
+
case EvalError:
|
|
865
|
+
case RangeError:
|
|
866
|
+
case ReferenceError:
|
|
867
|
+
case SyntaxError:
|
|
868
|
+
case TypeError:
|
|
869
|
+
case URIError:
|
|
870
|
+
return this.generateErrorNode(id, current);
|
|
871
|
+
default:
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
|
|
875
|
+
return this.generateAggregateErrorNode(id, current);
|
|
876
|
+
}
|
|
877
|
+
if (current instanceof Error) {
|
|
878
|
+
return this.generateErrorNode(id, current);
|
|
879
|
+
}
|
|
880
|
+
if (current instanceof Promise) {
|
|
881
|
+
return this.generatePromiseNode(id, current);
|
|
882
|
+
}
|
|
883
|
+
if (Symbol.iterator in current) {
|
|
884
|
+
return this.generateIterableNode(id, current);
|
|
885
|
+
}
|
|
886
|
+
if ("then" in current && typeof current.then === "function") {
|
|
887
|
+
return this.generatePromiseNode(id, current);
|
|
888
|
+
}
|
|
889
|
+
throw new Error("Unsupported type");
|
|
890
|
+
}
|
|
891
|
+
default:
|
|
892
|
+
throw new Error("Unsupported type");
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
};
|
|
838
896
|
async function parseAsync(ctx, current) {
|
|
839
|
-
const result = await
|
|
840
|
-
|
|
897
|
+
const result = await new AsyncParser(ctx).parse(current);
|
|
898
|
+
const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
|
|
899
|
+
return [result, createRef(ctx, current, false), isObject];
|
|
841
900
|
}
|
|
842
901
|
|
|
843
902
|
// src/tree/serialize.ts
|
|
@@ -1222,202 +1281,104 @@ function serializeTree(ctx, node) {
|
|
|
1222
1281
|
}
|
|
1223
1282
|
|
|
1224
1283
|
// src/tree/sync.ts
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
}
|
|
1245
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
1246
|
-
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1247
|
-
valueNodes[nodesSize + i] = generateTreeSync(ctx, deferredValues[i]);
|
|
1248
|
-
}
|
|
1249
|
-
return {
|
|
1250
|
-
k: keyNodes,
|
|
1251
|
-
v: valueNodes,
|
|
1252
|
-
s: size
|
|
1253
|
-
};
|
|
1254
|
-
}
|
|
1255
|
-
function generateSetNode2(ctx, current, id) {
|
|
1256
|
-
assert(ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
1257
|
-
const len = current.size;
|
|
1258
|
-
const nodes = new Array(len);
|
|
1259
|
-
const deferred = new Array(len);
|
|
1260
|
-
let deferredSize = 0;
|
|
1261
|
-
let nodeSize = 0;
|
|
1262
|
-
for (const item of current.keys()) {
|
|
1263
|
-
if (isIterable(item)) {
|
|
1264
|
-
deferred[deferredSize++] = item;
|
|
1265
|
-
} else {
|
|
1266
|
-
nodes[nodeSize++] = generateTreeSync(ctx, item);
|
|
1284
|
+
var SyncParser = class {
|
|
1285
|
+
constructor(ctx) {
|
|
1286
|
+
__publicField(this, "ctx");
|
|
1287
|
+
this.ctx = ctx;
|
|
1288
|
+
}
|
|
1289
|
+
generateNodeList(current) {
|
|
1290
|
+
const size = current.length;
|
|
1291
|
+
const nodes = new Array(size);
|
|
1292
|
+
const deferred = new Array(size);
|
|
1293
|
+
let item;
|
|
1294
|
+
for (let i = 0; i < size; i++) {
|
|
1295
|
+
if (i in current) {
|
|
1296
|
+
item = current[i];
|
|
1297
|
+
if (isIterable(item)) {
|
|
1298
|
+
deferred[i] = item;
|
|
1299
|
+
} else {
|
|
1300
|
+
nodes[i] = this.parse(item);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1267
1303
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
return {
|
|
1273
|
-
t: 5 /* Set */,
|
|
1274
|
-
i: id,
|
|
1275
|
-
a: nodes,
|
|
1276
|
-
s: void 0,
|
|
1277
|
-
l: void 0,
|
|
1278
|
-
m: void 0,
|
|
1279
|
-
c: void 0,
|
|
1280
|
-
d: void 0,
|
|
1281
|
-
n: void 0
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
function generateMapNode2(ctx, current, id) {
|
|
1285
|
-
assert(ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
1286
|
-
const len = current.size;
|
|
1287
|
-
const keyNodes = new Array(len);
|
|
1288
|
-
const valueNodes = new Array(len);
|
|
1289
|
-
const deferredKey = new Array(len);
|
|
1290
|
-
const deferredValue = new Array(len);
|
|
1291
|
-
let deferredSize = 0;
|
|
1292
|
-
let nodeSize = 0;
|
|
1293
|
-
for (const [key, value] of current.entries()) {
|
|
1294
|
-
if (isIterable(key) || isIterable(value)) {
|
|
1295
|
-
deferredKey[deferredSize] = key;
|
|
1296
|
-
deferredValue[deferredSize] = value;
|
|
1297
|
-
deferredSize++;
|
|
1298
|
-
} else {
|
|
1299
|
-
keyNodes[nodeSize] = generateTreeSync(ctx, key);
|
|
1300
|
-
valueNodes[nodeSize] = generateTreeSync(ctx, value);
|
|
1301
|
-
nodeSize++;
|
|
1304
|
+
for (let i = 0; i < size; i++) {
|
|
1305
|
+
if (i in deferred) {
|
|
1306
|
+
nodes[i] = this.parse(deferred[i]);
|
|
1307
|
+
}
|
|
1302
1308
|
}
|
|
1309
|
+
return nodes;
|
|
1303
1310
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1311
|
+
generateArrayNode(id, current) {
|
|
1312
|
+
return {
|
|
1313
|
+
t: 7 /* Array */,
|
|
1314
|
+
i: id,
|
|
1315
|
+
a: this.generateNodeList(current),
|
|
1316
|
+
s: void 0,
|
|
1317
|
+
l: void 0,
|
|
1318
|
+
m: void 0,
|
|
1319
|
+
c: void 0,
|
|
1320
|
+
d: void 0,
|
|
1321
|
+
n: void 0
|
|
1322
|
+
};
|
|
1307
1323
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const nodes = new Array(size);
|
|
1323
|
-
const deferred = new Array(size);
|
|
1324
|
-
for (let i = 0; i < size; i++) {
|
|
1325
|
-
if (i in current) {
|
|
1326
|
-
if (isIterable(current[i])) {
|
|
1327
|
-
deferred[i] = current[i];
|
|
1324
|
+
generateMapNode(id, current) {
|
|
1325
|
+
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
1326
|
+
const len = current.size;
|
|
1327
|
+
const keyNodes = new Array(len);
|
|
1328
|
+
const valueNodes = new Array(len);
|
|
1329
|
+
const deferredKey = new Array(len);
|
|
1330
|
+
const deferredValue = new Array(len);
|
|
1331
|
+
let deferredSize = 0;
|
|
1332
|
+
let nodeSize = 0;
|
|
1333
|
+
for (const [key, value] of current.entries()) {
|
|
1334
|
+
if (isIterable(key) || isIterable(value)) {
|
|
1335
|
+
deferredKey[deferredSize] = key;
|
|
1336
|
+
deferredValue[deferredSize] = value;
|
|
1337
|
+
deferredSize++;
|
|
1328
1338
|
} else {
|
|
1329
|
-
|
|
1339
|
+
keyNodes[nodeSize] = this.parse(key);
|
|
1340
|
+
valueNodes[nodeSize] = this.parse(value);
|
|
1341
|
+
nodeSize++;
|
|
1330
1342
|
}
|
|
1331
1343
|
}
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
nodes[i] = generateTreeSync(ctx, deferred[i]);
|
|
1344
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1345
|
+
keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
|
|
1346
|
+
valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
|
|
1336
1347
|
}
|
|
1337
|
-
}
|
|
1338
|
-
return nodes;
|
|
1339
|
-
}
|
|
1340
|
-
function generateArrayNode2(ctx, current, id) {
|
|
1341
|
-
return {
|
|
1342
|
-
t: 7 /* Array */,
|
|
1343
|
-
i: id,
|
|
1344
|
-
a: generateNodeList2(ctx, current),
|
|
1345
|
-
s: void 0,
|
|
1346
|
-
l: void 0,
|
|
1347
|
-
m: void 0,
|
|
1348
|
-
c: void 0,
|
|
1349
|
-
d: void 0,
|
|
1350
|
-
n: void 0
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
function generateAggregateErrorNode2(ctx, current, id) {
|
|
1354
|
-
const options = getErrorOptions(current);
|
|
1355
|
-
const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
|
|
1356
|
-
return {
|
|
1357
|
-
t: 12 /* AggregateError */,
|
|
1358
|
-
i: id,
|
|
1359
|
-
a: void 0,
|
|
1360
|
-
s: void 0,
|
|
1361
|
-
l: void 0,
|
|
1362
|
-
m: current.message,
|
|
1363
|
-
c: void 0,
|
|
1364
|
-
d: optionsNode,
|
|
1365
|
-
n: generateTreeSync(ctx, current.errors)
|
|
1366
|
-
};
|
|
1367
|
-
}
|
|
1368
|
-
function generateErrorNode2(ctx, current, id) {
|
|
1369
|
-
const options = getErrorOptions(current);
|
|
1370
|
-
const optionsNode = options ? serializePropertiesSync(ctx, options) : void 0;
|
|
1371
|
-
return {
|
|
1372
|
-
t: 11 /* Error */,
|
|
1373
|
-
i: id,
|
|
1374
|
-
a: void 0,
|
|
1375
|
-
s: void 0,
|
|
1376
|
-
l: void 0,
|
|
1377
|
-
m: current.message,
|
|
1378
|
-
c: getErrorConstructor(current),
|
|
1379
|
-
d: optionsNode,
|
|
1380
|
-
n: void 0
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
function generateIterableNode2(ctx, current, id) {
|
|
1384
|
-
assert(ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1385
|
-
const options = getIterableOptions(current);
|
|
1386
|
-
return {
|
|
1387
|
-
t: 13 /* Iterable */,
|
|
1388
|
-
i: id,
|
|
1389
|
-
s: void 0,
|
|
1390
|
-
l: void 0,
|
|
1391
|
-
m: void 0,
|
|
1392
|
-
c: void 0,
|
|
1393
|
-
// Parse options first before the items
|
|
1394
|
-
d: options ? serializePropertiesSync(ctx, options) : void 0,
|
|
1395
|
-
a: generateNodeList2(ctx, Array.from(current)),
|
|
1396
|
-
n: void 0
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
function generateTreeSync(ctx, current) {
|
|
1400
|
-
if (isPrimitive(current)) {
|
|
1401
1348
|
return {
|
|
1402
|
-
t:
|
|
1403
|
-
i:
|
|
1404
|
-
|
|
1349
|
+
t: 6 /* Map */,
|
|
1350
|
+
i: id,
|
|
1351
|
+
a: void 0,
|
|
1352
|
+
s: void 0,
|
|
1405
1353
|
l: void 0,
|
|
1406
1354
|
m: void 0,
|
|
1407
1355
|
c: void 0,
|
|
1408
|
-
|
|
1409
|
-
d: void 0,
|
|
1410
|
-
a: void 0,
|
|
1356
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1411
1357
|
n: void 0
|
|
1412
1358
|
};
|
|
1413
1359
|
}
|
|
1414
|
-
|
|
1415
|
-
assert(ctx.features &
|
|
1360
|
+
generateSetNode(id, current) {
|
|
1361
|
+
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
1362
|
+
const len = current.size;
|
|
1363
|
+
const nodes = new Array(len);
|
|
1364
|
+
const deferred = new Array(len);
|
|
1365
|
+
let deferredSize = 0;
|
|
1366
|
+
let nodeSize = 0;
|
|
1367
|
+
for (const item of current.keys()) {
|
|
1368
|
+
if (isIterable(item)) {
|
|
1369
|
+
deferred[deferredSize++] = item;
|
|
1370
|
+
} else {
|
|
1371
|
+
nodes[nodeSize++] = this.parse(item);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1375
|
+
nodes[nodeSize + i] = this.parse(deferred[i]);
|
|
1376
|
+
}
|
|
1416
1377
|
return {
|
|
1417
|
-
t:
|
|
1418
|
-
i:
|
|
1419
|
-
a:
|
|
1420
|
-
s:
|
|
1378
|
+
t: 5 /* Set */,
|
|
1379
|
+
i: id,
|
|
1380
|
+
a: nodes,
|
|
1381
|
+
s: void 0,
|
|
1421
1382
|
l: void 0,
|
|
1422
1383
|
m: void 0,
|
|
1423
1384
|
c: void 0,
|
|
@@ -1425,28 +1386,57 @@ function generateTreeSync(ctx, current) {
|
|
|
1425
1386
|
n: void 0
|
|
1426
1387
|
};
|
|
1427
1388
|
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1389
|
+
generateProperties(properties) {
|
|
1390
|
+
const keys = Object.keys(properties);
|
|
1391
|
+
const size = keys.length;
|
|
1392
|
+
const keyNodes = new Array(size);
|
|
1393
|
+
const valueNodes = new Array(size);
|
|
1394
|
+
const deferredKeys = new Array(size);
|
|
1395
|
+
const deferredValues = new Array(size);
|
|
1396
|
+
let deferredSize = 0;
|
|
1397
|
+
let nodesSize = 0;
|
|
1398
|
+
let item;
|
|
1399
|
+
for (const key of keys) {
|
|
1400
|
+
item = properties[key];
|
|
1401
|
+
if (isIterable(item)) {
|
|
1402
|
+
deferredKeys[deferredSize] = key;
|
|
1403
|
+
deferredValues[deferredSize] = item;
|
|
1404
|
+
deferredSize++;
|
|
1405
|
+
} else {
|
|
1406
|
+
keyNodes[nodesSize] = key;
|
|
1407
|
+
valueNodes[nodesSize] = this.parse(item);
|
|
1408
|
+
nodesSize++;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1412
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1413
|
+
valueNodes[nodesSize + i] = this.parse(deferredValues[i]);
|
|
1414
|
+
}
|
|
1430
1415
|
return {
|
|
1431
|
-
|
|
1416
|
+
k: keyNodes,
|
|
1417
|
+
v: valueNodes,
|
|
1418
|
+
s: size
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
generateIterableNode(id, current) {
|
|
1422
|
+
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1423
|
+
const options = getIterableOptions(current);
|
|
1424
|
+
return {
|
|
1425
|
+
t: 13 /* Iterable */,
|
|
1432
1426
|
i: id,
|
|
1433
|
-
a: void 0,
|
|
1434
1427
|
s: void 0,
|
|
1435
1428
|
l: void 0,
|
|
1436
1429
|
m: void 0,
|
|
1437
1430
|
c: void 0,
|
|
1438
|
-
|
|
1431
|
+
// Parse options first before the items
|
|
1432
|
+
d: options ? this.generateProperties(options) : void 0,
|
|
1433
|
+
a: this.generateNodeList(Array.from(current)),
|
|
1439
1434
|
n: void 0
|
|
1440
1435
|
};
|
|
1441
1436
|
}
|
|
1442
|
-
|
|
1443
|
-
return generateArrayNode2(ctx, current, id);
|
|
1444
|
-
}
|
|
1445
|
-
const cs = current.constructor;
|
|
1446
|
-
const empty = cs == null;
|
|
1447
|
-
if (cs === Object || empty) {
|
|
1437
|
+
generateObjectNode(id, current, empty) {
|
|
1448
1438
|
if (Symbol.iterator in current) {
|
|
1449
|
-
return
|
|
1439
|
+
return this.generateIterableNode(id, current);
|
|
1450
1440
|
}
|
|
1451
1441
|
return {
|
|
1452
1442
|
t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
|
|
@@ -1455,36 +1445,135 @@ function generateTreeSync(ctx, current) {
|
|
|
1455
1445
|
l: void 0,
|
|
1456
1446
|
m: void 0,
|
|
1457
1447
|
c: void 0,
|
|
1458
|
-
|
|
1459
|
-
d: serializePropertiesSync(ctx, current),
|
|
1448
|
+
d: this.generateProperties(current),
|
|
1460
1449
|
a: void 0,
|
|
1461
1450
|
n: void 0
|
|
1462
1451
|
};
|
|
1463
1452
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1453
|
+
generateAggregateErrorNode(id, current) {
|
|
1454
|
+
const options = getErrorOptions(current);
|
|
1455
|
+
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1456
|
+
return {
|
|
1457
|
+
t: 12 /* AggregateError */,
|
|
1458
|
+
i: id,
|
|
1459
|
+
a: void 0,
|
|
1460
|
+
s: void 0,
|
|
1461
|
+
l: void 0,
|
|
1462
|
+
m: current.message,
|
|
1463
|
+
c: void 0,
|
|
1464
|
+
d: optionsNode,
|
|
1465
|
+
n: this.parse(current.errors)
|
|
1466
|
+
};
|
|
1476
1467
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1468
|
+
generateErrorNode(id, current) {
|
|
1469
|
+
const options = getErrorOptions(current);
|
|
1470
|
+
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1471
|
+
return {
|
|
1472
|
+
t: 11 /* Error */,
|
|
1473
|
+
i: id,
|
|
1474
|
+
a: void 0,
|
|
1475
|
+
s: void 0,
|
|
1476
|
+
l: void 0,
|
|
1477
|
+
m: current.message,
|
|
1478
|
+
c: getErrorConstructor(current),
|
|
1479
|
+
d: optionsNode,
|
|
1480
|
+
n: void 0
|
|
1481
|
+
};
|
|
1479
1482
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1483
|
+
parse(current) {
|
|
1484
|
+
switch (typeof current) {
|
|
1485
|
+
case "boolean":
|
|
1486
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
1487
|
+
case "undefined":
|
|
1488
|
+
return UNDEFINED_NODE;
|
|
1489
|
+
case "string":
|
|
1490
|
+
return createPrimitiveNode(quote(current));
|
|
1491
|
+
case "number":
|
|
1492
|
+
if (Object.is(current, -0)) {
|
|
1493
|
+
return NEG_ZERO_NODE;
|
|
1494
|
+
}
|
|
1495
|
+
if (Object.is(current, Infinity)) {
|
|
1496
|
+
return createPrimitiveNode("1/0");
|
|
1497
|
+
}
|
|
1498
|
+
if (Object.is(current, -Infinity)) {
|
|
1499
|
+
return createPrimitiveNode("-1/0");
|
|
1500
|
+
}
|
|
1501
|
+
return createPrimitiveNode(current);
|
|
1502
|
+
case "bigint":
|
|
1503
|
+
return createBigIntNode(this.ctx, current);
|
|
1504
|
+
case "object": {
|
|
1505
|
+
if (!current) {
|
|
1506
|
+
return NULL_NODE;
|
|
1507
|
+
}
|
|
1508
|
+
const id = createRef(this.ctx, current, true);
|
|
1509
|
+
if (this.ctx.markedRefs[id]) {
|
|
1510
|
+
return createReferenceNode(id);
|
|
1511
|
+
}
|
|
1512
|
+
if (Array.isArray(current)) {
|
|
1513
|
+
return this.generateArrayNode(id, current);
|
|
1514
|
+
}
|
|
1515
|
+
switch (current.constructor) {
|
|
1516
|
+
case Date:
|
|
1517
|
+
return createDateNode(id, current);
|
|
1518
|
+
case RegExp:
|
|
1519
|
+
return createRegExpNode(id, current);
|
|
1520
|
+
case Int8Array:
|
|
1521
|
+
case Int16Array:
|
|
1522
|
+
case Int32Array:
|
|
1523
|
+
case Uint8Array:
|
|
1524
|
+
case Uint16Array:
|
|
1525
|
+
case Uint32Array:
|
|
1526
|
+
case Uint8ClampedArray:
|
|
1527
|
+
case Float32Array:
|
|
1528
|
+
case Float64Array:
|
|
1529
|
+
return createTypedArrayNode(this.ctx, id, current);
|
|
1530
|
+
case BigInt64Array:
|
|
1531
|
+
case BigUint64Array:
|
|
1532
|
+
return createBigIntTypedArrayNode(this.ctx, id, current);
|
|
1533
|
+
case Map:
|
|
1534
|
+
return this.generateMapNode(id, current);
|
|
1535
|
+
case Set:
|
|
1536
|
+
return this.generateSetNode(id, current);
|
|
1537
|
+
case Object:
|
|
1538
|
+
return this.generateObjectNode(id, current, false);
|
|
1539
|
+
case void 0:
|
|
1540
|
+
return this.generateObjectNode(id, current, true);
|
|
1541
|
+
case AggregateError:
|
|
1542
|
+
if (this.ctx.features & 1 /* AggregateError */) {
|
|
1543
|
+
return this.generateAggregateErrorNode(id, current);
|
|
1544
|
+
}
|
|
1545
|
+
return this.generateErrorNode(id, current);
|
|
1546
|
+
case Error:
|
|
1547
|
+
case EvalError:
|
|
1548
|
+
case RangeError:
|
|
1549
|
+
case ReferenceError:
|
|
1550
|
+
case SyntaxError:
|
|
1551
|
+
case TypeError:
|
|
1552
|
+
case URIError:
|
|
1553
|
+
return this.generateErrorNode(id, current);
|
|
1554
|
+
default:
|
|
1555
|
+
break;
|
|
1556
|
+
}
|
|
1557
|
+
if (current instanceof AggregateError && this.ctx.features & 1 /* AggregateError */) {
|
|
1558
|
+
return this.generateAggregateErrorNode(id, current);
|
|
1559
|
+
}
|
|
1560
|
+
if (current instanceof Error) {
|
|
1561
|
+
return this.generateErrorNode(id, current);
|
|
1562
|
+
}
|
|
1563
|
+
if (Symbol.iterator in current) {
|
|
1564
|
+
return this.generateIterableNode(id, current);
|
|
1565
|
+
}
|
|
1566
|
+
throw new Error("Unsupported type");
|
|
1567
|
+
}
|
|
1568
|
+
default:
|
|
1569
|
+
throw new Error("Unsupported type");
|
|
1570
|
+
}
|
|
1482
1571
|
}
|
|
1483
|
-
|
|
1484
|
-
}
|
|
1572
|
+
};
|
|
1485
1573
|
function parseSync(ctx, current) {
|
|
1486
|
-
const result =
|
|
1487
|
-
|
|
1574
|
+
const result = new SyncParser(ctx).parse(current);
|
|
1575
|
+
const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
|
|
1576
|
+
return [result, createRef(ctx, current, false), isObject];
|
|
1488
1577
|
}
|
|
1489
1578
|
|
|
1490
1579
|
// src/index.ts
|
|
@@ -1514,9 +1603,6 @@ function finalize(ctx, rootID, isObject, result) {
|
|
|
1514
1603
|
}
|
|
1515
1604
|
function serialize(source, options) {
|
|
1516
1605
|
const ctx = createParserContext(options);
|
|
1517
|
-
if (isPrimitive(source)) {
|
|
1518
|
-
return String(serializePrimitive(source));
|
|
1519
|
-
}
|
|
1520
1606
|
const [tree, rootID, isObject] = parseSync(ctx, source);
|
|
1521
1607
|
const serial = createSerializationContext(ctx);
|
|
1522
1608
|
const result = serializeTree(serial, tree);
|
|
@@ -1524,9 +1610,6 @@ function serialize(source, options) {
|
|
|
1524
1610
|
}
|
|
1525
1611
|
async function serializeAsync(source, options) {
|
|
1526
1612
|
const ctx = createParserContext(options);
|
|
1527
|
-
if (isPrimitive(source)) {
|
|
1528
|
-
return String(serializePrimitive(source));
|
|
1529
|
-
}
|
|
1530
1613
|
const [tree, rootID, isObject] = await parseAsync(ctx, source);
|
|
1531
1614
|
const serial = createSerializationContext(ctx);
|
|
1532
1615
|
const result = serializeTree(serial, tree);
|