seroval 0.4.1 → 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.
@@ -10,7 +10,7 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
10
10
  Feature2[Feature2["ObjectAssign"] = 128] = "ObjectAssign";
11
11
  Feature2[Feature2["Promise"] = 256] = "Promise";
12
12
  Feature2[Feature2["Set"] = 512] = "Set";
13
- Feature2[Feature2["SymbolIterator"] = 1024] = "SymbolIterator";
13
+ Feature2[Feature2["Symbol"] = 1024] = "Symbol";
14
14
  Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
15
15
  Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
16
16
  return Feature2;
@@ -54,41 +54,42 @@ function createSerializationContext(options) {
54
54
  validRefs: [],
55
55
  refSize: 0,
56
56
  features: options.features,
57
- markedRefs: new Set(options.markedRefs)
57
+ markedRefs: new Set(options.markedRefs),
58
+ valueMap: /* @__PURE__ */ new Map()
58
59
  };
59
60
  }
60
61
  function markRef(ctx, current) {
61
62
  ctx.markedRefs.add(current);
62
63
  }
63
- function createValidRef(ctx, index) {
64
- const current = ctx.validRefs[index];
65
- if (current == null) {
66
- const value = ctx.refSize++;
67
- ctx.validRefs[index] = value;
68
- return value;
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;
69
74
  }
70
- return current;
75
+ return identifier;
71
76
  }
72
- function getRefParam(ctx, index) {
73
- const actualIndex = createValidRef(ctx, index);
74
- if (ctx.vars[actualIndex]) {
75
- return ctx.vars[actualIndex];
77
+ function getRootID(ctx, current) {
78
+ const ref = ctx.refs.get(current);
79
+ if (ref == null) {
80
+ return ctx.refs.size;
76
81
  }
77
- const result = getIdentifier(actualIndex);
78
- ctx.vars[actualIndex] = result;
79
- return result;
82
+ return ref;
80
83
  }
81
- function createRef(ctx, current, mark) {
84
+ function createRef(ctx, current) {
82
85
  const ref = ctx.refs.get(current);
83
- if (ref != null) {
84
- if (mark) {
85
- markRef(ctx, ref);
86
- }
87
- return ref;
86
+ if (ref == null) {
87
+ const id = ctx.refs.size;
88
+ ctx.refs.set(current, id);
89
+ return id;
88
90
  }
89
- const id = ctx.refs.size;
90
- ctx.refs.set(current, id);
91
- return id;
91
+ markRef(ctx, ref);
92
+ return ref;
92
93
  }
93
94
 
94
95
  // src/assert.ts
@@ -137,13 +138,151 @@ function quote(str) {
137
138
  } else {
138
139
  result += str.slice(lastPos);
139
140
  }
140
- return '"' + result + '"';
141
+ return result;
142
+ }
143
+ function invQuote(str) {
144
+ return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\x3C/g, "<").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\u2028/g, "\u2028").replace(/\\u2029/g, "\u2029");
141
145
  }
142
146
 
147
+ // src/tree/symbols.ts
148
+ var SYMBOL_STRING = {
149
+ [0 /* AsyncIterator */]: "Symbol.asyncIterator",
150
+ [1 /* HasInstance */]: "Symbol.hasInstance",
151
+ [2 /* IsConcatSpreadable */]: "Symbol.isConcatSpreadable",
152
+ [3 /* Iterator */]: "Symbol.iterator",
153
+ [4 /* Match */]: "Symbol.match",
154
+ [5 /* MatchAll */]: "Symbol.matchAll",
155
+ [6 /* Replace */]: "Symbol.replace",
156
+ [7 /* Search */]: "Symbol.search",
157
+ [8 /* Species */]: "Symbol.species",
158
+ [9 /* Split */]: "Symbol.split",
159
+ [10 /* ToPrimitive */]: "Symbol.toPrimitive",
160
+ [11 /* ToStringTag */]: "Symbol.toStringTag",
161
+ [12 /* Unscopables */]: "Symbol.unscopables"
162
+ };
163
+ var INV_SYMBOL_REF = {
164
+ [Symbol.asyncIterator]: 0 /* AsyncIterator */,
165
+ [Symbol.hasInstance]: 1 /* HasInstance */,
166
+ [Symbol.isConcatSpreadable]: 2 /* IsConcatSpreadable */,
167
+ [Symbol.iterator]: 3 /* Iterator */,
168
+ [Symbol.match]: 4 /* Match */,
169
+ [Symbol.matchAll]: 5 /* MatchAll */,
170
+ [Symbol.replace]: 6 /* Replace */,
171
+ [Symbol.search]: 7 /* Search */,
172
+ [Symbol.species]: 8 /* Species */,
173
+ [Symbol.split]: 9 /* Split */,
174
+ [Symbol.toPrimitive]: 10 /* ToPrimitive */,
175
+ [Symbol.toStringTag]: 11 /* ToStringTag */,
176
+ [Symbol.unscopables]: 12 /* Unscopables */
177
+ };
178
+ var SYMBOL_REF = {
179
+ [0 /* AsyncIterator */]: Symbol.asyncIterator,
180
+ [1 /* HasInstance */]: Symbol.hasInstance,
181
+ [2 /* IsConcatSpreadable */]: Symbol.isConcatSpreadable,
182
+ [3 /* Iterator */]: Symbol.iterator,
183
+ [4 /* Match */]: Symbol.match,
184
+ [5 /* MatchAll */]: Symbol.matchAll,
185
+ [6 /* Replace */]: Symbol.replace,
186
+ [7 /* Search */]: Symbol.search,
187
+ [8 /* Species */]: Symbol.species,
188
+ [9 /* Split */]: Symbol.split,
189
+ [10 /* ToPrimitive */]: Symbol.toPrimitive,
190
+ [11 /* ToStringTag */]: Symbol.toStringTag,
191
+ [12 /* Unscopables */]: Symbol.unscopables
192
+ };
193
+
143
194
  // src/tree/primitives.ts
144
- function createPrimitiveNode(value) {
195
+ var TRUE_NODE = {
196
+ t: 2 /* Boolean */,
197
+ i: void 0,
198
+ s: true,
199
+ l: void 0,
200
+ c: void 0,
201
+ m: void 0,
202
+ d: void 0,
203
+ a: void 0,
204
+ f: void 0
205
+ };
206
+ var FALSE_NODE = {
207
+ t: 2 /* Boolean */,
208
+ i: void 0,
209
+ s: false,
210
+ l: void 0,
211
+ c: void 0,
212
+ m: void 0,
213
+ d: void 0,
214
+ a: void 0,
215
+ f: void 0
216
+ };
217
+ var UNDEFINED_NODE = {
218
+ t: 4 /* Undefined */,
219
+ i: void 0,
220
+ s: void 0,
221
+ l: void 0,
222
+ c: void 0,
223
+ m: void 0,
224
+ d: void 0,
225
+ a: void 0,
226
+ f: void 0
227
+ };
228
+ var NULL_NODE = {
229
+ t: 3 /* Null */,
230
+ i: void 0,
231
+ s: void 0,
232
+ l: void 0,
233
+ c: void 0,
234
+ m: void 0,
235
+ d: void 0,
236
+ a: void 0,
237
+ f: void 0
238
+ };
239
+ var NEG_ZERO_NODE = {
240
+ t: 5 /* NegativeZero */,
241
+ i: void 0,
242
+ s: void 0,
243
+ l: void 0,
244
+ c: void 0,
245
+ m: void 0,
246
+ d: void 0,
247
+ a: void 0,
248
+ f: void 0
249
+ };
250
+ var INFINITY_NODE = {
251
+ t: 6 /* Infinity */,
252
+ i: void 0,
253
+ s: void 0,
254
+ l: void 0,
255
+ c: void 0,
256
+ m: void 0,
257
+ d: void 0,
258
+ a: void 0,
259
+ f: void 0
260
+ };
261
+ var NEG_INFINITY_NODE = {
262
+ t: 7 /* NegativeInfinity */,
263
+ i: void 0,
264
+ s: void 0,
265
+ l: void 0,
266
+ c: void 0,
267
+ m: void 0,
268
+ d: void 0,
269
+ a: void 0,
270
+ f: void 0
271
+ };
272
+ var NAN_NODE = {
273
+ t: 8 /* NaN */,
274
+ i: void 0,
275
+ s: void 0,
276
+ l: void 0,
277
+ c: void 0,
278
+ m: void 0,
279
+ d: void 0,
280
+ a: void 0,
281
+ f: void 0
282
+ };
283
+ function createNumberNode(value) {
145
284
  return {
146
- t: 0 /* Primitive */,
285
+ t: 0 /* Number */,
147
286
  i: void 0,
148
287
  s: value,
149
288
  l: void 0,
@@ -151,33 +290,39 @@ function createPrimitiveNode(value) {
151
290
  m: void 0,
152
291
  d: void 0,
153
292
  a: void 0,
154
- n: void 0
293
+ f: void 0
294
+ };
295
+ }
296
+ function createStringNode(value) {
297
+ return {
298
+ t: 1 /* String */,
299
+ i: void 0,
300
+ s: quote(value),
301
+ l: void 0,
302
+ c: void 0,
303
+ m: void 0,
304
+ d: void 0,
305
+ a: void 0,
306
+ f: void 0
155
307
  };
156
308
  }
157
- var TRUE_NODE = createPrimitiveNode("!0");
158
- var FALSE_NODE = createPrimitiveNode("!1");
159
- var UNDEFINED_NODE = createPrimitiveNode("void 0");
160
- var NULL_NODE = createPrimitiveNode(null);
161
- var NEG_ZERO_NODE = createPrimitiveNode("-0");
162
- var INFINITY_NODE = createPrimitiveNode("1/0");
163
- var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
164
309
  function createBigIntNode(ctx, current) {
165
310
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
166
311
  return {
167
- t: 1 /* BigInt */,
312
+ t: 9 /* BigInt */,
168
313
  i: void 0,
169
- s: current.toString() + "n",
314
+ s: "" + current,
170
315
  l: void 0,
171
316
  c: void 0,
172
317
  m: void 0,
173
318
  d: void 0,
174
319
  a: void 0,
175
- n: void 0
320
+ f: void 0
176
321
  };
177
322
  }
178
323
  function createReferenceNode(id) {
179
324
  return {
180
- t: 2 /* Reference */,
325
+ t: 10 /* Reference */,
181
326
  i: id,
182
327
  s: void 0,
183
328
  l: void 0,
@@ -185,48 +330,53 @@ function createReferenceNode(id) {
185
330
  m: void 0,
186
331
  d: void 0,
187
332
  a: void 0,
188
- n: void 0
333
+ f: void 0
189
334
  };
190
335
  }
191
336
  function createDateNode(id, current) {
192
337
  return {
193
- t: 3 /* Date */,
338
+ t: 11 /* Date */,
194
339
  i: id,
195
340
  s: current.toISOString(),
196
341
  l: void 0,
197
342
  c: void 0,
198
343
  m: void 0,
199
344
  d: void 0,
200
- n: void 0,
345
+ f: void 0,
201
346
  a: void 0
202
347
  };
203
348
  }
204
349
  function createRegExpNode(id, current) {
205
350
  return {
206
- t: 4 /* RegExp */,
351
+ t: 12 /* RegExp */,
207
352
  i: id,
208
- s: String(current),
353
+ s: void 0,
209
354
  l: void 0,
210
- c: void 0,
211
- m: void 0,
355
+ c: current.source,
356
+ m: current.flags,
212
357
  d: void 0,
213
358
  a: void 0,
214
- n: void 0
359
+ f: void 0
215
360
  };
216
361
  }
217
362
  function createTypedArrayNode(ctx, id, current) {
218
363
  const constructor = current.constructor.name;
219
364
  assert(ctx.features & 2048 /* TypedArray */, `Unsupported value type "${constructor}"`);
365
+ const len = current.length;
366
+ const values = new Array(len);
367
+ for (let i = 0; i < len; i++) {
368
+ values[i] = "" + current[i];
369
+ }
220
370
  return {
221
- t: 14 /* TypedArray */,
371
+ t: 22 /* TypedArray */,
222
372
  i: id,
223
- s: current.toString(),
373
+ s: values,
224
374
  l: current.byteOffset,
225
375
  c: constructor,
226
376
  m: void 0,
227
377
  d: void 0,
228
378
  a: void 0,
229
- n: void 0
379
+ f: void 0
230
380
  };
231
381
  }
232
382
  var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
@@ -236,28 +386,39 @@ function createBigIntTypedArrayNode(ctx, id, current) {
236
386
  (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
237
387
  `Unsupported value type "${constructor}"`
238
388
  );
239
- let result = "";
240
- for (let i = 0, len = current.length; i < len; i++) {
241
- if (i !== 0) {
242
- result += ",";
243
- }
244
- result += current[i].toString() + "n";
389
+ const len = current.length;
390
+ const values = new Array(len);
391
+ for (let i = 0; i < len; i++) {
392
+ values[i] = "" + current[i];
245
393
  }
246
394
  return {
247
- t: 15 /* BigIntTypedArray */,
395
+ t: 23 /* BigIntTypedArray */,
248
396
  i: id,
249
- s: result,
397
+ s: values,
250
398
  l: current.byteOffset,
251
399
  c: constructor,
252
400
  m: void 0,
253
401
  d: void 0,
254
402
  a: void 0,
255
- n: void 0
403
+ f: void 0
404
+ };
405
+ }
406
+ function createWKSymbolNode(current) {
407
+ return {
408
+ t: 24 /* WKSymbol */,
409
+ i: void 0,
410
+ s: INV_SYMBOL_REF[current],
411
+ l: void 0,
412
+ c: void 0,
413
+ m: void 0,
414
+ d: void 0,
415
+ a: void 0,
416
+ f: void 0
256
417
  };
257
418
  }
258
419
 
259
420
  // src/tree/shared.ts
260
- function getErrorConstructor(error) {
421
+ function getErrorConstructorName(error) {
261
422
  if (error instanceof EvalError) {
262
423
  return "EvalError";
263
424
  }
@@ -278,9 +439,29 @@ function getErrorConstructor(error) {
278
439
  }
279
440
  return "Error";
280
441
  }
442
+ function getErrorConstructor(errorName) {
443
+ switch (errorName) {
444
+ case "Error":
445
+ return Error;
446
+ case "EvalError":
447
+ return EvalError;
448
+ case "RangeError":
449
+ return RangeError;
450
+ case "ReferenceError":
451
+ return ReferenceError;
452
+ case "SyntaxError":
453
+ return SyntaxError;
454
+ case "TypeError":
455
+ return TypeError;
456
+ case "URIError":
457
+ return URIError;
458
+ default:
459
+ throw new Error(`Unknown Error constructor "${errorName}"`);
460
+ }
461
+ }
281
462
  function getErrorOptions(ctx, error) {
282
463
  let options;
283
- const constructor = getErrorConstructor(error);
464
+ const constructor = getErrorConstructorName(error);
284
465
  if (error.name !== constructor) {
285
466
  options = { name: error.name };
286
467
  } else if (error.constructor.name !== constructor) {
@@ -340,6 +521,39 @@ function isIterable(value) {
340
521
  }
341
522
  return Symbol.iterator in value;
342
523
  }
524
+ function getTypedArrayConstructor(name) {
525
+ switch (name) {
526
+ case "Int8Array":
527
+ return Int8Array;
528
+ case "Int16Array":
529
+ return Int16Array;
530
+ case "Int32Array":
531
+ return Int32Array;
532
+ case "Uint8Array":
533
+ return Uint8Array;
534
+ case "Uint16Array":
535
+ return Uint16Array;
536
+ case "Uint32Array":
537
+ return Uint32Array;
538
+ case "Uint8ClampedArray":
539
+ return Uint8ClampedArray;
540
+ case "Float32Array":
541
+ return Float32Array;
542
+ case "Float64Array":
543
+ return Float64Array;
544
+ case "BigInt64Array":
545
+ return BigInt64Array;
546
+ case "BigUint64Array":
547
+ return BigUint64Array;
548
+ default:
549
+ throw new Error(`Unknown TypedArray "${name}"`);
550
+ }
551
+ }
552
+ var IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
553
+ function isValidIdentifier(name) {
554
+ const char = name[0];
555
+ return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
556
+ }
343
557
 
344
558
  // src/tree/async.ts
345
559
  async function generateNodeList(ctx, current) {
@@ -366,15 +580,15 @@ async function generateNodeList(ctx, current) {
366
580
  }
367
581
  async function generateArrayNode(ctx, id, current) {
368
582
  return {
369
- t: 7 /* Array */,
583
+ t: 15 /* Array */,
370
584
  i: id,
371
585
  s: void 0,
372
- l: void 0,
586
+ l: current.length,
373
587
  c: void 0,
374
588
  m: void 0,
375
589
  d: void 0,
376
590
  a: await generateNodeList(ctx, current),
377
- n: void 0
591
+ f: void 0
378
592
  };
379
593
  }
380
594
  async function generateMapNode(ctx, id, current) {
@@ -402,7 +616,7 @@ async function generateMapNode(ctx, id, current) {
402
616
  valueNodes[nodeSize + i] = await parse(ctx, deferredValue[i]);
403
617
  }
404
618
  return {
405
- t: 6 /* Map */,
619
+ t: 14 /* Map */,
406
620
  i: id,
407
621
  s: void 0,
408
622
  l: void 0,
@@ -410,7 +624,7 @@ async function generateMapNode(ctx, id, current) {
410
624
  m: void 0,
411
625
  d: { k: keyNodes, v: valueNodes, s: len },
412
626
  a: void 0,
413
- n: void 0
627
+ f: void 0
414
628
  };
415
629
  }
416
630
  async function generateSetNode(ctx, id, current) {
@@ -431,15 +645,15 @@ async function generateSetNode(ctx, id, current) {
431
645
  nodes[nodeSize + i] = await parse(ctx, deferred[i]);
432
646
  }
433
647
  return {
434
- t: 5 /* Set */,
648
+ t: 13 /* Set */,
435
649
  i: id,
436
650
  s: void 0,
437
- l: void 0,
651
+ l: len,
438
652
  c: void 0,
439
653
  m: void 0,
440
654
  d: void 0,
441
655
  a: nodes,
442
- n: void 0
656
+ f: void 0
443
657
  };
444
658
  }
445
659
  async function generateProperties(ctx, properties) {
@@ -475,25 +689,26 @@ async function generateProperties(ctx, properties) {
475
689
  };
476
690
  }
477
691
  async function generateIterableNode(ctx, id, current) {
478
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
692
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
479
693
  const options = getIterableOptions(current);
694
+ const array = Array.from(current);
480
695
  return {
481
- t: 13 /* Iterable */,
696
+ t: 21 /* Iterable */,
482
697
  i: id,
483
698
  s: void 0,
484
- l: void 0,
699
+ l: array.length,
485
700
  c: void 0,
486
701
  m: void 0,
487
702
  // Parse options first before the items
488
703
  d: options ? await generateProperties(ctx, options) : void 0,
489
- a: await generateNodeList(ctx, Array.from(current)),
490
- n: void 0
704
+ a: await generateNodeList(ctx, array),
705
+ f: void 0
491
706
  };
492
707
  }
493
708
  async function generatePromiseNode(ctx, id, current) {
494
709
  assert(ctx.features & 256 /* Promise */, 'Unsupported type "Promise"');
495
710
  return current.then(async (value) => ({
496
- t: 10 /* Promise */,
711
+ t: 18 /* Promise */,
497
712
  i: id,
498
713
  s: void 0,
499
714
  l: void 0,
@@ -502,7 +717,7 @@ async function generatePromiseNode(ctx, id, current) {
502
717
  // Parse options first before the items
503
718
  d: void 0,
504
719
  a: void 0,
505
- n: await parse(ctx, value)
720
+ f: await parse(ctx, value)
506
721
  }));
507
722
  }
508
723
  async function generateObjectNode(ctx, id, current, empty) {
@@ -513,7 +728,7 @@ async function generateObjectNode(ctx, id, current, empty) {
513
728
  return generatePromiseNode(ctx, id, current);
514
729
  }
515
730
  return {
516
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
731
+ t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
517
732
  i: id,
518
733
  s: void 0,
519
734
  l: void 0,
@@ -521,37 +736,37 @@ async function generateObjectNode(ctx, id, current, empty) {
521
736
  m: void 0,
522
737
  d: await generateProperties(ctx, current),
523
738
  a: void 0,
524
- n: void 0
739
+ f: void 0
525
740
  };
526
741
  }
527
742
  async function generateAggregateErrorNode(ctx, id, current) {
528
743
  const options = getErrorOptions(ctx, current);
529
744
  const optionsNode = options ? await generateProperties(ctx, options) : void 0;
530
745
  return {
531
- t: 12 /* AggregateError */,
746
+ t: 20 /* AggregateError */,
532
747
  i: id,
533
748
  s: void 0,
534
- l: void 0,
749
+ l: current.errors.length,
535
750
  c: void 0,
536
751
  m: current.message,
537
752
  d: optionsNode,
538
- a: void 0,
539
- n: await parse(ctx, current.errors)
753
+ a: await generateNodeList(ctx, current.errors),
754
+ f: void 0
540
755
  };
541
756
  }
542
757
  async function generateErrorNode(ctx, id, current) {
543
758
  const options = getErrorOptions(ctx, current);
544
759
  const optionsNode = options ? await generateProperties(ctx, options) : void 0;
545
760
  return {
546
- t: 11 /* Error */,
761
+ t: 19 /* Error */,
547
762
  i: id,
548
763
  s: void 0,
549
764
  l: void 0,
550
- c: getErrorConstructor(current),
765
+ c: getErrorConstructorName(current),
551
766
  m: current.message,
552
767
  d: optionsNode,
553
768
  a: void 0,
554
- n: void 0
769
+ f: void 0
555
770
  };
556
771
  }
557
772
  async function parse(ctx, current) {
@@ -561,25 +776,30 @@ async function parse(ctx, current) {
561
776
  case "undefined":
562
777
  return UNDEFINED_NODE;
563
778
  case "string":
564
- return createPrimitiveNode(quote(current));
779
+ return createStringNode(current);
565
780
  case "number":
566
- if (Object.is(current, -0)) {
567
- return NEG_ZERO_NODE;
781
+ switch (current) {
782
+ case Infinity:
783
+ return INFINITY_NODE;
784
+ case -Infinity:
785
+ return NEG_INFINITY_NODE;
786
+ default:
787
+ break;
568
788
  }
569
- if (Object.is(current, Infinity)) {
570
- return createPrimitiveNode("1/0");
789
+ if (current !== current) {
790
+ return NAN_NODE;
571
791
  }
572
- if (Object.is(current, -Infinity)) {
573
- return createPrimitiveNode("-1/0");
792
+ if (Object.is(current, -0)) {
793
+ return NEG_ZERO_NODE;
574
794
  }
575
- return createPrimitiveNode(current);
795
+ return createNumberNode(current);
576
796
  case "bigint":
577
797
  return createBigIntNode(ctx, current);
578
798
  case "object": {
579
799
  if (!current) {
580
800
  return NULL_NODE;
581
801
  }
582
- const id = createRef(ctx, current, true);
802
+ const id = createRef(ctx, current);
583
803
  if (ctx.markedRefs.has(id)) {
584
804
  return createReferenceNode(id);
585
805
  }
@@ -648,8 +868,11 @@ async function parse(ctx, current) {
648
868
  default:
649
869
  break;
650
870
  }
651
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
652
- return generateAggregateErrorNode(ctx, id, current);
871
+ if (current instanceof AggregateError) {
872
+ if (ctx.features & 1 /* AggregateError */) {
873
+ return generateAggregateErrorNode(ctx, id, current);
874
+ }
875
+ return generateErrorNode(ctx, id, current);
653
876
  }
654
877
  if (current instanceof Error) {
655
878
  return generateErrorNode(ctx, id, current);
@@ -665,14 +888,205 @@ async function parse(ctx, current) {
665
888
  }
666
889
  throw new Error("Unsupported type");
667
890
  }
891
+ case "symbol":
892
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
893
+ assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
894
+ return createWKSymbolNode(current);
668
895
  default:
669
896
  throw new Error("Unsupported type");
670
897
  }
671
898
  }
672
899
  async function parseAsync(ctx, current) {
673
900
  const result = await parse(ctx, current);
674
- const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
675
- return [result, createRef(ctx, current, false), isObject];
901
+ const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
902
+ return [result, getRootID(ctx, current), isObject];
903
+ }
904
+
905
+ // src/tree/deserialize.ts
906
+ function assignRef(ctx, index, value) {
907
+ ctx.valueMap.set(index, value);
908
+ return value;
909
+ }
910
+ function deserializeNodeList(ctx, node, result) {
911
+ let item;
912
+ for (let i = 0, len = node.a.length; i < len; i++) {
913
+ item = node.a[i];
914
+ if (item) {
915
+ result[i] = deserializeTree(ctx, item);
916
+ }
917
+ }
918
+ return result;
919
+ }
920
+ function deserializeArray(ctx, node) {
921
+ const result = assignRef(
922
+ ctx,
923
+ node.i,
924
+ new Array(node.l)
925
+ );
926
+ ctx.stack.push(node.i);
927
+ deserializeNodeList(ctx, node, result);
928
+ ctx.stack.pop();
929
+ return result;
930
+ }
931
+ function deserializeProperties(ctx, node, result) {
932
+ if (node.s === 0) {
933
+ return {};
934
+ }
935
+ for (let i = 0; i < node.s; i++) {
936
+ result[node.k[i]] = deserializeTree(ctx, node.v[i]);
937
+ }
938
+ return result;
939
+ }
940
+ function deserializeNullConstructor(ctx, node) {
941
+ const result = assignRef(ctx, node.i, /* @__PURE__ */ Object.create(null));
942
+ ctx.stack.push(node.i);
943
+ deserializeProperties(ctx, node.d, result);
944
+ ctx.stack.pop();
945
+ return result;
946
+ }
947
+ function deserializeObject(ctx, node) {
948
+ const result = assignRef(ctx, node.i, {});
949
+ ctx.stack.push(node.i);
950
+ deserializeProperties(ctx, node.d, result);
951
+ ctx.stack.pop();
952
+ return result;
953
+ }
954
+ function deserializeSet(ctx, node) {
955
+ const result = assignRef(ctx, node.i, /* @__PURE__ */ new Set());
956
+ ctx.stack.push(node.i);
957
+ for (let i = 0, len = node.a.length; i < len; i++) {
958
+ result.add(deserializeTree(ctx, node.a[i]));
959
+ }
960
+ ctx.stack.pop();
961
+ return result;
962
+ }
963
+ function deserializeMap(ctx, node) {
964
+ const result = assignRef(
965
+ ctx,
966
+ node.i,
967
+ /* @__PURE__ */ new Map()
968
+ );
969
+ ctx.stack.push(node.i);
970
+ for (let i = 0; i < node.d.s; i++) {
971
+ result.set(
972
+ deserializeTree(ctx, node.d.k[i]),
973
+ deserializeTree(ctx, node.d.v[i])
974
+ );
975
+ }
976
+ ctx.stack.pop();
977
+ return result;
978
+ }
979
+ function deserializeDictionary(ctx, node, result) {
980
+ if (node.d) {
981
+ ctx.stack.push(node.i);
982
+ const fields = deserializeProperties(ctx, node.d, {});
983
+ ctx.stack.pop();
984
+ Object.assign(result, fields);
985
+ }
986
+ return result;
987
+ }
988
+ function deserializeAggregateError(ctx, node) {
989
+ const result = assignRef(ctx, node.i, new AggregateError([], node.m));
990
+ ctx.stack.push(node.i);
991
+ result.errors = deserializeNodeList(ctx, node, new Array(node.l));
992
+ ctx.stack.pop();
993
+ return deserializeDictionary(ctx, node, result);
994
+ }
995
+ function deserializeError(ctx, node) {
996
+ const ErrorConstructor = getErrorConstructor(node.c);
997
+ const result = assignRef(ctx, node.i, new ErrorConstructor(node.m));
998
+ return deserializeDictionary(ctx, node, result);
999
+ }
1000
+ function createDeferred() {
1001
+ let resolver;
1002
+ return {
1003
+ resolve(v) {
1004
+ resolver(v);
1005
+ },
1006
+ promise: new Promise((res) => {
1007
+ resolver = res;
1008
+ })
1009
+ };
1010
+ }
1011
+ function deserializePromise(ctx, node) {
1012
+ const deferred = createDeferred();
1013
+ const result = assignRef(ctx, node.i, deferred.promise);
1014
+ deferred.resolve(deserializeTree(ctx, node.f));
1015
+ return result;
1016
+ }
1017
+ function deserializeTypedArray(ctx, node) {
1018
+ const TypedArray = getTypedArrayConstructor(node.c);
1019
+ const dummy = new TypedArray();
1020
+ const result = assignRef(ctx, node.i, new TypedArray(
1021
+ dummy.buffer,
1022
+ node.l
1023
+ ));
1024
+ for (let i = 0, len = node.s.length; i < len; i++) {
1025
+ result[i] = node.t === 23 /* BigIntTypedArray */ ? BigInt(node.s[i]) : Number(node.s[i]);
1026
+ }
1027
+ return result;
1028
+ }
1029
+ function deserializeIterable(ctx, node) {
1030
+ const values = [];
1031
+ deserializeNodeList(ctx, node, values);
1032
+ const result = assignRef(ctx, node.i, {
1033
+ [Symbol.iterator]: () => values.values()
1034
+ });
1035
+ return deserializeDictionary(ctx, node, result);
1036
+ }
1037
+ function deserializeTree(ctx, node) {
1038
+ switch (node.t) {
1039
+ case 0 /* Number */:
1040
+ case 2 /* Boolean */:
1041
+ return node.s;
1042
+ case 1 /* String */:
1043
+ return invQuote(node.s);
1044
+ case 4 /* Undefined */:
1045
+ return void 0;
1046
+ case 3 /* Null */:
1047
+ return null;
1048
+ case 5 /* NegativeZero */:
1049
+ return -0;
1050
+ case 6 /* Infinity */:
1051
+ return Infinity;
1052
+ case 7 /* NegativeInfinity */:
1053
+ return -Infinity;
1054
+ case 8 /* NaN */:
1055
+ return NaN;
1056
+ case 9 /* BigInt */:
1057
+ return BigInt(node.s);
1058
+ case 10 /* Reference */:
1059
+ return ctx.valueMap.get(node.i);
1060
+ case 15 /* Array */:
1061
+ return deserializeArray(ctx, node);
1062
+ case 16 /* Object */:
1063
+ return deserializeObject(ctx, node);
1064
+ case 17 /* NullConstructor */:
1065
+ return deserializeNullConstructor(ctx, node);
1066
+ case 11 /* Date */:
1067
+ return assignRef(ctx, node.i, new Date(node.s));
1068
+ case 12 /* RegExp */:
1069
+ return assignRef(ctx, node.i, new RegExp(node.c, node.m));
1070
+ case 13 /* Set */:
1071
+ return deserializeSet(ctx, node);
1072
+ case 14 /* Map */:
1073
+ return deserializeMap(ctx, node);
1074
+ case 23 /* BigIntTypedArray */:
1075
+ case 22 /* TypedArray */:
1076
+ return deserializeTypedArray(ctx, node);
1077
+ case 20 /* AggregateError */:
1078
+ return deserializeAggregateError(ctx, node);
1079
+ case 19 /* Error */:
1080
+ return deserializeError(ctx, node);
1081
+ case 21 /* Iterable */:
1082
+ return deserializeIterable(ctx, node);
1083
+ case 18 /* Promise */:
1084
+ return deserializePromise(ctx, node);
1085
+ case 24 /* WKSymbol */:
1086
+ return SYMBOL_REF[node.s];
1087
+ default:
1088
+ throw new Error("Unsupported type");
1089
+ }
676
1090
  }
677
1091
 
678
1092
  // src/tree/serialize.ts
@@ -696,30 +1110,48 @@ function mergeAssignments(assignments) {
696
1110
  for (let i = 1, len = assignments.length; i < len; i++) {
697
1111
  item = assignments[i];
698
1112
  if (item.t === prev.t) {
699
- if (item.t === "index" && item.v === prev.v) {
700
- current = {
701
- t: "index",
702
- s: item.s,
703
- k: void 0,
704
- v: getAssignmentExpression(current)
705
- };
706
- } else if (item.t === "map" && item.s === prev.s) {
707
- current = {
708
- t: "map",
709
- s: getAssignmentExpression(current),
710
- k: item.k,
711
- v: item.v
712
- };
713
- } else if (item.t === "set" && item.s === prev.s) {
714
- current = {
715
- t: "set",
716
- s: getAssignmentExpression(current),
717
- k: void 0,
718
- v: item.v
719
- };
720
- } else {
721
- newAssignments.push(current);
722
- current = item;
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;
723
1155
  }
724
1156
  } else {
725
1157
  newAssignments.push(current);
@@ -772,24 +1204,23 @@ function createMapSet(ctx, ref, key, value) {
772
1204
  }
773
1205
  function createArrayAssign(ctx, ref, index, value) {
774
1206
  markRef(ctx, ref);
775
- createAssignment(ctx, getRefParam(ctx, ref) + "[" + index.toString() + "]", value);
1207
+ createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
776
1208
  }
777
1209
  function createObjectAssign(ctx, ref, key, value) {
778
1210
  markRef(ctx, ref);
779
1211
  createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
780
1212
  }
781
- function assignRef(ctx, index, value) {
1213
+ function assignRef2(ctx, index, value) {
782
1214
  if (ctx.markedRefs.has(index)) {
783
1215
  return getRefParam(ctx, index) + "=" + value;
784
1216
  }
785
1217
  return value;
786
1218
  }
787
1219
  function isReferenceInStack(ctx, node) {
788
- return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
1220
+ return node.t === 10 /* Reference */ && ctx.stack.includes(node.i);
789
1221
  }
790
- var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
791
1222
  function serializeNodeList(ctx, node) {
792
- const size = node.a.length;
1223
+ const size = node.l;
793
1224
  let values = "";
794
1225
  let item;
795
1226
  let isHoley = false;
@@ -810,18 +1241,15 @@ function serializeNodeList(ctx, node) {
810
1241
  isHoley = true;
811
1242
  }
812
1243
  }
813
- if (isHoley) {
814
- values += ",";
815
- }
816
- return "[" + values + "]";
1244
+ return "[" + values + (isHoley ? ",]" : "]");
817
1245
  }
818
1246
  function serializeArray(ctx, node) {
819
1247
  ctx.stack.push(node.i);
820
1248
  const result = serializeNodeList(ctx, node);
821
1249
  ctx.stack.pop();
822
- return assignRef(ctx, node.i, result);
1250
+ return assignRef2(ctx, node.i, result);
823
1251
  }
824
- function serializeObject(ctx, sourceID, node) {
1252
+ function serializeProperties(ctx, sourceID, node) {
825
1253
  if (node.s === 0) {
826
1254
  return "{}";
827
1255
  }
@@ -837,20 +1265,16 @@ function serializeObject(ctx, sourceID, node) {
837
1265
  key = node.k[i];
838
1266
  val = node.v[i];
839
1267
  check = Number(key);
840
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1268
+ isIdentifier = check >= 0 || isValidIdentifier(key);
841
1269
  if (isReferenceInStack(ctx, val)) {
842
1270
  refParam = getRefParam(ctx, val.i);
843
1271
  if (isIdentifier && Number.isNaN(check)) {
844
1272
  createObjectAssign(ctx, sourceID, key, refParam);
845
1273
  } else {
846
- createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1274
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
847
1275
  }
848
1276
  } else {
849
- if (hasPrev) {
850
- result += ",";
851
- }
852
- result += isIdentifier ? key : quote(key);
853
- result += ":" + serializeTree(ctx, val);
1277
+ result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
854
1278
  hasPrev = true;
855
1279
  }
856
1280
  }
@@ -858,7 +1282,7 @@ function serializeObject(ctx, sourceID, node) {
858
1282
  return "{" + result + "}";
859
1283
  }
860
1284
  function serializeWithObjectAssign(ctx, value, id, serialized) {
861
- const fields = serializeObject(ctx, id, value);
1285
+ const fields = serializeProperties(ctx, id, value);
862
1286
  if (fields !== "{}") {
863
1287
  return "Object.assign(" + serialized + "," + fields + ")";
864
1288
  }
@@ -882,11 +1306,11 @@ function serializeAssignments(ctx, sourceID, node) {
882
1306
  check = Number(key);
883
1307
  parentAssignment = ctx.assignments;
884
1308
  ctx.assignments = mainAssignments;
885
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1309
+ isIdentifier = check >= 0 || isValidIdentifier(key);
886
1310
  if (isIdentifier && Number.isNaN(check)) {
887
1311
  createObjectAssign(ctx, sourceID, key, refParam);
888
1312
  } else {
889
- createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1313
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
890
1314
  }
891
1315
  ctx.assignments = parentAssignment;
892
1316
  }
@@ -901,19 +1325,21 @@ function serializeDictionary(ctx, i, d, init) {
901
1325
  markRef(ctx, i);
902
1326
  const assignments = serializeAssignments(ctx, i, d);
903
1327
  if (assignments) {
904
- const ref = getRefParam(ctx, i);
905
- return "(" + assignRef(ctx, i, init) + "," + assignments + ref + ")";
1328
+ return "(" + assignRef2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
906
1329
  }
907
1330
  }
908
1331
  }
909
- return assignRef(ctx, i, init);
1332
+ return assignRef2(ctx, i, init);
910
1333
  }
911
1334
  function serializeNullConstructor(ctx, node) {
912
1335
  return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
913
1336
  }
1337
+ function serializeObject(ctx, node) {
1338
+ return assignRef2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
1339
+ }
914
1340
  function serializeSet(ctx, node) {
915
1341
  let serialized = "new Set";
916
- const size = node.a.length;
1342
+ const size = node.l;
917
1343
  if (size) {
918
1344
  let result = "";
919
1345
  ctx.stack.push(node.i);
@@ -924,10 +1350,7 @@ function serializeSet(ctx, node) {
924
1350
  if (isReferenceInStack(ctx, item)) {
925
1351
  createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
926
1352
  } else {
927
- if (hasPrev) {
928
- result += ",";
929
- }
930
- result += serializeTree(ctx, item);
1353
+ result += (hasPrev ? "," : "") + serializeTree(ctx, item);
931
1354
  hasPrev = true;
932
1355
  }
933
1356
  }
@@ -936,7 +1359,7 @@ function serializeSet(ctx, node) {
936
1359
  serialized += "([" + result + "])";
937
1360
  }
938
1361
  }
939
- return assignRef(ctx, node.i, serialized);
1362
+ return assignRef2(ctx, node.i, serialized);
940
1363
  }
941
1364
  function serializeMap(ctx, node) {
942
1365
  let serialized = "new Map";
@@ -970,10 +1393,7 @@ function serializeMap(ctx, node) {
970
1393
  createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
971
1394
  ctx.stack = parent;
972
1395
  } else {
973
- if (hasPrev) {
974
- result += ",";
975
- }
976
- result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
1396
+ result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
977
1397
  hasPrev = true;
978
1398
  }
979
1399
  }
@@ -982,22 +1402,22 @@ function serializeMap(ctx, node) {
982
1402
  serialized += "([" + result + "])";
983
1403
  }
984
1404
  }
985
- return assignRef(ctx, node.i, serialized);
1405
+ return assignRef2(ctx, node.i, serialized);
986
1406
  }
987
1407
  function serializeAggregateError(ctx, node) {
988
1408
  ctx.stack.push(node.i);
989
- const serialized = "new AggregateError(" + serializeTree(ctx, node.n) + "," + quote(node.m) + ")";
1409
+ const serialized = "new AggregateError(" + serializeNodeList(ctx, node) + ',"' + quote(node.m) + '")';
990
1410
  ctx.stack.pop();
991
1411
  return serializeDictionary(ctx, node.i, node.d, serialized);
992
1412
  }
993
1413
  function serializeError(ctx, node) {
994
- const serialized = "new " + node.c + "(" + quote(node.m) + ")";
1414
+ const serialized = "new " + node.c + '("' + quote(node.m) + '")';
995
1415
  return serializeDictionary(ctx, node.i, node.d, serialized);
996
1416
  }
997
1417
  function serializePromise(ctx, node) {
998
1418
  let serialized;
999
- if (isReferenceInStack(ctx, node.n)) {
1000
- const ref = getRefParam(ctx, node.n.i);
1419
+ if (isReferenceInStack(ctx, node.f)) {
1420
+ const ref = getRefParam(ctx, node.f.i);
1001
1421
  if (ctx.features & 4 /* ArrowFunction */) {
1002
1422
  serialized = "Promise.resolve().then(()=>" + ref + ")";
1003
1423
  } else {
@@ -1005,18 +1425,20 @@ function serializePromise(ctx, node) {
1005
1425
  }
1006
1426
  } else {
1007
1427
  ctx.stack.push(node.i);
1008
- const result = serializeTree(ctx, node.n);
1428
+ const result = serializeTree(ctx, node.f);
1009
1429
  ctx.stack.pop();
1010
1430
  serialized = "Promise.resolve(" + result + ")";
1011
1431
  }
1012
- return assignRef(ctx, node.i, serialized);
1432
+ return assignRef2(ctx, node.i, serialized);
1013
1433
  }
1014
1434
  function serializeTypedArray(ctx, node) {
1015
- let args = "[" + node.s + "]";
1016
- if (node.l !== 0) {
1017
- args += "," + node.l.toString();
1435
+ let result = "";
1436
+ const isBigInt = node.t === 23 /* BigIntTypedArray */;
1437
+ for (let i = 0, len = node.s.length; i < len; i++) {
1438
+ result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
1018
1439
  }
1019
- return assignRef(ctx, node.i, "new " + node.c + "(" + args + ")");
1440
+ const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
1441
+ return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
1020
1442
  }
1021
1443
  function serializeIterable(ctx, node) {
1022
1444
  const parent = ctx.stack;
@@ -1040,37 +1462,55 @@ function serializeIterable(ctx, node) {
1040
1462
  }
1041
1463
  function serializeTree(ctx, node) {
1042
1464
  switch (node.t) {
1043
- case 0 /* Primitive */:
1044
- return String(node.s);
1045
- case 1 /* BigInt */:
1046
- return node.s;
1047
- case 2 /* Reference */:
1465
+ case 0 /* Number */:
1466
+ return "" + node.s;
1467
+ case 1 /* String */:
1468
+ return '"' + node.s + '"';
1469
+ case 2 /* Boolean */:
1470
+ return node.s ? "!0" : "!1";
1471
+ case 4 /* Undefined */:
1472
+ return "void 0";
1473
+ case 3 /* Null */:
1474
+ return "null";
1475
+ case 5 /* NegativeZero */:
1476
+ return "-0";
1477
+ case 6 /* Infinity */:
1478
+ return "1/0";
1479
+ case 7 /* NegativeInfinity */:
1480
+ return "-1/0";
1481
+ case 8 /* NaN */:
1482
+ return "NaN";
1483
+ case 9 /* BigInt */:
1484
+ return node.s + "n";
1485
+ case 10 /* Reference */:
1048
1486
  return getRefParam(ctx, node.i);
1049
- case 7 /* Array */:
1487
+ case 15 /* Array */:
1050
1488
  return serializeArray(ctx, node);
1051
- case 8 /* Object */:
1052
- return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1053
- case 9 /* NullConstructor */:
1489
+ case 16 /* Object */:
1490
+ return serializeObject(ctx, node);
1491
+ case 17 /* NullConstructor */:
1054
1492
  return serializeNullConstructor(ctx, node);
1055
- case 3 /* Date */:
1056
- return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
1057
- case 4 /* RegExp */:
1058
- return assignRef(ctx, node.i, node.s);
1059
- case 5 /* Set */:
1493
+ case 11 /* Date */:
1494
+ return assignRef2(ctx, node.i, 'new Date("' + node.s + '")');
1495
+ case 12 /* RegExp */:
1496
+ return assignRef2(ctx, node.i, "/" + node.c + "/" + node.m);
1497
+ case 13 /* Set */:
1060
1498
  return serializeSet(ctx, node);
1061
- case 6 /* Map */:
1499
+ case 14 /* Map */:
1062
1500
  return serializeMap(ctx, node);
1063
- case 15 /* BigIntTypedArray */:
1064
- case 14 /* TypedArray */:
1501
+ case 23 /* BigIntTypedArray */:
1502
+ case 22 /* TypedArray */:
1065
1503
  return serializeTypedArray(ctx, node);
1066
- case 12 /* AggregateError */:
1504
+ case 20 /* AggregateError */:
1067
1505
  return serializeAggregateError(ctx, node);
1068
- case 11 /* Error */:
1506
+ case 19 /* Error */:
1069
1507
  return serializeError(ctx, node);
1070
- case 13 /* Iterable */:
1508
+ case 21 /* Iterable */:
1071
1509
  return serializeIterable(ctx, node);
1072
- case 10 /* Promise */:
1510
+ case 18 /* Promise */:
1073
1511
  return serializePromise(ctx, node);
1512
+ case 24 /* WKSymbol */:
1513
+ return SYMBOL_STRING[node.s];
1074
1514
  default:
1075
1515
  throw new Error("Unsupported type");
1076
1516
  }
@@ -1101,15 +1541,15 @@ function generateNodeList2(ctx, current) {
1101
1541
  }
1102
1542
  function generateArrayNode2(ctx, id, current) {
1103
1543
  return {
1104
- t: 7 /* Array */,
1544
+ t: 15 /* Array */,
1105
1545
  i: id,
1106
1546
  s: void 0,
1107
- l: void 0,
1547
+ l: current.length,
1108
1548
  c: void 0,
1109
1549
  m: void 0,
1110
1550
  d: void 0,
1111
1551
  a: generateNodeList2(ctx, current),
1112
- n: void 0
1552
+ f: void 0
1113
1553
  };
1114
1554
  }
1115
1555
  function generateMapNode2(ctx, id, current) {
@@ -1137,7 +1577,7 @@ function generateMapNode2(ctx, id, current) {
1137
1577
  valueNodes[nodeSize + i] = parse2(ctx, deferredValue[i]);
1138
1578
  }
1139
1579
  return {
1140
- t: 6 /* Map */,
1580
+ t: 14 /* Map */,
1141
1581
  i: id,
1142
1582
  s: void 0,
1143
1583
  l: void 0,
@@ -1145,7 +1585,7 @@ function generateMapNode2(ctx, id, current) {
1145
1585
  m: void 0,
1146
1586
  d: { k: keyNodes, v: valueNodes, s: len },
1147
1587
  a: void 0,
1148
- n: void 0
1588
+ f: void 0
1149
1589
  };
1150
1590
  }
1151
1591
  function generateSetNode2(ctx, id, current) {
@@ -1166,15 +1606,15 @@ function generateSetNode2(ctx, id, current) {
1166
1606
  nodes[nodeSize + i] = parse2(ctx, deferred[i]);
1167
1607
  }
1168
1608
  return {
1169
- t: 5 /* Set */,
1609
+ t: 13 /* Set */,
1170
1610
  i: id,
1171
1611
  s: void 0,
1172
- l: void 0,
1612
+ l: len,
1173
1613
  c: void 0,
1174
1614
  m: void 0,
1175
1615
  d: void 0,
1176
1616
  a: nodes,
1177
- n: void 0
1617
+ f: void 0
1178
1618
  };
1179
1619
  }
1180
1620
  function generateProperties2(ctx, properties) {
@@ -1210,19 +1650,20 @@ function generateProperties2(ctx, properties) {
1210
1650
  };
1211
1651
  }
1212
1652
  function generateIterableNode2(ctx, id, current) {
1213
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
1653
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
1214
1654
  const options = getIterableOptions(current);
1655
+ const array = Array.from(current);
1215
1656
  return {
1216
- t: 13 /* Iterable */,
1657
+ t: 21 /* Iterable */,
1217
1658
  i: id,
1218
1659
  s: void 0,
1219
- l: void 0,
1660
+ l: array.length,
1220
1661
  c: void 0,
1221
1662
  m: void 0,
1222
1663
  // Parse options first before the items
1223
1664
  d: options ? generateProperties2(ctx, options) : void 0,
1224
- a: generateNodeList2(ctx, Array.from(current)),
1225
- n: void 0
1665
+ a: generateNodeList2(ctx, array),
1666
+ f: void 0
1226
1667
  };
1227
1668
  }
1228
1669
  function generateObjectNode2(ctx, id, current, empty) {
@@ -1230,7 +1671,7 @@ function generateObjectNode2(ctx, id, current, empty) {
1230
1671
  return generateIterableNode2(ctx, id, current);
1231
1672
  }
1232
1673
  return {
1233
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1674
+ t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
1234
1675
  i: id,
1235
1676
  s: void 0,
1236
1677
  l: void 0,
@@ -1238,37 +1679,37 @@ function generateObjectNode2(ctx, id, current, empty) {
1238
1679
  m: void 0,
1239
1680
  d: generateProperties2(ctx, current),
1240
1681
  a: void 0,
1241
- n: void 0
1682
+ f: void 0
1242
1683
  };
1243
1684
  }
1244
1685
  function generateAggregateErrorNode2(ctx, id, current) {
1245
1686
  const options = getErrorOptions(ctx, current);
1246
1687
  const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1247
1688
  return {
1248
- t: 12 /* AggregateError */,
1689
+ t: 20 /* AggregateError */,
1249
1690
  i: id,
1250
1691
  s: void 0,
1251
- l: void 0,
1692
+ l: current.errors.length,
1252
1693
  c: void 0,
1253
1694
  m: current.message,
1254
1695
  d: optionsNode,
1255
- a: void 0,
1256
- n: parse2(ctx, current.errors)
1696
+ a: generateNodeList2(ctx, current.errors),
1697
+ f: void 0
1257
1698
  };
1258
1699
  }
1259
1700
  function generateErrorNode2(ctx, id, current) {
1260
1701
  const options = getErrorOptions(ctx, current);
1261
1702
  const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1262
1703
  return {
1263
- t: 11 /* Error */,
1704
+ t: 19 /* Error */,
1264
1705
  i: id,
1265
1706
  s: void 0,
1266
1707
  l: void 0,
1267
- c: getErrorConstructor(current),
1708
+ c: getErrorConstructorName(current),
1268
1709
  m: current.message,
1269
1710
  d: optionsNode,
1270
1711
  a: void 0,
1271
- n: void 0
1712
+ f: void 0
1272
1713
  };
1273
1714
  }
1274
1715
  function parse2(ctx, current) {
@@ -1278,25 +1719,30 @@ function parse2(ctx, current) {
1278
1719
  case "undefined":
1279
1720
  return UNDEFINED_NODE;
1280
1721
  case "string":
1281
- return createPrimitiveNode(quote(current));
1722
+ return createStringNode(current);
1282
1723
  case "number":
1283
- if (Object.is(current, -0)) {
1284
- return NEG_ZERO_NODE;
1724
+ switch (current) {
1725
+ case Infinity:
1726
+ return INFINITY_NODE;
1727
+ case -Infinity:
1728
+ return NEG_INFINITY_NODE;
1729
+ default:
1730
+ break;
1285
1731
  }
1286
- if (Object.is(current, Infinity)) {
1287
- return createPrimitiveNode("1/0");
1732
+ if (current !== current) {
1733
+ return NAN_NODE;
1288
1734
  }
1289
- if (Object.is(current, -Infinity)) {
1290
- return createPrimitiveNode("-1/0");
1735
+ if (Object.is(current, -0)) {
1736
+ return NEG_ZERO_NODE;
1291
1737
  }
1292
- return createPrimitiveNode(current);
1738
+ return createNumberNode(current);
1293
1739
  case "bigint":
1294
1740
  return createBigIntNode(ctx, current);
1295
1741
  case "object": {
1296
1742
  if (!current) {
1297
1743
  return NULL_NODE;
1298
1744
  }
1299
- const id = createRef(ctx, current, true);
1745
+ const id = createRef(ctx, current);
1300
1746
  if (ctx.markedRefs.has(id)) {
1301
1747
  return createReferenceNode(id);
1302
1748
  }
@@ -1345,8 +1791,11 @@ function parse2(ctx, current) {
1345
1791
  default:
1346
1792
  break;
1347
1793
  }
1348
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1349
- return generateAggregateErrorNode2(ctx, id, current);
1794
+ if (current instanceof AggregateError) {
1795
+ if (ctx.features & 1 /* AggregateError */) {
1796
+ return generateAggregateErrorNode2(ctx, id, current);
1797
+ }
1798
+ return generateErrorNode2(ctx, id, current);
1350
1799
  }
1351
1800
  if (current instanceof Error) {
1352
1801
  return generateErrorNode2(ctx, id, current);
@@ -1356,14 +1805,18 @@ function parse2(ctx, current) {
1356
1805
  }
1357
1806
  throw new Error("Unsupported type");
1358
1807
  }
1808
+ case "symbol":
1809
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
1810
+ assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
1811
+ return createWKSymbolNode(current);
1359
1812
  default:
1360
1813
  throw new Error("Unsupported type");
1361
1814
  }
1362
1815
  }
1363
1816
  function parseSync(ctx, current) {
1364
1817
  const result = parse2(ctx, current);
1365
- const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
1366
- return [result, createRef(ctx, current, false), isObject];
1818
+ const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
1819
+ return [result, getRootID(ctx, current), isObject];
1367
1820
  }
1368
1821
 
1369
1822
  // src/index.ts
@@ -1438,7 +1891,11 @@ function compileJSON(source) {
1438
1891
  return finalize(serial, source.r, source.i, result);
1439
1892
  }
1440
1893
  function fromJSON(source) {
1441
- return deserialize(compileJSON(source));
1894
+ const serial = createSerializationContext({
1895
+ features: source.f,
1896
+ markedRefs: source.m
1897
+ });
1898
+ return deserializeTree(serial, source.t);
1442
1899
  }
1443
1900
  var src_default = serialize;
1444
1901
  export {