seroval 1.3.0 → 1.3.2
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 +138 -131
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +4 -4
- package/dist/esm/development/index.mjs +138 -131
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/context/deserializer.d.ts +1 -0
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +1 -1
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +1 -1
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/tree/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/core/context/deserializer.ts +80 -73
- package/src/core/context/parser/async.ts +19 -23
- package/src/core/context/parser/stream.ts +4 -4
- package/src/core/context/parser/sync.ts +15 -19
- package/src/core/context/serializer.ts +12 -3
- package/src/core/cross/index.ts +5 -5
- package/src/core/tree/index.ts +6 -6
|
@@ -1403,7 +1403,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1403
1403
|
const nodes = [];
|
|
1404
1404
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
1405
1405
|
if (i in current) {
|
|
1406
|
-
nodes[i] = await this.
|
|
1406
|
+
nodes[i] = await this.parse(current[i]);
|
|
1407
1407
|
}
|
|
1408
1408
|
}
|
|
1409
1409
|
return nodes;
|
|
@@ -1417,7 +1417,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1417
1417
|
const valueNodes = [];
|
|
1418
1418
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
1419
1419
|
keyNodes.push(serializeString(entries[i][0]));
|
|
1420
|
-
valueNodes.push(await this.
|
|
1420
|
+
valueNodes.push(await this.parse(entries[i][1]));
|
|
1421
1421
|
}
|
|
1422
1422
|
let symbol = Symbol.iterator;
|
|
1423
1423
|
if (symbol in properties) {
|
|
@@ -1425,7 +1425,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1425
1425
|
valueNodes.push(
|
|
1426
1426
|
createIteratorFactoryInstanceNode(
|
|
1427
1427
|
this.parseIteratorFactory(),
|
|
1428
|
-
await this.
|
|
1428
|
+
await this.parse(
|
|
1429
1429
|
iteratorToSequence(properties)
|
|
1430
1430
|
)
|
|
1431
1431
|
)
|
|
@@ -1437,7 +1437,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1437
1437
|
valueNodes.push(
|
|
1438
1438
|
createAsyncIteratorFactoryInstanceNode(
|
|
1439
1439
|
this.parseAsyncIteratorFactory(),
|
|
1440
|
-
await this.
|
|
1440
|
+
await this.parse(
|
|
1441
1441
|
createStreamFromAsyncIterable(
|
|
1442
1442
|
properties
|
|
1443
1443
|
)
|
|
@@ -1470,24 +1470,20 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1470
1470
|
);
|
|
1471
1471
|
}
|
|
1472
1472
|
async parseBoxed(id, current) {
|
|
1473
|
-
return createBoxedNode(id, await this.
|
|
1473
|
+
return createBoxedNode(id, await this.parse(current.valueOf()));
|
|
1474
1474
|
}
|
|
1475
1475
|
async parseTypedArray(id, current) {
|
|
1476
|
-
return createTypedArrayNode(
|
|
1477
|
-
id,
|
|
1478
|
-
current,
|
|
1479
|
-
await this.parseTop(current.buffer)
|
|
1480
|
-
);
|
|
1476
|
+
return createTypedArrayNode(id, current, await this.parse(current.buffer));
|
|
1481
1477
|
}
|
|
1482
1478
|
async parseBigIntTypedArray(id, current) {
|
|
1483
1479
|
return createBigIntTypedArrayNode(
|
|
1484
1480
|
id,
|
|
1485
1481
|
current,
|
|
1486
|
-
await this.
|
|
1482
|
+
await this.parse(current.buffer)
|
|
1487
1483
|
);
|
|
1488
1484
|
}
|
|
1489
1485
|
async parseDataView(id, current) {
|
|
1490
|
-
return createDataViewNode(id, current, await this.
|
|
1486
|
+
return createDataViewNode(id, current, await this.parse(current.buffer));
|
|
1491
1487
|
}
|
|
1492
1488
|
async parseError(id, current) {
|
|
1493
1489
|
const options = getErrorOptions(current, this.features);
|
|
@@ -1509,15 +1505,15 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1509
1505
|
const keyNodes = [];
|
|
1510
1506
|
const valueNodes = [];
|
|
1511
1507
|
for (const [key, value] of current.entries()) {
|
|
1512
|
-
keyNodes.push(await this.
|
|
1513
|
-
valueNodes.push(await this.
|
|
1508
|
+
keyNodes.push(await this.parse(key));
|
|
1509
|
+
valueNodes.push(await this.parse(value));
|
|
1514
1510
|
}
|
|
1515
1511
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
1516
1512
|
}
|
|
1517
1513
|
async parseSet(id, current) {
|
|
1518
1514
|
const items = [];
|
|
1519
1515
|
for (const item of current.keys()) {
|
|
1520
|
-
items.push(await this.
|
|
1516
|
+
items.push(await this.parse(item));
|
|
1521
1517
|
}
|
|
1522
1518
|
return createSetNode(id, current.size, items);
|
|
1523
1519
|
}
|
|
@@ -1533,7 +1529,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1533
1529
|
NIL,
|
|
1534
1530
|
NIL,
|
|
1535
1531
|
NIL,
|
|
1536
|
-
await this.
|
|
1532
|
+
await this.parse(result),
|
|
1537
1533
|
NIL,
|
|
1538
1534
|
NIL
|
|
1539
1535
|
);
|
|
@@ -1565,7 +1561,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1565
1561
|
const cleanup = current.on({
|
|
1566
1562
|
next: (value) => {
|
|
1567
1563
|
this.markRef(id);
|
|
1568
|
-
this.
|
|
1564
|
+
this.parse(value).then(
|
|
1569
1565
|
(data) => {
|
|
1570
1566
|
sequence.push(createStreamNextNode(id, data));
|
|
1571
1567
|
},
|
|
@@ -1577,7 +1573,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1577
1573
|
},
|
|
1578
1574
|
throw: (value) => {
|
|
1579
1575
|
this.markRef(id);
|
|
1580
|
-
this.
|
|
1576
|
+
this.parse(value).then(
|
|
1581
1577
|
(data) => {
|
|
1582
1578
|
sequence.push(createStreamThrowNode(id, data));
|
|
1583
1579
|
resolve(sequence);
|
|
@@ -1591,7 +1587,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1591
1587
|
},
|
|
1592
1588
|
return: (value) => {
|
|
1593
1589
|
this.markRef(id);
|
|
1594
|
-
this.
|
|
1590
|
+
this.parse(value).then(
|
|
1595
1591
|
(data) => {
|
|
1596
1592
|
sequence.push(createStreamReturnNode(id, data));
|
|
1597
1593
|
resolve(sequence);
|
|
@@ -1617,7 +1613,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1617
1613
|
}
|
|
1618
1614
|
const currentClass = current.constructor;
|
|
1619
1615
|
if (currentClass === OpaqueReference) {
|
|
1620
|
-
return this.
|
|
1616
|
+
return this.parse(
|
|
1621
1617
|
current.replacement
|
|
1622
1618
|
);
|
|
1623
1619
|
}
|
|
@@ -1714,7 +1710,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1714
1710
|
}
|
|
1715
1711
|
throw new SerovalUnsupportedTypeError(current);
|
|
1716
1712
|
}
|
|
1717
|
-
async
|
|
1713
|
+
async parse(current) {
|
|
1718
1714
|
switch (typeof current) {
|
|
1719
1715
|
case "boolean":
|
|
1720
1716
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -1741,9 +1737,9 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1741
1737
|
throw new SerovalUnsupportedTypeError(current);
|
|
1742
1738
|
}
|
|
1743
1739
|
}
|
|
1744
|
-
async
|
|
1740
|
+
async parseTop(current) {
|
|
1745
1741
|
try {
|
|
1746
|
-
return await this.
|
|
1742
|
+
return await this.parse(current);
|
|
1747
1743
|
} catch (error) {
|
|
1748
1744
|
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
1749
1745
|
}
|
|
@@ -1956,7 +1952,10 @@ var BaseDeserializerContext = class {
|
|
|
1956
1952
|
throw new SerovalMissingPluginError(node.c);
|
|
1957
1953
|
}
|
|
1958
1954
|
deserializePromiseConstructor(node) {
|
|
1959
|
-
return this.assignIndexedValue(
|
|
1955
|
+
return this.assignIndexedValue(
|
|
1956
|
+
node.i,
|
|
1957
|
+
this.assignIndexedValue(node.s, createDeferred()).promise
|
|
1958
|
+
);
|
|
1960
1959
|
}
|
|
1961
1960
|
deserializePromiseResolve(node) {
|
|
1962
1961
|
const deferred = this.refs.get(node.i);
|
|
@@ -2016,83 +2015,86 @@ var BaseDeserializerContext = class {
|
|
|
2016
2015
|
this.deserialize(node.a[1]);
|
|
2017
2016
|
return void 0;
|
|
2018
2017
|
}
|
|
2019
|
-
|
|
2018
|
+
deserializeTop(node) {
|
|
2020
2019
|
try {
|
|
2021
|
-
|
|
2022
|
-
case 2 /* Constant */:
|
|
2023
|
-
return CONSTANT_VAL[node.s];
|
|
2024
|
-
case 0 /* Number */:
|
|
2025
|
-
return node.s;
|
|
2026
|
-
case 1 /* String */:
|
|
2027
|
-
return deserializeString(node.s);
|
|
2028
|
-
case 3 /* BigInt */:
|
|
2029
|
-
return BigInt(node.s);
|
|
2030
|
-
case 4 /* IndexedValue */:
|
|
2031
|
-
return this.refs.get(node.i);
|
|
2032
|
-
case 18 /* Reference */:
|
|
2033
|
-
return this.deserializeReference(node);
|
|
2034
|
-
case 9 /* Array */:
|
|
2035
|
-
return this.deserializeArray(node);
|
|
2036
|
-
case 10 /* Object */:
|
|
2037
|
-
case 11 /* NullConstructor */:
|
|
2038
|
-
return this.deserializeObject(node);
|
|
2039
|
-
case 5 /* Date */:
|
|
2040
|
-
return this.deserializeDate(node);
|
|
2041
|
-
case 6 /* RegExp */:
|
|
2042
|
-
return this.deserializeRegExp(node);
|
|
2043
|
-
case 7 /* Set */:
|
|
2044
|
-
return this.deserializeSet(node);
|
|
2045
|
-
case 8 /* Map */:
|
|
2046
|
-
return this.deserializeMap(node);
|
|
2047
|
-
case 19 /* ArrayBuffer */:
|
|
2048
|
-
return this.deserializeArrayBuffer(node);
|
|
2049
|
-
case 16 /* BigIntTypedArray */:
|
|
2050
|
-
case 15 /* TypedArray */:
|
|
2051
|
-
return this.deserializeTypedArray(node);
|
|
2052
|
-
case 20 /* DataView */:
|
|
2053
|
-
return this.deserializeDataView(node);
|
|
2054
|
-
case 14 /* AggregateError */:
|
|
2055
|
-
return this.deserializeAggregateError(node);
|
|
2056
|
-
case 13 /* Error */:
|
|
2057
|
-
return this.deserializeError(node);
|
|
2058
|
-
case 12 /* Promise */:
|
|
2059
|
-
return this.deserializePromise(node);
|
|
2060
|
-
case 17 /* WKSymbol */:
|
|
2061
|
-
return SYMBOL_REF[node.s];
|
|
2062
|
-
case 21 /* Boxed */:
|
|
2063
|
-
return this.deserializeBoxed(node);
|
|
2064
|
-
case 25 /* Plugin */:
|
|
2065
|
-
return this.deserializePlugin(node);
|
|
2066
|
-
case 22 /* PromiseConstructor */:
|
|
2067
|
-
return this.deserializePromiseConstructor(node);
|
|
2068
|
-
case 23 /* PromiseSuccess */:
|
|
2069
|
-
return this.deserializePromiseResolve(node);
|
|
2070
|
-
case 24 /* PromiseFailure */:
|
|
2071
|
-
return this.deserializePromiseReject(node);
|
|
2072
|
-
case 28 /* IteratorFactoryInstance */:
|
|
2073
|
-
return this.deserializeIteratorFactoryInstance(node);
|
|
2074
|
-
case 30 /* AsyncIteratorFactoryInstance */:
|
|
2075
|
-
return this.deserializeAsyncIteratorFactoryInstance(node);
|
|
2076
|
-
case 31 /* StreamConstructor */:
|
|
2077
|
-
return this.deserializeStreamConstructor(node);
|
|
2078
|
-
case 32 /* StreamNext */:
|
|
2079
|
-
return this.deserializeStreamNext(node);
|
|
2080
|
-
case 33 /* StreamThrow */:
|
|
2081
|
-
return this.deserializeStreamThrow(node);
|
|
2082
|
-
case 34 /* StreamReturn */:
|
|
2083
|
-
return this.deserializeStreamReturn(node);
|
|
2084
|
-
case 27 /* IteratorFactory */:
|
|
2085
|
-
return this.deserializeIteratorFactory(node);
|
|
2086
|
-
case 29 /* AsyncIteratorFactory */:
|
|
2087
|
-
return this.deserializeAsyncIteratorFactory(node);
|
|
2088
|
-
// case SerovalNodeType.SpecialReference:
|
|
2089
|
-
default:
|
|
2090
|
-
throw new SerovalUnsupportedNodeError(node);
|
|
2091
|
-
}
|
|
2020
|
+
return this.deserialize(node);
|
|
2092
2021
|
} catch (error) {
|
|
2093
2022
|
throw new SerovalDeserializationError(error);
|
|
2094
2023
|
}
|
|
2095
2024
|
}
|
|
2025
|
+
deserialize(node) {
|
|
2026
|
+
switch (node.t) {
|
|
2027
|
+
case 2 /* Constant */:
|
|
2028
|
+
return CONSTANT_VAL[node.s];
|
|
2029
|
+
case 0 /* Number */:
|
|
2030
|
+
return node.s;
|
|
2031
|
+
case 1 /* String */:
|
|
2032
|
+
return deserializeString(node.s);
|
|
2033
|
+
case 3 /* BigInt */:
|
|
2034
|
+
return BigInt(node.s);
|
|
2035
|
+
case 4 /* IndexedValue */:
|
|
2036
|
+
return this.refs.get(node.i);
|
|
2037
|
+
case 18 /* Reference */:
|
|
2038
|
+
return this.deserializeReference(node);
|
|
2039
|
+
case 9 /* Array */:
|
|
2040
|
+
return this.deserializeArray(node);
|
|
2041
|
+
case 10 /* Object */:
|
|
2042
|
+
case 11 /* NullConstructor */:
|
|
2043
|
+
return this.deserializeObject(node);
|
|
2044
|
+
case 5 /* Date */:
|
|
2045
|
+
return this.deserializeDate(node);
|
|
2046
|
+
case 6 /* RegExp */:
|
|
2047
|
+
return this.deserializeRegExp(node);
|
|
2048
|
+
case 7 /* Set */:
|
|
2049
|
+
return this.deserializeSet(node);
|
|
2050
|
+
case 8 /* Map */:
|
|
2051
|
+
return this.deserializeMap(node);
|
|
2052
|
+
case 19 /* ArrayBuffer */:
|
|
2053
|
+
return this.deserializeArrayBuffer(node);
|
|
2054
|
+
case 16 /* BigIntTypedArray */:
|
|
2055
|
+
case 15 /* TypedArray */:
|
|
2056
|
+
return this.deserializeTypedArray(node);
|
|
2057
|
+
case 20 /* DataView */:
|
|
2058
|
+
return this.deserializeDataView(node);
|
|
2059
|
+
case 14 /* AggregateError */:
|
|
2060
|
+
return this.deserializeAggregateError(node);
|
|
2061
|
+
case 13 /* Error */:
|
|
2062
|
+
return this.deserializeError(node);
|
|
2063
|
+
case 12 /* Promise */:
|
|
2064
|
+
return this.deserializePromise(node);
|
|
2065
|
+
case 17 /* WKSymbol */:
|
|
2066
|
+
return SYMBOL_REF[node.s];
|
|
2067
|
+
case 21 /* Boxed */:
|
|
2068
|
+
return this.deserializeBoxed(node);
|
|
2069
|
+
case 25 /* Plugin */:
|
|
2070
|
+
return this.deserializePlugin(node);
|
|
2071
|
+
case 22 /* PromiseConstructor */:
|
|
2072
|
+
return this.deserializePromiseConstructor(node);
|
|
2073
|
+
case 23 /* PromiseSuccess */:
|
|
2074
|
+
return this.deserializePromiseResolve(node);
|
|
2075
|
+
case 24 /* PromiseFailure */:
|
|
2076
|
+
return this.deserializePromiseReject(node);
|
|
2077
|
+
case 28 /* IteratorFactoryInstance */:
|
|
2078
|
+
return this.deserializeIteratorFactoryInstance(node);
|
|
2079
|
+
case 30 /* AsyncIteratorFactoryInstance */:
|
|
2080
|
+
return this.deserializeAsyncIteratorFactoryInstance(node);
|
|
2081
|
+
case 31 /* StreamConstructor */:
|
|
2082
|
+
return this.deserializeStreamConstructor(node);
|
|
2083
|
+
case 32 /* StreamNext */:
|
|
2084
|
+
return this.deserializeStreamNext(node);
|
|
2085
|
+
case 33 /* StreamThrow */:
|
|
2086
|
+
return this.deserializeStreamThrow(node);
|
|
2087
|
+
case 34 /* StreamReturn */:
|
|
2088
|
+
return this.deserializeStreamReturn(node);
|
|
2089
|
+
case 27 /* IteratorFactory */:
|
|
2090
|
+
return this.deserializeIteratorFactory(node);
|
|
2091
|
+
case 29 /* AsyncIteratorFactory */:
|
|
2092
|
+
return this.deserializeAsyncIteratorFactory(node);
|
|
2093
|
+
// case SerovalNodeType.SpecialReference:
|
|
2094
|
+
default:
|
|
2095
|
+
throw new SerovalUnsupportedNodeError(node);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2096
2098
|
};
|
|
2097
2099
|
|
|
2098
2100
|
// src/core/cross/deserializer.ts
|
|
@@ -2755,6 +2757,15 @@ var BaseSerializerContext = class {
|
|
|
2755
2757
|
["s"],
|
|
2756
2758
|
this.createFunction(
|
|
2757
2759
|
["b", "c", "p", "d", "e", "t", "f"],
|
|
2760
|
+
/**
|
|
2761
|
+
* b = resolved values
|
|
2762
|
+
* c = b size
|
|
2763
|
+
* p = pending promises
|
|
2764
|
+
* d = index where the resolved value stops
|
|
2765
|
+
* e = if the last value is a throw
|
|
2766
|
+
* t = placeholder variable
|
|
2767
|
+
* f = finalize
|
|
2768
|
+
*/
|
|
2758
2769
|
"(b=[],c=0,p=[],d=-1,e=!1,f=" + this.createEffectfulFunction(
|
|
2759
2770
|
["i", "l"],
|
|
2760
2771
|
"for(i=0,l=p.length;i<l;i++)p[i].s({done:!0,value:void 0})"
|
|
@@ -2767,9 +2778,9 @@ var BaseSerializerContext = class {
|
|
|
2767
2778
|
) + ",return:" + this.createEffectfulFunction(
|
|
2768
2779
|
["v", "t"],
|
|
2769
2780
|
"if(t=p.shift())t.s({done:!0,value:v});f(),d=b.length,b.push(v)"
|
|
2770
|
-
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction(
|
|
2781
|
+
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t.p") + ",next:" + this.createEffectfulFunction(
|
|
2771
2782
|
["i", "t", "v"],
|
|
2772
|
-
"if(d===-1){return((i=c++)>=b.length)?(
|
|
2783
|
+
"if(d===-1){return((i=c++)>=b.length)?(" + this.getRefParam(promise.i) + "(t={p:0,s:0,f:0}),p.push(t),t.p):{done:!1,value:b[i]}}if(c>d)return{done:!0,value:void 0};if(v=b[i=c++],i!==d)return{done:!1,value:v};if(e)throw v;return{done:!0,value:v}"
|
|
2773
2784
|
) + "})"
|
|
2774
2785
|
)
|
|
2775
2786
|
)
|
|
@@ -2927,7 +2938,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2927
2938
|
const nodes = [];
|
|
2928
2939
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
2929
2940
|
if (i in current) {
|
|
2930
|
-
nodes[i] = this.
|
|
2941
|
+
nodes[i] = this.parse(current[i]);
|
|
2931
2942
|
}
|
|
2932
2943
|
}
|
|
2933
2944
|
return nodes;
|
|
@@ -2941,7 +2952,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2941
2952
|
const valueNodes = [];
|
|
2942
2953
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
2943
2954
|
keyNodes.push(serializeString(entries[i][0]));
|
|
2944
|
-
valueNodes.push(this.
|
|
2955
|
+
valueNodes.push(this.parse(entries[i][1]));
|
|
2945
2956
|
}
|
|
2946
2957
|
let symbol = Symbol.iterator;
|
|
2947
2958
|
if (symbol in properties) {
|
|
@@ -2949,7 +2960,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2949
2960
|
valueNodes.push(
|
|
2950
2961
|
createIteratorFactoryInstanceNode(
|
|
2951
2962
|
this.parseIteratorFactory(),
|
|
2952
|
-
this.
|
|
2963
|
+
this.parse(
|
|
2953
2964
|
iteratorToSequence(properties)
|
|
2954
2965
|
)
|
|
2955
2966
|
)
|
|
@@ -2961,7 +2972,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2961
2972
|
valueNodes.push(
|
|
2962
2973
|
createAsyncIteratorFactoryInstanceNode(
|
|
2963
2974
|
this.parseAsyncIteratorFactory(),
|
|
2964
|
-
this.
|
|
2975
|
+
this.parse(createStream())
|
|
2965
2976
|
)
|
|
2966
2977
|
);
|
|
2967
2978
|
}
|
|
@@ -2990,20 +3001,16 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2990
3001
|
);
|
|
2991
3002
|
}
|
|
2992
3003
|
parseBoxed(id, current) {
|
|
2993
|
-
return createBoxedNode(id, this.
|
|
3004
|
+
return createBoxedNode(id, this.parse(current.valueOf()));
|
|
2994
3005
|
}
|
|
2995
3006
|
parseTypedArray(id, current) {
|
|
2996
|
-
return createTypedArrayNode(id, current, this.
|
|
3007
|
+
return createTypedArrayNode(id, current, this.parse(current.buffer));
|
|
2997
3008
|
}
|
|
2998
3009
|
parseBigIntTypedArray(id, current) {
|
|
2999
|
-
return createBigIntTypedArrayNode(
|
|
3000
|
-
id,
|
|
3001
|
-
current,
|
|
3002
|
-
this.parseTop(current.buffer)
|
|
3003
|
-
);
|
|
3010
|
+
return createBigIntTypedArrayNode(id, current, this.parse(current.buffer));
|
|
3004
3011
|
}
|
|
3005
3012
|
parseDataView(id, current) {
|
|
3006
|
-
return createDataViewNode(id, current, this.
|
|
3013
|
+
return createDataViewNode(id, current, this.parse(current.buffer));
|
|
3007
3014
|
}
|
|
3008
3015
|
parseError(id, current) {
|
|
3009
3016
|
const options = getErrorOptions(current, this.features);
|
|
@@ -3025,15 +3032,15 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3025
3032
|
const keyNodes = [];
|
|
3026
3033
|
const valueNodes = [];
|
|
3027
3034
|
for (const [key, value] of current.entries()) {
|
|
3028
|
-
keyNodes.push(this.
|
|
3029
|
-
valueNodes.push(this.
|
|
3035
|
+
keyNodes.push(this.parse(key));
|
|
3036
|
+
valueNodes.push(this.parse(value));
|
|
3030
3037
|
}
|
|
3031
3038
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
3032
3039
|
}
|
|
3033
3040
|
parseSet(id, current) {
|
|
3034
3041
|
const items = [];
|
|
3035
3042
|
for (const item of current.keys()) {
|
|
3036
|
-
items.push(this.
|
|
3043
|
+
items.push(this.parse(item));
|
|
3037
3044
|
}
|
|
3038
3045
|
return createSetNode(id, current.size, items);
|
|
3039
3046
|
}
|
|
@@ -3075,7 +3082,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3075
3082
|
}
|
|
3076
3083
|
const currentClass = current.constructor;
|
|
3077
3084
|
if (currentClass === OpaqueReference) {
|
|
3078
|
-
return this.
|
|
3085
|
+
return this.parse(
|
|
3079
3086
|
current.replacement
|
|
3080
3087
|
);
|
|
3081
3088
|
}
|
|
@@ -3172,7 +3179,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3172
3179
|
}
|
|
3173
3180
|
throw new SerovalUnsupportedTypeError(current);
|
|
3174
3181
|
}
|
|
3175
|
-
|
|
3182
|
+
parse(current) {
|
|
3176
3183
|
switch (typeof current) {
|
|
3177
3184
|
case "boolean":
|
|
3178
3185
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -3200,9 +3207,9 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3200
3207
|
throw new SerovalUnsupportedTypeError(current);
|
|
3201
3208
|
}
|
|
3202
3209
|
}
|
|
3203
|
-
|
|
3210
|
+
parseTop(current) {
|
|
3204
3211
|
try {
|
|
3205
|
-
return this.
|
|
3212
|
+
return this.parse(current);
|
|
3206
3213
|
} catch (error) {
|
|
3207
3214
|
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3208
3215
|
}
|
|
@@ -3268,7 +3275,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3268
3275
|
const valueNodes = [];
|
|
3269
3276
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3270
3277
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3271
|
-
valueNodes.push(this.
|
|
3278
|
+
valueNodes.push(this.parse(entries[i][1]));
|
|
3272
3279
|
}
|
|
3273
3280
|
let symbol = Symbol.iterator;
|
|
3274
3281
|
if (symbol in properties) {
|
|
@@ -3276,7 +3283,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3276
3283
|
valueNodes.push(
|
|
3277
3284
|
createIteratorFactoryInstanceNode(
|
|
3278
3285
|
this.parseIteratorFactory(),
|
|
3279
|
-
this.
|
|
3286
|
+
this.parse(
|
|
3280
3287
|
iteratorToSequence(properties)
|
|
3281
3288
|
)
|
|
3282
3289
|
)
|
|
@@ -3288,7 +3295,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3288
3295
|
valueNodes.push(
|
|
3289
3296
|
createAsyncIteratorFactoryInstanceNode(
|
|
3290
3297
|
this.parseAsyncIteratorFactory(),
|
|
3291
|
-
this.
|
|
3298
|
+
this.parse(
|
|
3292
3299
|
createStreamFromAsyncIterable(
|
|
3293
3300
|
properties
|
|
3294
3301
|
)
|
|
@@ -3427,7 +3434,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3427
3434
|
}
|
|
3428
3435
|
parseWithError(current) {
|
|
3429
3436
|
try {
|
|
3430
|
-
return this.
|
|
3437
|
+
return this.parse(current);
|
|
3431
3438
|
} catch (err) {
|
|
3432
3439
|
this.onError(err);
|
|
3433
3440
|
return NIL;
|
|
@@ -3485,7 +3492,7 @@ function crossSerialize(source, options = {}) {
|
|
|
3485
3492
|
disabledFeatures: options.disabledFeatures,
|
|
3486
3493
|
refs: options.refs
|
|
3487
3494
|
});
|
|
3488
|
-
const tree = ctx.
|
|
3495
|
+
const tree = ctx.parseTop(source);
|
|
3489
3496
|
const serial = new CrossSerializerContext({
|
|
3490
3497
|
plugins,
|
|
3491
3498
|
features: ctx.features,
|
|
@@ -3501,7 +3508,7 @@ async function crossSerializeAsync(source, options = {}) {
|
|
|
3501
3508
|
disabledFeatures: options.disabledFeatures,
|
|
3502
3509
|
refs: options.refs
|
|
3503
3510
|
});
|
|
3504
|
-
const tree = await ctx.
|
|
3511
|
+
const tree = await ctx.parseTop(source);
|
|
3505
3512
|
const serial = new CrossSerializerContext({
|
|
3506
3513
|
plugins,
|
|
3507
3514
|
features: ctx.features,
|
|
@@ -3517,7 +3524,7 @@ function toCrossJSON(source, options = {}) {
|
|
|
3517
3524
|
disabledFeatures: options.disabledFeatures,
|
|
3518
3525
|
refs: options.refs
|
|
3519
3526
|
});
|
|
3520
|
-
return ctx.
|
|
3527
|
+
return ctx.parseTop(source);
|
|
3521
3528
|
}
|
|
3522
3529
|
async function toCrossJSONAsync(source, options = {}) {
|
|
3523
3530
|
const plugins = resolvePlugins(options.plugins);
|
|
@@ -3526,7 +3533,7 @@ async function toCrossJSONAsync(source, options = {}) {
|
|
|
3526
3533
|
disabledFeatures: options.disabledFeatures,
|
|
3527
3534
|
refs: options.refs
|
|
3528
3535
|
});
|
|
3529
|
-
return await ctx.
|
|
3536
|
+
return await ctx.parseTop(source);
|
|
3530
3537
|
}
|
|
3531
3538
|
function crossSerializeStream(source, options) {
|
|
3532
3539
|
const plugins = resolvePlugins(options.plugins);
|
|
@@ -3577,7 +3584,7 @@ function fromCrossJSON(source, options) {
|
|
|
3577
3584
|
plugins,
|
|
3578
3585
|
refs: options.refs
|
|
3579
3586
|
});
|
|
3580
|
-
return ctx.
|
|
3587
|
+
return ctx.deserializeTop(source);
|
|
3581
3588
|
}
|
|
3582
3589
|
|
|
3583
3590
|
// src/core/tree/async.ts
|
|
@@ -3705,7 +3712,7 @@ function serialize(source, options = {}) {
|
|
|
3705
3712
|
plugins,
|
|
3706
3713
|
disabledFeatures: options.disabledFeatures
|
|
3707
3714
|
});
|
|
3708
|
-
const tree = ctx.
|
|
3715
|
+
const tree = ctx.parseTop(source);
|
|
3709
3716
|
const serial = new VanillaSerializerContext({
|
|
3710
3717
|
plugins,
|
|
3711
3718
|
features: ctx.features,
|
|
@@ -3719,7 +3726,7 @@ async function serializeAsync(source, options = {}) {
|
|
|
3719
3726
|
plugins,
|
|
3720
3727
|
disabledFeatures: options.disabledFeatures
|
|
3721
3728
|
});
|
|
3722
|
-
const tree = await ctx.
|
|
3729
|
+
const tree = await ctx.parseTop(source);
|
|
3723
3730
|
const serial = new VanillaSerializerContext({
|
|
3724
3731
|
plugins,
|
|
3725
3732
|
features: ctx.features,
|
|
@@ -3737,7 +3744,7 @@ function toJSON(source, options = {}) {
|
|
|
3737
3744
|
disabledFeatures: options.disabledFeatures
|
|
3738
3745
|
});
|
|
3739
3746
|
return {
|
|
3740
|
-
t: ctx.
|
|
3747
|
+
t: ctx.parseTop(source),
|
|
3741
3748
|
f: ctx.features,
|
|
3742
3749
|
m: Array.from(ctx.marked)
|
|
3743
3750
|
};
|
|
@@ -3749,7 +3756,7 @@ async function toJSONAsync(source, options = {}) {
|
|
|
3749
3756
|
disabledFeatures: options.disabledFeatures
|
|
3750
3757
|
});
|
|
3751
3758
|
return {
|
|
3752
|
-
t: await ctx.
|
|
3759
|
+
t: await ctx.parseTop(source),
|
|
3753
3760
|
f: ctx.features,
|
|
3754
3761
|
m: Array.from(ctx.marked)
|
|
3755
3762
|
};
|
|
@@ -3769,7 +3776,7 @@ function fromJSON(source, options = {}) {
|
|
|
3769
3776
|
plugins,
|
|
3770
3777
|
markedRefs: source.m
|
|
3771
3778
|
});
|
|
3772
|
-
return ctx.
|
|
3779
|
+
return ctx.deserializeTop(source.t);
|
|
3773
3780
|
}
|
|
3774
3781
|
|
|
3775
3782
|
// src/core/Serializer.ts
|