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
|
@@ -95,35 +95,35 @@ function createSerializationContext(options) {
|
|
|
95
95
|
function markRef(ctx, current) {
|
|
96
96
|
ctx.markedRefs.add(current);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
ctx.validRefs[index] =
|
|
103
|
-
|
|
98
|
+
function getRefParam(ctx, index) {
|
|
99
|
+
let actualIndex = ctx.validRefs[index];
|
|
100
|
+
if (actualIndex == null) {
|
|
101
|
+
actualIndex = ctx.refSize++;
|
|
102
|
+
ctx.validRefs[index] = actualIndex;
|
|
103
|
+
}
|
|
104
|
+
let identifier = ctx.vars[actualIndex];
|
|
105
|
+
if (identifier == null) {
|
|
106
|
+
identifier = getIdentifier(actualIndex);
|
|
107
|
+
ctx.vars[actualIndex] = identifier;
|
|
104
108
|
}
|
|
105
|
-
return
|
|
109
|
+
return identifier;
|
|
106
110
|
}
|
|
107
|
-
function
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
return ctx.
|
|
111
|
+
function getRootID(ctx, current) {
|
|
112
|
+
const ref = ctx.refs.get(current);
|
|
113
|
+
if (ref == null) {
|
|
114
|
+
return ctx.refs.size;
|
|
111
115
|
}
|
|
112
|
-
|
|
113
|
-
ctx.vars[actualIndex] = result;
|
|
114
|
-
return result;
|
|
116
|
+
return ref;
|
|
115
117
|
}
|
|
116
|
-
function createRef(ctx, current
|
|
118
|
+
function createRef(ctx, current) {
|
|
117
119
|
const ref = ctx.refs.get(current);
|
|
118
|
-
if (ref
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return ref;
|
|
120
|
+
if (ref == null) {
|
|
121
|
+
const id = ctx.refs.size;
|
|
122
|
+
ctx.refs.set(current, id);
|
|
123
|
+
return id;
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return id;
|
|
125
|
+
markRef(ctx, ref);
|
|
126
|
+
return ref;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// src/assert.ts
|
|
@@ -235,7 +235,7 @@ var TRUE_NODE = {
|
|
|
235
235
|
m: void 0,
|
|
236
236
|
d: void 0,
|
|
237
237
|
a: void 0,
|
|
238
|
-
|
|
238
|
+
f: void 0
|
|
239
239
|
};
|
|
240
240
|
var FALSE_NODE = {
|
|
241
241
|
t: 2 /* Boolean */,
|
|
@@ -246,7 +246,7 @@ var FALSE_NODE = {
|
|
|
246
246
|
m: void 0,
|
|
247
247
|
d: void 0,
|
|
248
248
|
a: void 0,
|
|
249
|
-
|
|
249
|
+
f: void 0
|
|
250
250
|
};
|
|
251
251
|
var UNDEFINED_NODE = {
|
|
252
252
|
t: 4 /* Undefined */,
|
|
@@ -257,7 +257,7 @@ var UNDEFINED_NODE = {
|
|
|
257
257
|
m: void 0,
|
|
258
258
|
d: void 0,
|
|
259
259
|
a: void 0,
|
|
260
|
-
|
|
260
|
+
f: void 0
|
|
261
261
|
};
|
|
262
262
|
var NULL_NODE = {
|
|
263
263
|
t: 3 /* Null */,
|
|
@@ -268,7 +268,7 @@ var NULL_NODE = {
|
|
|
268
268
|
m: void 0,
|
|
269
269
|
d: void 0,
|
|
270
270
|
a: void 0,
|
|
271
|
-
|
|
271
|
+
f: void 0
|
|
272
272
|
};
|
|
273
273
|
var NEG_ZERO_NODE = {
|
|
274
274
|
t: 5 /* NegativeZero */,
|
|
@@ -279,7 +279,7 @@ var NEG_ZERO_NODE = {
|
|
|
279
279
|
m: void 0,
|
|
280
280
|
d: void 0,
|
|
281
281
|
a: void 0,
|
|
282
|
-
|
|
282
|
+
f: void 0
|
|
283
283
|
};
|
|
284
284
|
var INFINITY_NODE = {
|
|
285
285
|
t: 6 /* Infinity */,
|
|
@@ -290,7 +290,7 @@ var INFINITY_NODE = {
|
|
|
290
290
|
m: void 0,
|
|
291
291
|
d: void 0,
|
|
292
292
|
a: void 0,
|
|
293
|
-
|
|
293
|
+
f: void 0
|
|
294
294
|
};
|
|
295
295
|
var NEG_INFINITY_NODE = {
|
|
296
296
|
t: 7 /* NegativeInfinity */,
|
|
@@ -301,7 +301,7 @@ var NEG_INFINITY_NODE = {
|
|
|
301
301
|
m: void 0,
|
|
302
302
|
d: void 0,
|
|
303
303
|
a: void 0,
|
|
304
|
-
|
|
304
|
+
f: void 0
|
|
305
305
|
};
|
|
306
306
|
var NAN_NODE = {
|
|
307
307
|
t: 8 /* NaN */,
|
|
@@ -312,7 +312,7 @@ var NAN_NODE = {
|
|
|
312
312
|
m: void 0,
|
|
313
313
|
d: void 0,
|
|
314
314
|
a: void 0,
|
|
315
|
-
|
|
315
|
+
f: void 0
|
|
316
316
|
};
|
|
317
317
|
function createNumberNode(value) {
|
|
318
318
|
return {
|
|
@@ -324,7 +324,7 @@ function createNumberNode(value) {
|
|
|
324
324
|
m: void 0,
|
|
325
325
|
d: void 0,
|
|
326
326
|
a: void 0,
|
|
327
|
-
|
|
327
|
+
f: void 0
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
330
|
function createStringNode(value) {
|
|
@@ -337,7 +337,7 @@ function createStringNode(value) {
|
|
|
337
337
|
m: void 0,
|
|
338
338
|
d: void 0,
|
|
339
339
|
a: void 0,
|
|
340
|
-
|
|
340
|
+
f: void 0
|
|
341
341
|
};
|
|
342
342
|
}
|
|
343
343
|
function createBigIntNode(ctx, current) {
|
|
@@ -345,13 +345,13 @@ function createBigIntNode(ctx, current) {
|
|
|
345
345
|
return {
|
|
346
346
|
t: 9 /* BigInt */,
|
|
347
347
|
i: void 0,
|
|
348
|
-
s: current
|
|
348
|
+
s: "" + current,
|
|
349
349
|
l: void 0,
|
|
350
350
|
c: void 0,
|
|
351
351
|
m: void 0,
|
|
352
352
|
d: void 0,
|
|
353
353
|
a: void 0,
|
|
354
|
-
|
|
354
|
+
f: void 0
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
357
|
function createReferenceNode(id) {
|
|
@@ -364,7 +364,7 @@ function createReferenceNode(id) {
|
|
|
364
364
|
m: void 0,
|
|
365
365
|
d: void 0,
|
|
366
366
|
a: void 0,
|
|
367
|
-
|
|
367
|
+
f: void 0
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
370
|
function createDateNode(id, current) {
|
|
@@ -376,7 +376,7 @@ function createDateNode(id, current) {
|
|
|
376
376
|
c: void 0,
|
|
377
377
|
m: void 0,
|
|
378
378
|
d: void 0,
|
|
379
|
-
|
|
379
|
+
f: void 0,
|
|
380
380
|
a: void 0
|
|
381
381
|
};
|
|
382
382
|
}
|
|
@@ -390,7 +390,7 @@ function createRegExpNode(id, current) {
|
|
|
390
390
|
m: current.flags,
|
|
391
391
|
d: void 0,
|
|
392
392
|
a: void 0,
|
|
393
|
-
|
|
393
|
+
f: void 0
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
396
|
function createTypedArrayNode(ctx, id, current) {
|
|
@@ -399,7 +399,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
399
399
|
const len = current.length;
|
|
400
400
|
const values = new Array(len);
|
|
401
401
|
for (let i = 0; i < len; i++) {
|
|
402
|
-
values[i] = current[i]
|
|
402
|
+
values[i] = "" + current[i];
|
|
403
403
|
}
|
|
404
404
|
return {
|
|
405
405
|
t: 22 /* TypedArray */,
|
|
@@ -410,7 +410,7 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
410
410
|
m: void 0,
|
|
411
411
|
d: void 0,
|
|
412
412
|
a: void 0,
|
|
413
|
-
|
|
413
|
+
f: void 0
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
416
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -423,7 +423,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
423
423
|
const len = current.length;
|
|
424
424
|
const values = new Array(len);
|
|
425
425
|
for (let i = 0; i < len; i++) {
|
|
426
|
-
values[i] = current[i]
|
|
426
|
+
values[i] = "" + current[i];
|
|
427
427
|
}
|
|
428
428
|
return {
|
|
429
429
|
t: 23 /* BigIntTypedArray */,
|
|
@@ -434,7 +434,7 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
434
434
|
m: void 0,
|
|
435
435
|
d: void 0,
|
|
436
436
|
a: void 0,
|
|
437
|
-
|
|
437
|
+
f: void 0
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
function createWKSymbolNode(current) {
|
|
@@ -447,7 +447,7 @@ function createWKSymbolNode(current) {
|
|
|
447
447
|
m: void 0,
|
|
448
448
|
d: void 0,
|
|
449
449
|
a: void 0,
|
|
450
|
-
|
|
450
|
+
f: void 0
|
|
451
451
|
};
|
|
452
452
|
}
|
|
453
453
|
|
|
@@ -622,7 +622,7 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
622
622
|
m: void 0,
|
|
623
623
|
d: void 0,
|
|
624
624
|
a: await generateNodeList(ctx, current),
|
|
625
|
-
|
|
625
|
+
f: void 0
|
|
626
626
|
};
|
|
627
627
|
}
|
|
628
628
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -658,7 +658,7 @@ async function generateMapNode(ctx, id, current) {
|
|
|
658
658
|
m: void 0,
|
|
659
659
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
660
660
|
a: void 0,
|
|
661
|
-
|
|
661
|
+
f: void 0
|
|
662
662
|
};
|
|
663
663
|
}
|
|
664
664
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -687,7 +687,7 @@ async function generateSetNode(ctx, id, current) {
|
|
|
687
687
|
m: void 0,
|
|
688
688
|
d: void 0,
|
|
689
689
|
a: nodes,
|
|
690
|
-
|
|
690
|
+
f: void 0
|
|
691
691
|
};
|
|
692
692
|
}
|
|
693
693
|
async function generateProperties(ctx, properties) {
|
|
@@ -736,7 +736,7 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
736
736
|
// Parse options first before the items
|
|
737
737
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
738
738
|
a: await generateNodeList(ctx, array),
|
|
739
|
-
|
|
739
|
+
f: void 0
|
|
740
740
|
};
|
|
741
741
|
}
|
|
742
742
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -751,7 +751,7 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
751
751
|
// Parse options first before the items
|
|
752
752
|
d: void 0,
|
|
753
753
|
a: void 0,
|
|
754
|
-
|
|
754
|
+
f: await parse(ctx, value)
|
|
755
755
|
}));
|
|
756
756
|
}
|
|
757
757
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -770,7 +770,7 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
770
770
|
m: void 0,
|
|
771
771
|
d: await generateProperties(ctx, current),
|
|
772
772
|
a: void 0,
|
|
773
|
-
|
|
773
|
+
f: void 0
|
|
774
774
|
};
|
|
775
775
|
}
|
|
776
776
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -785,7 +785,7 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
785
785
|
m: current.message,
|
|
786
786
|
d: optionsNode,
|
|
787
787
|
a: await generateNodeList(ctx, current.errors),
|
|
788
|
-
|
|
788
|
+
f: void 0
|
|
789
789
|
};
|
|
790
790
|
}
|
|
791
791
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -800,7 +800,7 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
800
800
|
m: current.message,
|
|
801
801
|
d: optionsNode,
|
|
802
802
|
a: void 0,
|
|
803
|
-
|
|
803
|
+
f: void 0
|
|
804
804
|
};
|
|
805
805
|
}
|
|
806
806
|
async function parse(ctx, current) {
|
|
@@ -812,18 +812,20 @@ async function parse(ctx, current) {
|
|
|
812
812
|
case "string":
|
|
813
813
|
return createStringNode(current);
|
|
814
814
|
case "number":
|
|
815
|
+
switch (current) {
|
|
816
|
+
case Infinity:
|
|
817
|
+
return INFINITY_NODE;
|
|
818
|
+
case -Infinity:
|
|
819
|
+
return NEG_INFINITY_NODE;
|
|
820
|
+
default:
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
815
823
|
if (current !== current) {
|
|
816
824
|
return NAN_NODE;
|
|
817
825
|
}
|
|
818
826
|
if (Object.is(current, -0)) {
|
|
819
827
|
return NEG_ZERO_NODE;
|
|
820
828
|
}
|
|
821
|
-
if (Object.is(current, Infinity)) {
|
|
822
|
-
return INFINITY_NODE;
|
|
823
|
-
}
|
|
824
|
-
if (Object.is(current, -Infinity)) {
|
|
825
|
-
return NEG_INFINITY_NODE;
|
|
826
|
-
}
|
|
827
829
|
return createNumberNode(current);
|
|
828
830
|
case "bigint":
|
|
829
831
|
return createBigIntNode(ctx, current);
|
|
@@ -831,7 +833,7 @@ async function parse(ctx, current) {
|
|
|
831
833
|
if (!current) {
|
|
832
834
|
return NULL_NODE;
|
|
833
835
|
}
|
|
834
|
-
const id = createRef(ctx, current
|
|
836
|
+
const id = createRef(ctx, current);
|
|
835
837
|
if (ctx.markedRefs.has(id)) {
|
|
836
838
|
return createReferenceNode(id);
|
|
837
839
|
}
|
|
@@ -900,8 +902,11 @@ async function parse(ctx, current) {
|
|
|
900
902
|
default:
|
|
901
903
|
break;
|
|
902
904
|
}
|
|
903
|
-
if (current instanceof AggregateError
|
|
904
|
-
|
|
905
|
+
if (current instanceof AggregateError) {
|
|
906
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
907
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
908
|
+
}
|
|
909
|
+
return generateErrorNode(ctx, id, current);
|
|
905
910
|
}
|
|
906
911
|
if (current instanceof Error) {
|
|
907
912
|
return generateErrorNode(ctx, id, current);
|
|
@@ -928,7 +933,7 @@ async function parse(ctx, current) {
|
|
|
928
933
|
async function parseAsync(ctx, current) {
|
|
929
934
|
const result = await parse(ctx, current);
|
|
930
935
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
931
|
-
return [result,
|
|
936
|
+
return [result, getRootID(ctx, current), isObject];
|
|
932
937
|
}
|
|
933
938
|
|
|
934
939
|
// src/tree/deserialize.ts
|
|
@@ -1040,7 +1045,7 @@ function createDeferred() {
|
|
|
1040
1045
|
function deserializePromise(ctx, node) {
|
|
1041
1046
|
const deferred = createDeferred();
|
|
1042
1047
|
const result = assignRef(ctx, node.i, deferred.promise);
|
|
1043
|
-
deferred.resolve(deserializeTree(ctx, node.
|
|
1048
|
+
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1044
1049
|
return result;
|
|
1045
1050
|
}
|
|
1046
1051
|
function deserializeTypedArray(ctx, node) {
|
|
@@ -1139,30 +1144,48 @@ function mergeAssignments(assignments) {
|
|
|
1139
1144
|
for (let i = 1, len = assignments.length; i < len; i++) {
|
|
1140
1145
|
item = assignments[i];
|
|
1141
1146
|
if (item.t === prev.t) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1147
|
+
switch (item.t) {
|
|
1148
|
+
case "index":
|
|
1149
|
+
if (item.v === prev.v) {
|
|
1150
|
+
current = {
|
|
1151
|
+
t: "index",
|
|
1152
|
+
s: item.s,
|
|
1153
|
+
k: void 0,
|
|
1154
|
+
v: getAssignmentExpression(current)
|
|
1155
|
+
};
|
|
1156
|
+
} else {
|
|
1157
|
+
newAssignments.push(current);
|
|
1158
|
+
current = item;
|
|
1159
|
+
}
|
|
1160
|
+
break;
|
|
1161
|
+
case "map":
|
|
1162
|
+
if (item.s === prev.s) {
|
|
1163
|
+
current = {
|
|
1164
|
+
t: "map",
|
|
1165
|
+
s: getAssignmentExpression(current),
|
|
1166
|
+
k: item.k,
|
|
1167
|
+
v: item.v
|
|
1168
|
+
};
|
|
1169
|
+
} else {
|
|
1170
|
+
newAssignments.push(current);
|
|
1171
|
+
current = item;
|
|
1172
|
+
}
|
|
1173
|
+
break;
|
|
1174
|
+
case "set":
|
|
1175
|
+
if (item.s === prev.s) {
|
|
1176
|
+
current = {
|
|
1177
|
+
t: "set",
|
|
1178
|
+
s: getAssignmentExpression(current),
|
|
1179
|
+
k: void 0,
|
|
1180
|
+
v: item.v
|
|
1181
|
+
};
|
|
1182
|
+
} else {
|
|
1183
|
+
newAssignments.push(current);
|
|
1184
|
+
current = item;
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
default:
|
|
1188
|
+
break;
|
|
1166
1189
|
}
|
|
1167
1190
|
} else {
|
|
1168
1191
|
newAssignments.push(current);
|
|
@@ -1215,7 +1238,7 @@ function createMapSet(ctx, ref, key, value) {
|
|
|
1215
1238
|
}
|
|
1216
1239
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1217
1240
|
markRef(ctx, ref);
|
|
1218
|
-
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index
|
|
1241
|
+
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1219
1242
|
}
|
|
1220
1243
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1221
1244
|
markRef(ctx, ref);
|
|
@@ -1252,10 +1275,7 @@ function serializeNodeList(ctx, node) {
|
|
|
1252
1275
|
isHoley = true;
|
|
1253
1276
|
}
|
|
1254
1277
|
}
|
|
1255
|
-
|
|
1256
|
-
values += ",";
|
|
1257
|
-
}
|
|
1258
|
-
return "[" + values + "]";
|
|
1278
|
+
return "[" + values + (isHoley ? ",]" : "]");
|
|
1259
1279
|
}
|
|
1260
1280
|
function serializeArray(ctx, node) {
|
|
1261
1281
|
ctx.stack.push(node.i);
|
|
@@ -1288,11 +1308,7 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1288
1308
|
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
|
|
1289
1309
|
}
|
|
1290
1310
|
} else {
|
|
1291
|
-
|
|
1292
|
-
result += ",";
|
|
1293
|
-
}
|
|
1294
|
-
result += isIdentifier ? key : '"' + quote(key) + '"';
|
|
1295
|
-
result += ":" + serializeTree(ctx, val);
|
|
1311
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
|
|
1296
1312
|
hasPrev = true;
|
|
1297
1313
|
}
|
|
1298
1314
|
}
|
|
@@ -1343,8 +1359,7 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1343
1359
|
markRef(ctx, i);
|
|
1344
1360
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1345
1361
|
if (assignments) {
|
|
1346
|
-
|
|
1347
|
-
return "(" + assignRef2(ctx, i, init) + "," + assignments + ref + ")";
|
|
1362
|
+
return "(" + assignRef2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1348
1363
|
}
|
|
1349
1364
|
}
|
|
1350
1365
|
}
|
|
@@ -1369,10 +1384,7 @@ function serializeSet(ctx, node) {
|
|
|
1369
1384
|
if (isReferenceInStack(ctx, item)) {
|
|
1370
1385
|
createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
|
|
1371
1386
|
} else {
|
|
1372
|
-
|
|
1373
|
-
result += ",";
|
|
1374
|
-
}
|
|
1375
|
-
result += serializeTree(ctx, item);
|
|
1387
|
+
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1376
1388
|
hasPrev = true;
|
|
1377
1389
|
}
|
|
1378
1390
|
}
|
|
@@ -1415,10 +1427,7 @@ function serializeMap(ctx, node) {
|
|
|
1415
1427
|
createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1416
1428
|
ctx.stack = parent;
|
|
1417
1429
|
} else {
|
|
1418
|
-
|
|
1419
|
-
result += ",";
|
|
1420
|
-
}
|
|
1421
|
-
result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1430
|
+
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
1422
1431
|
hasPrev = true;
|
|
1423
1432
|
}
|
|
1424
1433
|
}
|
|
@@ -1441,8 +1450,8 @@ function serializeError(ctx, node) {
|
|
|
1441
1450
|
}
|
|
1442
1451
|
function serializePromise(ctx, node) {
|
|
1443
1452
|
let serialized;
|
|
1444
|
-
if (isReferenceInStack(ctx, node.
|
|
1445
|
-
const ref = getRefParam(ctx, node.
|
|
1453
|
+
if (isReferenceInStack(ctx, node.f)) {
|
|
1454
|
+
const ref = getRefParam(ctx, node.f.i);
|
|
1446
1455
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1447
1456
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1448
1457
|
} else {
|
|
@@ -1450,7 +1459,7 @@ function serializePromise(ctx, node) {
|
|
|
1450
1459
|
}
|
|
1451
1460
|
} else {
|
|
1452
1461
|
ctx.stack.push(node.i);
|
|
1453
|
-
const result = serializeTree(ctx, node.
|
|
1462
|
+
const result = serializeTree(ctx, node.f);
|
|
1454
1463
|
ctx.stack.pop();
|
|
1455
1464
|
serialized = "Promise.resolve(" + result + ")";
|
|
1456
1465
|
}
|
|
@@ -1458,19 +1467,11 @@ function serializePromise(ctx, node) {
|
|
|
1458
1467
|
}
|
|
1459
1468
|
function serializeTypedArray(ctx, node) {
|
|
1460
1469
|
let result = "";
|
|
1470
|
+
const isBigInt = node.t === 23 /* BigIntTypedArray */;
|
|
1461
1471
|
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1462
|
-
|
|
1463
|
-
result += ",";
|
|
1464
|
-
}
|
|
1465
|
-
result += node.s[i];
|
|
1466
|
-
if (node.t === 23 /* BigIntTypedArray */) {
|
|
1467
|
-
result += "n";
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
let args = "[" + result + "]";
|
|
1471
|
-
if (node.l !== 0) {
|
|
1472
|
-
args += "," + node.l.toString();
|
|
1472
|
+
result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
|
|
1473
1473
|
}
|
|
1474
|
+
const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
|
|
1474
1475
|
return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1475
1476
|
}
|
|
1476
1477
|
function serializeIterable(ctx, node) {
|
|
@@ -1496,13 +1497,13 @@ function serializeIterable(ctx, node) {
|
|
|
1496
1497
|
function serializeTree(ctx, node) {
|
|
1497
1498
|
switch (node.t) {
|
|
1498
1499
|
case 0 /* Number */:
|
|
1499
|
-
return
|
|
1500
|
+
return "" + node.s;
|
|
1500
1501
|
case 1 /* String */:
|
|
1501
1502
|
return '"' + node.s + '"';
|
|
1502
1503
|
case 2 /* Boolean */:
|
|
1503
1504
|
return node.s ? "!0" : "!1";
|
|
1504
1505
|
case 4 /* Undefined */:
|
|
1505
|
-
return "
|
|
1506
|
+
return "void 0";
|
|
1506
1507
|
case 3 /* Null */:
|
|
1507
1508
|
return "null";
|
|
1508
1509
|
case 5 /* NegativeZero */:
|
|
@@ -1582,7 +1583,7 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1582
1583
|
m: void 0,
|
|
1583
1584
|
d: void 0,
|
|
1584
1585
|
a: generateNodeList2(ctx, current),
|
|
1585
|
-
|
|
1586
|
+
f: void 0
|
|
1586
1587
|
};
|
|
1587
1588
|
}
|
|
1588
1589
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1618,7 +1619,7 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1618
1619
|
m: void 0,
|
|
1619
1620
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1620
1621
|
a: void 0,
|
|
1621
|
-
|
|
1622
|
+
f: void 0
|
|
1622
1623
|
};
|
|
1623
1624
|
}
|
|
1624
1625
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1647,7 +1648,7 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1647
1648
|
m: void 0,
|
|
1648
1649
|
d: void 0,
|
|
1649
1650
|
a: nodes,
|
|
1650
|
-
|
|
1651
|
+
f: void 0
|
|
1651
1652
|
};
|
|
1652
1653
|
}
|
|
1653
1654
|
function generateProperties2(ctx, properties) {
|
|
@@ -1696,7 +1697,7 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1696
1697
|
// Parse options first before the items
|
|
1697
1698
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1698
1699
|
a: generateNodeList2(ctx, array),
|
|
1699
|
-
|
|
1700
|
+
f: void 0
|
|
1700
1701
|
};
|
|
1701
1702
|
}
|
|
1702
1703
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1712,7 +1713,7 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1712
1713
|
m: void 0,
|
|
1713
1714
|
d: generateProperties2(ctx, current),
|
|
1714
1715
|
a: void 0,
|
|
1715
|
-
|
|
1716
|
+
f: void 0
|
|
1716
1717
|
};
|
|
1717
1718
|
}
|
|
1718
1719
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1727,7 +1728,7 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1727
1728
|
m: current.message,
|
|
1728
1729
|
d: optionsNode,
|
|
1729
1730
|
a: generateNodeList2(ctx, current.errors),
|
|
1730
|
-
|
|
1731
|
+
f: void 0
|
|
1731
1732
|
};
|
|
1732
1733
|
}
|
|
1733
1734
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1742,7 +1743,7 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1742
1743
|
m: current.message,
|
|
1743
1744
|
d: optionsNode,
|
|
1744
1745
|
a: void 0,
|
|
1745
|
-
|
|
1746
|
+
f: void 0
|
|
1746
1747
|
};
|
|
1747
1748
|
}
|
|
1748
1749
|
function parse2(ctx, current) {
|
|
@@ -1754,18 +1755,20 @@ function parse2(ctx, current) {
|
|
|
1754
1755
|
case "string":
|
|
1755
1756
|
return createStringNode(current);
|
|
1756
1757
|
case "number":
|
|
1758
|
+
switch (current) {
|
|
1759
|
+
case Infinity:
|
|
1760
|
+
return INFINITY_NODE;
|
|
1761
|
+
case -Infinity:
|
|
1762
|
+
return NEG_INFINITY_NODE;
|
|
1763
|
+
default:
|
|
1764
|
+
break;
|
|
1765
|
+
}
|
|
1757
1766
|
if (current !== current) {
|
|
1758
1767
|
return NAN_NODE;
|
|
1759
1768
|
}
|
|
1760
1769
|
if (Object.is(current, -0)) {
|
|
1761
1770
|
return NEG_ZERO_NODE;
|
|
1762
1771
|
}
|
|
1763
|
-
if (Object.is(current, Infinity)) {
|
|
1764
|
-
return INFINITY_NODE;
|
|
1765
|
-
}
|
|
1766
|
-
if (Object.is(current, -Infinity)) {
|
|
1767
|
-
return NEG_INFINITY_NODE;
|
|
1768
|
-
}
|
|
1769
1772
|
return createNumberNode(current);
|
|
1770
1773
|
case "bigint":
|
|
1771
1774
|
return createBigIntNode(ctx, current);
|
|
@@ -1773,7 +1776,7 @@ function parse2(ctx, current) {
|
|
|
1773
1776
|
if (!current) {
|
|
1774
1777
|
return NULL_NODE;
|
|
1775
1778
|
}
|
|
1776
|
-
const id = createRef(ctx, current
|
|
1779
|
+
const id = createRef(ctx, current);
|
|
1777
1780
|
if (ctx.markedRefs.has(id)) {
|
|
1778
1781
|
return createReferenceNode(id);
|
|
1779
1782
|
}
|
|
@@ -1822,8 +1825,11 @@ function parse2(ctx, current) {
|
|
|
1822
1825
|
default:
|
|
1823
1826
|
break;
|
|
1824
1827
|
}
|
|
1825
|
-
if (current instanceof AggregateError
|
|
1826
|
-
|
|
1828
|
+
if (current instanceof AggregateError) {
|
|
1829
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1830
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1831
|
+
}
|
|
1832
|
+
return generateErrorNode2(ctx, id, current);
|
|
1827
1833
|
}
|
|
1828
1834
|
if (current instanceof Error) {
|
|
1829
1835
|
return generateErrorNode2(ctx, id, current);
|
|
@@ -1844,7 +1850,7 @@ function parse2(ctx, current) {
|
|
|
1844
1850
|
function parseSync(ctx, current) {
|
|
1845
1851
|
const result = parse2(ctx, current);
|
|
1846
1852
|
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
1847
|
-
return [result,
|
|
1853
|
+
return [result, getRootID(ctx, current), isObject];
|
|
1848
1854
|
}
|
|
1849
1855
|
|
|
1850
1856
|
// src/index.ts
|