seroval 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -9
- package/dist/cjs/development/index.cjs +145 -139
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +145 -139
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/context.d.ts +2 -4
- package/dist/types/tree/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/context.ts +35 -45
- package/src/tree/async.ts +21 -19
- package/src/tree/deserialize.ts +1 -1
- package/src/tree/primitives.ts +21 -21
- package/src/tree/serialize.ts +65 -65
- package/src/tree/sync.ts +20 -18
- package/src/tree/types.ts +3 -3
|
@@ -61,35 +61,35 @@ function createSerializationContext(options) {
|
|
|
61
61
|
function markRef(ctx, current) {
|
|
62
62
|
ctx.markedRefs.add(current);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
ctx.validRefs[index] =
|
|
69
|
-
|
|
64
|
+
function getRefParam(ctx, index) {
|
|
65
|
+
let actualIndex = ctx.validRefs[index];
|
|
66
|
+
if (actualIndex == null) {
|
|
67
|
+
actualIndex = ctx.refSize++;
|
|
68
|
+
ctx.validRefs[index] = actualIndex;
|
|
69
|
+
}
|
|
70
|
+
let identifier = ctx.vars[actualIndex];
|
|
71
|
+
if (identifier == null) {
|
|
72
|
+
identifier = getIdentifier(actualIndex);
|
|
73
|
+
ctx.vars[actualIndex] = identifier;
|
|
70
74
|
}
|
|
71
|
-
return
|
|
75
|
+
return identifier;
|
|
72
76
|
}
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return ctx.
|
|
77
|
+
function getRootID(ctx, current) {
|
|
78
|
+
const ref = ctx.refs.get(current);
|
|
79
|
+
if (ref == null) {
|
|
80
|
+
return ctx.refs.size;
|
|
77
81
|
}
|
|
78
|
-
|
|
79
|
-
ctx.vars[actualIndex] = result;
|
|
80
|
-
return result;
|
|
82
|
+
return ref;
|
|
81
83
|
}
|
|
82
|
-
function createRef(ctx, current
|
|
84
|
+
function createRef(ctx, current) {
|
|
83
85
|
const ref = ctx.refs.get(current);
|
|
84
|
-
if (ref
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return ref;
|
|
86
|
+
if (ref == null) {
|
|
87
|
+
const id = ctx.refs.size;
|
|
88
|
+
ctx.refs.set(current, id);
|
|
89
|
+
return id;
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return id;
|
|
91
|
+
markRef(ctx, ref);
|
|
92
|
+
return ref;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// src/assert.ts
|
|
@@ -201,7 +201,7 @@ var TRUE_NODE = {
|
|
|
201
201
|
m: void 0,
|
|
202
202
|
d: void 0,
|
|
203
203
|
a: void 0,
|
|
204
|
-
|
|
204
|
+
f: void 0
|
|
205
205
|
};
|
|
206
206
|
var FALSE_NODE = {
|
|
207
207
|
t: 2 /* Boolean */,
|
|
@@ -212,7 +212,7 @@ var FALSE_NODE = {
|
|
|
212
212
|
m: void 0,
|
|
213
213
|
d: void 0,
|
|
214
214
|
a: void 0,
|
|
215
|
-
|
|
215
|
+
f: void 0
|
|
216
216
|
};
|
|
217
217
|
var UNDEFINED_NODE = {
|
|
218
218
|
t: 4 /* Undefined */,
|
|
@@ -223,7 +223,7 @@ var UNDEFINED_NODE = {
|
|
|
223
223
|
m: void 0,
|
|
224
224
|
d: void 0,
|
|
225
225
|
a: void 0,
|
|
226
|
-
|
|
226
|
+
f: void 0
|
|
227
227
|
};
|
|
228
228
|
var NULL_NODE = {
|
|
229
229
|
t: 3 /* Null */,
|
|
@@ -234,7 +234,7 @@ var NULL_NODE = {
|
|
|
234
234
|
m: void 0,
|
|
235
235
|
d: void 0,
|
|
236
236
|
a: void 0,
|
|
237
|
-
|
|
237
|
+
f: void 0
|
|
238
238
|
};
|
|
239
239
|
var NEG_ZERO_NODE = {
|
|
240
240
|
t: 5 /* NegativeZero */,
|
|
@@ -245,7 +245,7 @@ var NEG_ZERO_NODE = {
|
|
|
245
245
|
m: void 0,
|
|
246
246
|
d: void 0,
|
|
247
247
|
a: void 0,
|
|
248
|
-
|
|
248
|
+
f: void 0
|
|
249
249
|
};
|
|
250
250
|
var INFINITY_NODE = {
|
|
251
251
|
t: 6 /* Infinity */,
|
|
@@ -256,7 +256,7 @@ var INFINITY_NODE = {
|
|
|
256
256
|
m: void 0,
|
|
257
257
|
d: void 0,
|
|
258
258
|
a: void 0,
|
|
259
|
-
|
|
259
|
+
f: void 0
|
|
260
260
|
};
|
|
261
261
|
var NEG_INFINITY_NODE = {
|
|
262
262
|
t: 7 /* NegativeInfinity */,
|
|
@@ -267,7 +267,7 @@ var NEG_INFINITY_NODE = {
|
|
|
267
267
|
m: void 0,
|
|
268
268
|
d: void 0,
|
|
269
269
|
a: void 0,
|
|
270
|
-
|
|
270
|
+
f: void 0
|
|
271
271
|
};
|
|
272
272
|
var NAN_NODE = {
|
|
273
273
|
t: 8 /* NaN */,
|
|
@@ -278,7 +278,7 @@ var NAN_NODE = {
|
|
|
278
278
|
m: void 0,
|
|
279
279
|
d: void 0,
|
|
280
280
|
a: void 0,
|
|
281
|
-
|
|
281
|
+
f: void 0
|
|
282
282
|
};
|
|
283
283
|
function createNumberNode(value) {
|
|
284
284
|
return {
|
|
@@ -290,7 +290,7 @@ function createNumberNode(value) {
|
|
|
290
290
|
m: void 0,
|
|
291
291
|
d: void 0,
|
|
292
292
|
a: void 0,
|
|
293
|
-
|
|
293
|
+
f: void 0
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
function createStringNode(value) {
|
|
@@ -303,7 +303,7 @@ function createStringNode(value) {
|
|
|
303
303
|
m: void 0,
|
|
304
304
|
d: void 0,
|
|
305
305
|
a: void 0,
|
|
306
|
-
|
|
306
|
+
f: void 0
|
|
307
307
|
};
|
|
308
308
|
}
|
|
309
309
|
function createBigIntNode(ctx, current) {
|
|
@@ -311,13 +311,13 @@ function createBigIntNode(ctx, current) {
|
|
|
311
311
|
return {
|
|
312
312
|
t: 9 /* BigInt */,
|
|
313
313
|
i: void 0,
|
|
314
|
-
s: current
|
|
314
|
+
s: "" + current,
|
|
315
315
|
l: void 0,
|
|
316
316
|
c: void 0,
|
|
317
317
|
m: void 0,
|
|
318
318
|
d: void 0,
|
|
319
319
|
a: void 0,
|
|
320
|
-
|
|
320
|
+
f: void 0
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
323
|
function createReferenceNode(id) {
|
|
@@ -330,7 +330,7 @@ function createReferenceNode(id) {
|
|
|
330
330
|
m: void 0,
|
|
331
331
|
d: void 0,
|
|
332
332
|
a: void 0,
|
|
333
|
-
|
|
333
|
+
f: void 0
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
336
|
function createDateNode(id, current) {
|
|
@@ -342,7 +342,7 @@ function createDateNode(id, current) {
|
|
|
342
342
|
c: void 0,
|
|
343
343
|
m: void 0,
|
|
344
344
|
d: void 0,
|
|
345
|
-
|
|
345
|
+
f: void 0,
|
|
346
346
|
a: void 0
|
|
347
347
|
};
|
|
348
348
|
}
|
|
@@ -356,7 +356,7 @@ function createRegExpNode(id, current) {
|
|
|
356
356
|
m: current.flags,
|
|
357
357
|
d: void 0,
|
|
358
358
|
a: void 0,
|
|
359
|
-
|
|
359
|
+
f: void 0
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
362
|
function createTypedArrayNode(ctx, id, current) {
|
|
@@ -365,7 +365,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
365
365
|
const len = current.length;
|
|
366
366
|
const values = new Array(len);
|
|
367
367
|
for (let i = 0; i < len; i++) {
|
|
368
|
-
values[i] = current[i]
|
|
368
|
+
values[i] = "" + current[i];
|
|
369
369
|
}
|
|
370
370
|
return {
|
|
371
371
|
t: 22 /* TypedArray */,
|
|
@@ -376,7 +376,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
376
376
|
m: void 0,
|
|
377
377
|
d: void 0,
|
|
378
378
|
a: void 0,
|
|
379
|
-
|
|
379
|
+
f: void 0
|
|
380
380
|
};
|
|
381
381
|
}
|
|
382
382
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -389,7 +389,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
389
389
|
const len = current.length;
|
|
390
390
|
const values = new Array(len);
|
|
391
391
|
for (let i = 0; i < len; i++) {
|
|
392
|
-
values[i] = current[i]
|
|
392
|
+
values[i] = "" + current[i];
|
|
393
393
|
}
|
|
394
394
|
return {
|
|
395
395
|
t: 23 /* BigIntTypedArray */,
|
|
@@ -400,7 +400,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
400
400
|
m: void 0,
|
|
401
401
|
d: void 0,
|
|
402
402
|
a: void 0,
|
|
403
|
-
|
|
403
|
+
f: void 0
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
406
|
function createWKSymbolNode(current) {
|
|
@@ -413,7 +413,7 @@ function createWKSymbolNode(current) {
|
|
|
413
413
|
m: void 0,
|
|
414
414
|
d: void 0,
|
|
415
415
|
a: void 0,
|
|
416
|
-
|
|
416
|
+
f: void 0
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
419
|
|
|
@@ -588,7 +588,7 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
588
588
|
m: void 0,
|
|
589
589
|
d: void 0,
|
|
590
590
|
a: await generateNodeList(ctx, current),
|
|
591
|
-
|
|
591
|
+
f: void 0
|
|
592
592
|
};
|
|
593
593
|
}
|
|
594
594
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -624,7 +624,7 @@ async function generateMapNode(ctx, id, current) {
|
|
|
624
624
|
m: void 0,
|
|
625
625
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
626
626
|
a: void 0,
|
|
627
|
-
|
|
627
|
+
f: void 0
|
|
628
628
|
};
|
|
629
629
|
}
|
|
630
630
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -653,7 +653,7 @@ async function generateSetNode(ctx, id, current) {
|
|
|
653
653
|
m: void 0,
|
|
654
654
|
d: void 0,
|
|
655
655
|
a: nodes,
|
|
656
|
-
|
|
656
|
+
f: void 0
|
|
657
657
|
};
|
|
658
658
|
}
|
|
659
659
|
async function generateProperties(ctx, properties) {
|
|
@@ -702,7 +702,7 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
702
702
|
// Parse options first before the items
|
|
703
703
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
704
704
|
a: await generateNodeList(ctx, array),
|
|
705
|
-
|
|
705
|
+
f: void 0
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
708
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -717,7 +717,7 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
717
717
|
// Parse options first before the items
|
|
718
718
|
d: void 0,
|
|
719
719
|
a: void 0,
|
|
720
|
-
|
|
720
|
+
f: await parse(ctx, value)
|
|
721
721
|
}));
|
|
722
722
|
}
|
|
723
723
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -736,7 +736,7 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
736
736
|
m: void 0,
|
|
737
737
|
d: await generateProperties(ctx, current),
|
|
738
738
|
a: void 0,
|
|
739
|
-
|
|
739
|
+
f: void 0
|
|
740
740
|
};
|
|
741
741
|
}
|
|
742
742
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -751,7 +751,7 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
751
751
|
m: current.message,
|
|
752
752
|
d: optionsNode,
|
|
753
753
|
a: await generateNodeList(ctx, current.errors),
|
|
754
|
-
|
|
754
|
+
f: void 0
|
|
755
755
|
};
|
|
756
756
|
}
|
|
757
757
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -766,7 +766,7 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
766
766
|
m: current.message,
|
|
767
767
|
d: optionsNode,
|
|
768
768
|
a: void 0,
|
|
769
|
-
|
|
769
|
+
f: void 0
|
|
770
770
|
};
|
|
771
771
|
}
|
|
772
772
|
async function parse(ctx, current) {
|
|
@@ -778,18 +778,20 @@ async function parse(ctx, current) {
|
|
|
778
778
|
case "string":
|
|
779
779
|
return createStringNode(current);
|
|
780
780
|
case "number":
|
|
781
|
+
switch (current) {
|
|
782
|
+
case Infinity:
|
|
783
|
+
return INFINITY_NODE;
|
|
784
|
+
case -Infinity:
|
|
785
|
+
return NEG_INFINITY_NODE;
|
|
786
|
+
default:
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
781
789
|
if (current !== current) {
|
|
782
790
|
return NAN_NODE;
|
|
783
791
|
}
|
|
784
792
|
if (Object.is(current, -0)) {
|
|
785
793
|
return NEG_ZERO_NODE;
|
|
786
794
|
}
|
|
787
|
-
if (Object.is(current, Infinity)) {
|
|
788
|
-
return INFINITY_NODE;
|
|
789
|
-
}
|
|
790
|
-
if (Object.is(current, -Infinity)) {
|
|
791
|
-
return NEG_INFINITY_NODE;
|
|
792
|
-
}
|
|
793
795
|
return createNumberNode(current);
|
|
794
796
|
case "bigint":
|
|
795
797
|
return createBigIntNode(ctx, current);
|
|
@@ -797,7 +799,7 @@ async function parse(ctx, current) {
|
|
|
797
799
|
if (!current) {
|
|
798
800
|
return NULL_NODE;
|
|
799
801
|
}
|
|
800
|
-
const id = createRef(ctx, current
|
|
802
|
+
const id = createRef(ctx, current);
|
|
801
803
|
if (ctx.markedRefs.has(id)) {
|
|
802
804
|
return createReferenceNode(id);
|
|
803
805
|
}
|
|
@@ -866,8 +868,11 @@ async function parse(ctx, current) {
|
|
|
866
868
|
default:
|
|
867
869
|
break;
|
|
868
870
|
}
|
|
869
|
-
if (current instanceof AggregateError
|
|
870
|
-
|
|
871
|
+
if (current instanceof AggregateError) {
|
|
872
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
873
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
874
|
+
}
|
|
875
|
+
return generateErrorNode(ctx, id, current);
|
|
871
876
|
}
|
|
872
877
|
if (current instanceof Error) {
|
|
873
878
|
return generateErrorNode(ctx, id, current);
|
|
@@ -894,7 +899,7 @@ async function parse(ctx, current) {
|
|
|
894
899
|
async function parseAsync(ctx, current) {
|
|
895
900
|
const result = await parse(ctx, current);
|
|
896
901
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
897
|
-
return [result,
|
|
902
|
+
return [result, getRootID(ctx, current), isObject];
|
|
898
903
|
}
|
|
899
904
|
|
|
900
905
|
// src/tree/deserialize.ts
|
|
@@ -1006,7 +1011,7 @@ function createDeferred() {
|
|
|
1006
1011
|
function deserializePromise(ctx, node) {
|
|
1007
1012
|
const deferred = createDeferred();
|
|
1008
1013
|
const result = assignRef(ctx, node.i, deferred.promise);
|
|
1009
|
-
deferred.resolve(deserializeTree(ctx, node.
|
|
1014
|
+
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1010
1015
|
return result;
|
|
1011
1016
|
}
|
|
1012
1017
|
function deserializeTypedArray(ctx, node) {
|
|
@@ -1105,30 +1110,48 @@ function mergeAssignments(assignments) {
|
|
|
1105
1110
|
for (let i = 1, len = assignments.length; i < len; i++) {
|
|
1106
1111
|
item = assignments[i];
|
|
1107
1112
|
if (item.t === prev.t) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1113
|
+
switch (item.t) {
|
|
1114
|
+
case "index":
|
|
1115
|
+
if (item.v === prev.v) {
|
|
1116
|
+
current = {
|
|
1117
|
+
t: "index",
|
|
1118
|
+
s: item.s,
|
|
1119
|
+
k: void 0,
|
|
1120
|
+
v: getAssignmentExpression(current)
|
|
1121
|
+
};
|
|
1122
|
+
} else {
|
|
1123
|
+
newAssignments.push(current);
|
|
1124
|
+
current = item;
|
|
1125
|
+
}
|
|
1126
|
+
break;
|
|
1127
|
+
case "map":
|
|
1128
|
+
if (item.s === prev.s) {
|
|
1129
|
+
current = {
|
|
1130
|
+
t: "map",
|
|
1131
|
+
s: getAssignmentExpression(current),
|
|
1132
|
+
k: item.k,
|
|
1133
|
+
v: item.v
|
|
1134
|
+
};
|
|
1135
|
+
} else {
|
|
1136
|
+
newAssignments.push(current);
|
|
1137
|
+
current = item;
|
|
1138
|
+
}
|
|
1139
|
+
break;
|
|
1140
|
+
case "set":
|
|
1141
|
+
if (item.s === prev.s) {
|
|
1142
|
+
current = {
|
|
1143
|
+
t: "set",
|
|
1144
|
+
s: getAssignmentExpression(current),
|
|
1145
|
+
k: void 0,
|
|
1146
|
+
v: item.v
|
|
1147
|
+
};
|
|
1148
|
+
} else {
|
|
1149
|
+
newAssignments.push(current);
|
|
1150
|
+
current = item;
|
|
1151
|
+
}
|
|
1152
|
+
break;
|
|
1153
|
+
default:
|
|
1154
|
+
break;
|
|
1132
1155
|
}
|
|
1133
1156
|
} else {
|
|
1134
1157
|
newAssignments.push(current);
|
|
@@ -1181,7 +1204,7 @@ function createMapSet(ctx, ref, key, value) {
|
|
|
1181
1204
|
}
|
|
1182
1205
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1183
1206
|
markRef(ctx, ref);
|
|
1184
|
-
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index
|
|
1207
|
+
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1185
1208
|
}
|
|
1186
1209
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1187
1210
|
markRef(ctx, ref);
|
|
@@ -1218,10 +1241,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1218
1241
|
isHoley = true;
|
|
1219
1242
|
}
|
|
1220
1243
|
}
|
|
1221
|
-
|
|
1222
|
-
values += ",";
|
|
1223
|
-
}
|
|
1224
|
-
return "[" + values + "]";
|
|
1244
|
+
return "[" + values + (isHoley ? ",]" : "]");
|
|
1225
1245
|
}
|
|
1226
1246
|
function serializeArray(ctx, node) {
|
|
1227
1247
|
ctx.stack.push(node.i);
|
|
@@ -1254,11 +1274,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1254
1274
|
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
|
|
1255
1275
|
}
|
|
1256
1276
|
} else {
|
|
1257
|
-
|
|
1258
|
-
result += ",";
|
|
1259
|
-
}
|
|
1260
|
-
result += isIdentifier ? key : '"' + quote(key) + '"';
|
|
1261
|
-
result += ":" + serializeTree(ctx, val);
|
|
1277
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
|
|
1262
1278
|
hasPrev = true;
|
|
1263
1279
|
}
|
|
1264
1280
|
}
|
|
@@ -1309,8 +1325,7 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1309
1325
|
markRef(ctx, i);
|
|
1310
1326
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1311
1327
|
if (assignments) {
|
|
1312
|
-
|
|
1313
|
-
return "(" + assignRef2(ctx, i, init) + "," + assignments + ref + ")";
|
|
1328
|
+
return "(" + assignRef2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1314
1329
|
}
|
|
1315
1330
|
}
|
|
1316
1331
|
}
|
|
@@ -1335,10 +1350,7 @@ function serializeSet(ctx, node) {
|
|
|
1335
1350
|
if (isReferenceInStack(ctx, item)) {
|
|
1336
1351
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1337
1352
|
} else {
|
|
1338
|
-
|
|
1339
|
-
result += ",";
|
|
1340
|
-
}
|
|
1341
|
-
result += serializeTree(ctx, item);
|
|
1353
|
+
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1342
1354
|
hasPrev = true;
|
|
1343
1355
|
}
|
|
1344
1356
|
}
|
|
@@ -1381,10 +1393,7 @@ function serializeMap(ctx, node) {
|
|
|
1381
1393
|
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1382
1394
|
ctx.stack = parent;
|
|
1383
1395
|
} else {
|
|
1384
|
-
|
|
1385
|
-
result += ",";
|
|
1386
|
-
}
|
|
1387
|
-
result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1396
|
+
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1388
1397
|
hasPrev = true;
|
|
1389
1398
|
}
|
|
1390
1399
|
}
|
|
@@ -1407,8 +1416,8 @@ function serializeError(ctx, node) {
|
|
|
1407
1416
|
}
|
|
1408
1417
|
function serializePromise(ctx, node) {
|
|
1409
1418
|
let serialized;
|
|
1410
|
-
if (isReferenceInStack(ctx, node.
|
|
1411
|
-
const ref = getRefParam(ctx, node.
|
|
1419
|
+
if (isReferenceInStack(ctx, node.f)) {
|
|
1420
|
+
const ref = getRefParam(ctx, node.f.i);
|
|
1412
1421
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1413
1422
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1414
1423
|
} else {
|
|
@@ -1416,7 +1425,7 @@ function serializePromise(ctx, node) {
|
|
|
1416
1425
|
}
|
|
1417
1426
|
} else {
|
|
1418
1427
|
ctx.stack.push(node.i);
|
|
1419
|
-
const result = serializeTree(ctx, node.
|
|
1428
|
+
const result = serializeTree(ctx, node.f);
|
|
1420
1429
|
ctx.stack.pop();
|
|
1421
1430
|
serialized = "Promise.resolve(" + result + ")";
|
|
1422
1431
|
}
|
|
@@ -1424,19 +1433,11 @@ function serializePromise(ctx, node) {
|
|
|
1424
1433
|
}
|
|
1425
1434
|
function serializeTypedArray(ctx, node) {
|
|
1426
1435
|
let result = "";
|
|
1436
|
+
const isBigInt = node.t === 23 /* BigIntTypedArray */;
|
|
1427
1437
|
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1428
|
-
|
|
1429
|
-
result += ",";
|
|
1430
|
-
}
|
|
1431
|
-
result += node.s[i];
|
|
1432
|
-
if (node.t === 23 /* BigIntTypedArray */) {
|
|
1433
|
-
result += "n";
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
let args = "[" + result + "]";
|
|
1437
|
-
if (node.l !== 0) {
|
|
1438
|
-
args += "," + node.l.toString();
|
|
1438
|
+
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1439
1439
|
}
|
|
1440
|
+
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1440
1441
|
return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1441
1442
|
}
|
|
1442
1443
|
function serializeIterable(ctx, node) {
|
|
@@ -1462,13 +1463,13 @@ function serializeIterable(ctx, node) {
|
|
|
1462
1463
|
function serializeTree(ctx, node) {
|
|
1463
1464
|
switch (node.t) {
|
|
1464
1465
|
case 0 /* Number */:
|
|
1465
|
-
return
|
|
1466
|
+
return "" + node.s;
|
|
1466
1467
|
case 1 /* String */:
|
|
1467
1468
|
return '"' + node.s + '"';
|
|
1468
1469
|
case 2 /* Boolean */:
|
|
1469
1470
|
return node.s ? "!0" : "!1";
|
|
1470
1471
|
case 4 /* Undefined */:
|
|
1471
|
-
return "
|
|
1472
|
+
return "void 0";
|
|
1472
1473
|
case 3 /* Null */:
|
|
1473
1474
|
return "null";
|
|
1474
1475
|
case 5 /* NegativeZero */:
|
|
@@ -1548,7 +1549,7 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1548
1549
|
m: void 0,
|
|
1549
1550
|
d: void 0,
|
|
1550
1551
|
a: generateNodeList2(ctx, current),
|
|
1551
|
-
|
|
1552
|
+
f: void 0
|
|
1552
1553
|
};
|
|
1553
1554
|
}
|
|
1554
1555
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1584,7 +1585,7 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1584
1585
|
m: void 0,
|
|
1585
1586
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1586
1587
|
a: void 0,
|
|
1587
|
-
|
|
1588
|
+
f: void 0
|
|
1588
1589
|
};
|
|
1589
1590
|
}
|
|
1590
1591
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1613,7 +1614,7 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1613
1614
|
m: void 0,
|
|
1614
1615
|
d: void 0,
|
|
1615
1616
|
a: nodes,
|
|
1616
|
-
|
|
1617
|
+
f: void 0
|
|
1617
1618
|
};
|
|
1618
1619
|
}
|
|
1619
1620
|
function generateProperties2(ctx, properties) {
|
|
@@ -1662,7 +1663,7 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1662
1663
|
// Parse options first before the items
|
|
1663
1664
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1664
1665
|
a: generateNodeList2(ctx, array),
|
|
1665
|
-
|
|
1666
|
+
f: void 0
|
|
1666
1667
|
};
|
|
1667
1668
|
}
|
|
1668
1669
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1678,7 +1679,7 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1678
1679
|
m: void 0,
|
|
1679
1680
|
d: generateProperties2(ctx, current),
|
|
1680
1681
|
a: void 0,
|
|
1681
|
-
|
|
1682
|
+
f: void 0
|
|
1682
1683
|
};
|
|
1683
1684
|
}
|
|
1684
1685
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1693,7 +1694,7 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1693
1694
|
m: current.message,
|
|
1694
1695
|
d: optionsNode,
|
|
1695
1696
|
a: generateNodeList2(ctx, current.errors),
|
|
1696
|
-
|
|
1697
|
+
f: void 0
|
|
1697
1698
|
};
|
|
1698
1699
|
}
|
|
1699
1700
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1708,7 +1709,7 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1708
1709
|
m: current.message,
|
|
1709
1710
|
d: optionsNode,
|
|
1710
1711
|
a: void 0,
|
|
1711
|
-
|
|
1712
|
+
f: void 0
|
|
1712
1713
|
};
|
|
1713
1714
|
}
|
|
1714
1715
|
function parse2(ctx, current) {
|
|
@@ -1720,18 +1721,20 @@ function parse2(ctx, current) {
|
|
|
1720
1721
|
case "string":
|
|
1721
1722
|
return createStringNode(current);
|
|
1722
1723
|
case "number":
|
|
1724
|
+
switch (current) {
|
|
1725
|
+
case Infinity:
|
|
1726
|
+
return INFINITY_NODE;
|
|
1727
|
+
case -Infinity:
|
|
1728
|
+
return NEG_INFINITY_NODE;
|
|
1729
|
+
default:
|
|
1730
|
+
break;
|
|
1731
|
+
}
|
|
1723
1732
|
if (current !== current) {
|
|
1724
1733
|
return NAN_NODE;
|
|
1725
1734
|
}
|
|
1726
1735
|
if (Object.is(current, -0)) {
|
|
1727
1736
|
return NEG_ZERO_NODE;
|
|
1728
1737
|
}
|
|
1729
|
-
if (Object.is(current, Infinity)) {
|
|
1730
|
-
return INFINITY_NODE;
|
|
1731
|
-
}
|
|
1732
|
-
if (Object.is(current, -Infinity)) {
|
|
1733
|
-
return NEG_INFINITY_NODE;
|
|
1734
|
-
}
|
|
1735
1738
|
return createNumberNode(current);
|
|
1736
1739
|
case "bigint":
|
|
1737
1740
|
return createBigIntNode(ctx, current);
|
|
@@ -1739,7 +1742,7 @@ function parse2(ctx, current) {
|
|
|
1739
1742
|
if (!current) {
|
|
1740
1743
|
return NULL_NODE;
|
|
1741
1744
|
}
|
|
1742
|
-
const id = createRef(ctx, current
|
|
1745
|
+
const id = createRef(ctx, current);
|
|
1743
1746
|
if (ctx.markedRefs.has(id)) {
|
|
1744
1747
|
return createReferenceNode(id);
|
|
1745
1748
|
}
|
|
@@ -1788,8 +1791,11 @@ function parse2(ctx, current) {
|
|
|
1788
1791
|
default:
|
|
1789
1792
|
break;
|
|
1790
1793
|
}
|
|
1791
|
-
if (current instanceof AggregateError
|
|
1792
|
-
|
|
1794
|
+
if (current instanceof AggregateError) {
|
|
1795
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1796
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1797
|
+
}
|
|
1798
|
+
return generateErrorNode2(ctx, id, current);
|
|
1793
1799
|
}
|
|
1794
1800
|
if (current instanceof Error) {
|
|
1795
1801
|
return generateErrorNode2(ctx, id, current);
|
|
@@ -1810,7 +1816,7 @@ function parse2(ctx, current) {
|
|
|
1810
1816
|
function parseSync(ctx, current) {
|
|
1811
1817
|
const result = parse2(ctx, current);
|
|
1812
1818
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
1813
|
-
return [result,
|
|
1819
|
+
return [result, getRootID(ctx, current), isObject];
|
|
1814
1820
|
}
|
|
1815
1821
|
|
|
1816
1822
|
// src/index.ts
|