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.
@@ -44,7 +44,7 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
44
44
  Feature2[Feature2["ObjectAssign"] = 128] = "ObjectAssign";
45
45
  Feature2[Feature2["Promise"] = 256] = "Promise";
46
46
  Feature2[Feature2["Set"] = 512] = "Set";
47
- Feature2[Feature2["SymbolIterator"] = 1024] = "SymbolIterator";
47
+ Feature2[Feature2["Symbol"] = 1024] = "Symbol";
48
48
  Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
49
49
  Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
50
50
  return Feature2;
@@ -88,41 +88,42 @@ function createSerializationContext(options) {
88
88
  validRefs: [],
89
89
  refSize: 0,
90
90
  features: options.features,
91
- markedRefs: new Set(options.markedRefs)
91
+ markedRefs: new Set(options.markedRefs),
92
+ valueMap: /* @__PURE__ */ new Map()
92
93
  };
93
94
  }
94
95
  function markRef(ctx, current) {
95
96
  ctx.markedRefs.add(current);
96
97
  }
97
- function createValidRef(ctx, index) {
98
- const current = ctx.validRefs[index];
99
- if (current == null) {
100
- const value = ctx.refSize++;
101
- ctx.validRefs[index] = value;
102
- return value;
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;
103
108
  }
104
- return current;
109
+ return identifier;
105
110
  }
106
- function getRefParam(ctx, index) {
107
- const actualIndex = createValidRef(ctx, index);
108
- if (ctx.vars[actualIndex]) {
109
- return ctx.vars[actualIndex];
111
+ function getRootID(ctx, current) {
112
+ const ref = ctx.refs.get(current);
113
+ if (ref == null) {
114
+ return ctx.refs.size;
110
115
  }
111
- const result = getIdentifier(actualIndex);
112
- ctx.vars[actualIndex] = result;
113
- return result;
116
+ return ref;
114
117
  }
115
- function createRef(ctx, current, mark) {
118
+ function createRef(ctx, current) {
116
119
  const ref = ctx.refs.get(current);
117
- if (ref != null) {
118
- if (mark) {
119
- markRef(ctx, ref);
120
- }
121
- return ref;
120
+ if (ref == null) {
121
+ const id = ctx.refs.size;
122
+ ctx.refs.set(current, id);
123
+ return id;
122
124
  }
123
- const id = ctx.refs.size;
124
- ctx.refs.set(current, id);
125
- return id;
125
+ markRef(ctx, ref);
126
+ return ref;
126
127
  }
127
128
 
128
129
  // src/assert.ts
@@ -171,13 +172,151 @@ function quote(str) {
171
172
  } else {
172
173
  result += str.slice(lastPos);
173
174
  }
174
- return '"' + result + '"';
175
+ return result;
176
+ }
177
+ function invQuote(str) {
178
+ 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");
175
179
  }
176
180
 
181
+ // src/tree/symbols.ts
182
+ var SYMBOL_STRING = {
183
+ [0 /* AsyncIterator */]: "Symbol.asyncIterator",
184
+ [1 /* HasInstance */]: "Symbol.hasInstance",
185
+ [2 /* IsConcatSpreadable */]: "Symbol.isConcatSpreadable",
186
+ [3 /* Iterator */]: "Symbol.iterator",
187
+ [4 /* Match */]: "Symbol.match",
188
+ [5 /* MatchAll */]: "Symbol.matchAll",
189
+ [6 /* Replace */]: "Symbol.replace",
190
+ [7 /* Search */]: "Symbol.search",
191
+ [8 /* Species */]: "Symbol.species",
192
+ [9 /* Split */]: "Symbol.split",
193
+ [10 /* ToPrimitive */]: "Symbol.toPrimitive",
194
+ [11 /* ToStringTag */]: "Symbol.toStringTag",
195
+ [12 /* Unscopables */]: "Symbol.unscopables"
196
+ };
197
+ var INV_SYMBOL_REF = {
198
+ [Symbol.asyncIterator]: 0 /* AsyncIterator */,
199
+ [Symbol.hasInstance]: 1 /* HasInstance */,
200
+ [Symbol.isConcatSpreadable]: 2 /* IsConcatSpreadable */,
201
+ [Symbol.iterator]: 3 /* Iterator */,
202
+ [Symbol.match]: 4 /* Match */,
203
+ [Symbol.matchAll]: 5 /* MatchAll */,
204
+ [Symbol.replace]: 6 /* Replace */,
205
+ [Symbol.search]: 7 /* Search */,
206
+ [Symbol.species]: 8 /* Species */,
207
+ [Symbol.split]: 9 /* Split */,
208
+ [Symbol.toPrimitive]: 10 /* ToPrimitive */,
209
+ [Symbol.toStringTag]: 11 /* ToStringTag */,
210
+ [Symbol.unscopables]: 12 /* Unscopables */
211
+ };
212
+ var SYMBOL_REF = {
213
+ [0 /* AsyncIterator */]: Symbol.asyncIterator,
214
+ [1 /* HasInstance */]: Symbol.hasInstance,
215
+ [2 /* IsConcatSpreadable */]: Symbol.isConcatSpreadable,
216
+ [3 /* Iterator */]: Symbol.iterator,
217
+ [4 /* Match */]: Symbol.match,
218
+ [5 /* MatchAll */]: Symbol.matchAll,
219
+ [6 /* Replace */]: Symbol.replace,
220
+ [7 /* Search */]: Symbol.search,
221
+ [8 /* Species */]: Symbol.species,
222
+ [9 /* Split */]: Symbol.split,
223
+ [10 /* ToPrimitive */]: Symbol.toPrimitive,
224
+ [11 /* ToStringTag */]: Symbol.toStringTag,
225
+ [12 /* Unscopables */]: Symbol.unscopables
226
+ };
227
+
177
228
  // src/tree/primitives.ts
178
- function createPrimitiveNode(value) {
229
+ var TRUE_NODE = {
230
+ t: 2 /* Boolean */,
231
+ i: void 0,
232
+ s: true,
233
+ l: void 0,
234
+ c: void 0,
235
+ m: void 0,
236
+ d: void 0,
237
+ a: void 0,
238
+ f: void 0
239
+ };
240
+ var FALSE_NODE = {
241
+ t: 2 /* Boolean */,
242
+ i: void 0,
243
+ s: false,
244
+ l: void 0,
245
+ c: void 0,
246
+ m: void 0,
247
+ d: void 0,
248
+ a: void 0,
249
+ f: void 0
250
+ };
251
+ var UNDEFINED_NODE = {
252
+ t: 4 /* Undefined */,
253
+ i: void 0,
254
+ s: void 0,
255
+ l: void 0,
256
+ c: void 0,
257
+ m: void 0,
258
+ d: void 0,
259
+ a: void 0,
260
+ f: void 0
261
+ };
262
+ var NULL_NODE = {
263
+ t: 3 /* Null */,
264
+ i: void 0,
265
+ s: void 0,
266
+ l: void 0,
267
+ c: void 0,
268
+ m: void 0,
269
+ d: void 0,
270
+ a: void 0,
271
+ f: void 0
272
+ };
273
+ var NEG_ZERO_NODE = {
274
+ t: 5 /* NegativeZero */,
275
+ i: void 0,
276
+ s: void 0,
277
+ l: void 0,
278
+ c: void 0,
279
+ m: void 0,
280
+ d: void 0,
281
+ a: void 0,
282
+ f: void 0
283
+ };
284
+ var INFINITY_NODE = {
285
+ t: 6 /* Infinity */,
286
+ i: void 0,
287
+ s: void 0,
288
+ l: void 0,
289
+ c: void 0,
290
+ m: void 0,
291
+ d: void 0,
292
+ a: void 0,
293
+ f: void 0
294
+ };
295
+ var NEG_INFINITY_NODE = {
296
+ t: 7 /* NegativeInfinity */,
297
+ i: void 0,
298
+ s: void 0,
299
+ l: void 0,
300
+ c: void 0,
301
+ m: void 0,
302
+ d: void 0,
303
+ a: void 0,
304
+ f: void 0
305
+ };
306
+ var NAN_NODE = {
307
+ t: 8 /* NaN */,
308
+ i: void 0,
309
+ s: void 0,
310
+ l: void 0,
311
+ c: void 0,
312
+ m: void 0,
313
+ d: void 0,
314
+ a: void 0,
315
+ f: void 0
316
+ };
317
+ function createNumberNode(value) {
179
318
  return {
180
- t: 0 /* Primitive */,
319
+ t: 0 /* Number */,
181
320
  i: void 0,
182
321
  s: value,
183
322
  l: void 0,
@@ -185,33 +324,39 @@ function createPrimitiveNode(value) {
185
324
  m: void 0,
186
325
  d: void 0,
187
326
  a: void 0,
188
- n: void 0
327
+ f: void 0
328
+ };
329
+ }
330
+ function createStringNode(value) {
331
+ return {
332
+ t: 1 /* String */,
333
+ i: void 0,
334
+ s: quote(value),
335
+ l: void 0,
336
+ c: void 0,
337
+ m: void 0,
338
+ d: void 0,
339
+ a: void 0,
340
+ f: void 0
189
341
  };
190
342
  }
191
- var TRUE_NODE = createPrimitiveNode("!0");
192
- var FALSE_NODE = createPrimitiveNode("!1");
193
- var UNDEFINED_NODE = createPrimitiveNode("void 0");
194
- var NULL_NODE = createPrimitiveNode(null);
195
- var NEG_ZERO_NODE = createPrimitiveNode("-0");
196
- var INFINITY_NODE = createPrimitiveNode("1/0");
197
- var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
198
343
  function createBigIntNode(ctx, current) {
199
344
  assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
200
345
  return {
201
- t: 1 /* BigInt */,
346
+ t: 9 /* BigInt */,
202
347
  i: void 0,
203
- s: current.toString() + "n",
348
+ s: "" + current,
204
349
  l: void 0,
205
350
  c: void 0,
206
351
  m: void 0,
207
352
  d: void 0,
208
353
  a: void 0,
209
- n: void 0
354
+ f: void 0
210
355
  };
211
356
  }
212
357
  function createReferenceNode(id) {
213
358
  return {
214
- t: 2 /* Reference */,
359
+ t: 10 /* Reference */,
215
360
  i: id,
216
361
  s: void 0,
217
362
  l: void 0,
@@ -219,48 +364,53 @@ function createReferenceNode(id) {
219
364
  m: void 0,
220
365
  d: void 0,
221
366
  a: void 0,
222
- n: void 0
367
+ f: void 0
223
368
  };
224
369
  }
225
370
  function createDateNode(id, current) {
226
371
  return {
227
- t: 3 /* Date */,
372
+ t: 11 /* Date */,
228
373
  i: id,
229
374
  s: current.toISOString(),
230
375
  l: void 0,
231
376
  c: void 0,
232
377
  m: void 0,
233
378
  d: void 0,
234
- n: void 0,
379
+ f: void 0,
235
380
  a: void 0
236
381
  };
237
382
  }
238
383
  function createRegExpNode(id, current) {
239
384
  return {
240
- t: 4 /* RegExp */,
385
+ t: 12 /* RegExp */,
241
386
  i: id,
242
- s: String(current),
387
+ s: void 0,
243
388
  l: void 0,
244
- c: void 0,
245
- m: void 0,
389
+ c: current.source,
390
+ m: current.flags,
246
391
  d: void 0,
247
392
  a: void 0,
248
- n: void 0
393
+ f: void 0
249
394
  };
250
395
  }
251
396
  function createTypedArrayNode(ctx, id, current) {
252
397
  const constructor = current.constructor.name;
253
398
  assert(ctx.features & 2048 /* TypedArray */, `Unsupported value type "${constructor}"`);
399
+ const len = current.length;
400
+ const values = new Array(len);
401
+ for (let i = 0; i < len; i++) {
402
+ values[i] = "" + current[i];
403
+ }
254
404
  return {
255
- t: 14 /* TypedArray */,
405
+ t: 22 /* TypedArray */,
256
406
  i: id,
257
- s: current.toString(),
407
+ s: values,
258
408
  l: current.byteOffset,
259
409
  c: constructor,
260
410
  m: void 0,
261
411
  d: void 0,
262
412
  a: void 0,
263
- n: void 0
413
+ f: void 0
264
414
  };
265
415
  }
266
416
  var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
@@ -270,28 +420,39 @@ function createBigIntTypedArrayNode(ctx, id, current) {
270
420
  (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
271
421
  `Unsupported value type "${constructor}"`
272
422
  );
273
- let result = "";
274
- for (let i = 0, len = current.length; i < len; i++) {
275
- if (i !== 0) {
276
- result += ",";
277
- }
278
- result += current[i].toString() + "n";
423
+ const len = current.length;
424
+ const values = new Array(len);
425
+ for (let i = 0; i < len; i++) {
426
+ values[i] = "" + current[i];
279
427
  }
280
428
  return {
281
- t: 15 /* BigIntTypedArray */,
429
+ t: 23 /* BigIntTypedArray */,
282
430
  i: id,
283
- s: result,
431
+ s: values,
284
432
  l: current.byteOffset,
285
433
  c: constructor,
286
434
  m: void 0,
287
435
  d: void 0,
288
436
  a: void 0,
289
- n: void 0
437
+ f: void 0
438
+ };
439
+ }
440
+ function createWKSymbolNode(current) {
441
+ return {
442
+ t: 24 /* WKSymbol */,
443
+ i: void 0,
444
+ s: INV_SYMBOL_REF[current],
445
+ l: void 0,
446
+ c: void 0,
447
+ m: void 0,
448
+ d: void 0,
449
+ a: void 0,
450
+ f: void 0
290
451
  };
291
452
  }
292
453
 
293
454
  // src/tree/shared.ts
294
- function getErrorConstructor(error) {
455
+ function getErrorConstructorName(error) {
295
456
  if (error instanceof EvalError) {
296
457
  return "EvalError";
297
458
  }
@@ -312,9 +473,29 @@ function getErrorConstructor(error) {
312
473
  }
313
474
  return "Error";
314
475
  }
476
+ function getErrorConstructor(errorName) {
477
+ switch (errorName) {
478
+ case "Error":
479
+ return Error;
480
+ case "EvalError":
481
+ return EvalError;
482
+ case "RangeError":
483
+ return RangeError;
484
+ case "ReferenceError":
485
+ return ReferenceError;
486
+ case "SyntaxError":
487
+ return SyntaxError;
488
+ case "TypeError":
489
+ return TypeError;
490
+ case "URIError":
491
+ return URIError;
492
+ default:
493
+ throw new Error(`Unknown Error constructor "${errorName}"`);
494
+ }
495
+ }
315
496
  function getErrorOptions(ctx, error) {
316
497
  let options;
317
- const constructor = getErrorConstructor(error);
498
+ const constructor = getErrorConstructorName(error);
318
499
  if (error.name !== constructor) {
319
500
  options = { name: error.name };
320
501
  } else if (error.constructor.name !== constructor) {
@@ -374,6 +555,39 @@ function isIterable(value) {
374
555
  }
375
556
  return Symbol.iterator in value;
376
557
  }
558
+ function getTypedArrayConstructor(name) {
559
+ switch (name) {
560
+ case "Int8Array":
561
+ return Int8Array;
562
+ case "Int16Array":
563
+ return Int16Array;
564
+ case "Int32Array":
565
+ return Int32Array;
566
+ case "Uint8Array":
567
+ return Uint8Array;
568
+ case "Uint16Array":
569
+ return Uint16Array;
570
+ case "Uint32Array":
571
+ return Uint32Array;
572
+ case "Uint8ClampedArray":
573
+ return Uint8ClampedArray;
574
+ case "Float32Array":
575
+ return Float32Array;
576
+ case "Float64Array":
577
+ return Float64Array;
578
+ case "BigInt64Array":
579
+ return BigInt64Array;
580
+ case "BigUint64Array":
581
+ return BigUint64Array;
582
+ default:
583
+ throw new Error(`Unknown TypedArray "${name}"`);
584
+ }
585
+ }
586
+ var IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
587
+ function isValidIdentifier(name) {
588
+ const char = name[0];
589
+ return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
590
+ }
377
591
 
378
592
  // src/tree/async.ts
379
593
  async function generateNodeList(ctx, current) {
@@ -400,15 +614,15 @@ async function generateNodeList(ctx, current) {
400
614
  }
401
615
  async function generateArrayNode(ctx, id, current) {
402
616
  return {
403
- t: 7 /* Array */,
617
+ t: 15 /* Array */,
404
618
  i: id,
405
619
  s: void 0,
406
- l: void 0,
620
+ l: current.length,
407
621
  c: void 0,
408
622
  m: void 0,
409
623
  d: void 0,
410
624
  a: await generateNodeList(ctx, current),
411
- n: void 0
625
+ f: void 0
412
626
  };
413
627
  }
414
628
  async function generateMapNode(ctx, id, current) {
@@ -436,7 +650,7 @@ async function generateMapNode(ctx, id, current) {
436
650
  valueNodes[nodeSize + i] = await parse(ctx, deferredValue[i]);
437
651
  }
438
652
  return {
439
- t: 6 /* Map */,
653
+ t: 14 /* Map */,
440
654
  i: id,
441
655
  s: void 0,
442
656
  l: void 0,
@@ -444,7 +658,7 @@ async function generateMapNode(ctx, id, current) {
444
658
  m: void 0,
445
659
  d: { k: keyNodes, v: valueNodes, s: len },
446
660
  a: void 0,
447
- n: void 0
661
+ f: void 0
448
662
  };
449
663
  }
450
664
  async function generateSetNode(ctx, id, current) {
@@ -465,15 +679,15 @@ async function generateSetNode(ctx, id, current) {
465
679
  nodes[nodeSize + i] = await parse(ctx, deferred[i]);
466
680
  }
467
681
  return {
468
- t: 5 /* Set */,
682
+ t: 13 /* Set */,
469
683
  i: id,
470
684
  s: void 0,
471
- l: void 0,
685
+ l: len,
472
686
  c: void 0,
473
687
  m: void 0,
474
688
  d: void 0,
475
689
  a: nodes,
476
- n: void 0
690
+ f: void 0
477
691
  };
478
692
  }
479
693
  async function generateProperties(ctx, properties) {
@@ -509,25 +723,26 @@ async function generateProperties(ctx, properties) {
509
723
  };
510
724
  }
511
725
  async function generateIterableNode(ctx, id, current) {
512
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
726
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
513
727
  const options = getIterableOptions(current);
728
+ const array = Array.from(current);
514
729
  return {
515
- t: 13 /* Iterable */,
730
+ t: 21 /* Iterable */,
516
731
  i: id,
517
732
  s: void 0,
518
- l: void 0,
733
+ l: array.length,
519
734
  c: void 0,
520
735
  m: void 0,
521
736
  // Parse options first before the items
522
737
  d: options ? await generateProperties(ctx, options) : void 0,
523
- a: await generateNodeList(ctx, Array.from(current)),
524
- n: void 0
738
+ a: await generateNodeList(ctx, array),
739
+ f: void 0
525
740
  };
526
741
  }
527
742
  async function generatePromiseNode(ctx, id, current) {
528
743
  assert(ctx.features & 256 /* Promise */, 'Unsupported type "Promise"');
529
744
  return current.then(async (value) => ({
530
- t: 10 /* Promise */,
745
+ t: 18 /* Promise */,
531
746
  i: id,
532
747
  s: void 0,
533
748
  l: void 0,
@@ -536,7 +751,7 @@ async function generatePromiseNode(ctx, id, current) {
536
751
  // Parse options first before the items
537
752
  d: void 0,
538
753
  a: void 0,
539
- n: await parse(ctx, value)
754
+ f: await parse(ctx, value)
540
755
  }));
541
756
  }
542
757
  async function generateObjectNode(ctx, id, current, empty) {
@@ -547,7 +762,7 @@ async function generateObjectNode(ctx, id, current, empty) {
547
762
  return generatePromiseNode(ctx, id, current);
548
763
  }
549
764
  return {
550
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
765
+ t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
551
766
  i: id,
552
767
  s: void 0,
553
768
  l: void 0,
@@ -555,37 +770,37 @@ async function generateObjectNode(ctx, id, current, empty) {
555
770
  m: void 0,
556
771
  d: await generateProperties(ctx, current),
557
772
  a: void 0,
558
- n: void 0
773
+ f: void 0
559
774
  };
560
775
  }
561
776
  async function generateAggregateErrorNode(ctx, id, current) {
562
777
  const options = getErrorOptions(ctx, current);
563
778
  const optionsNode = options ? await generateProperties(ctx, options) : void 0;
564
779
  return {
565
- t: 12 /* AggregateError */,
780
+ t: 20 /* AggregateError */,
566
781
  i: id,
567
782
  s: void 0,
568
- l: void 0,
783
+ l: current.errors.length,
569
784
  c: void 0,
570
785
  m: current.message,
571
786
  d: optionsNode,
572
- a: void 0,
573
- n: await parse(ctx, current.errors)
787
+ a: await generateNodeList(ctx, current.errors),
788
+ f: void 0
574
789
  };
575
790
  }
576
791
  async function generateErrorNode(ctx, id, current) {
577
792
  const options = getErrorOptions(ctx, current);
578
793
  const optionsNode = options ? await generateProperties(ctx, options) : void 0;
579
794
  return {
580
- t: 11 /* Error */,
795
+ t: 19 /* Error */,
581
796
  i: id,
582
797
  s: void 0,
583
798
  l: void 0,
584
- c: getErrorConstructor(current),
799
+ c: getErrorConstructorName(current),
585
800
  m: current.message,
586
801
  d: optionsNode,
587
802
  a: void 0,
588
- n: void 0
803
+ f: void 0
589
804
  };
590
805
  }
591
806
  async function parse(ctx, current) {
@@ -595,25 +810,30 @@ async function parse(ctx, current) {
595
810
  case "undefined":
596
811
  return UNDEFINED_NODE;
597
812
  case "string":
598
- return createPrimitiveNode(quote(current));
813
+ return createStringNode(current);
599
814
  case "number":
600
- if (Object.is(current, -0)) {
601
- return NEG_ZERO_NODE;
815
+ switch (current) {
816
+ case Infinity:
817
+ return INFINITY_NODE;
818
+ case -Infinity:
819
+ return NEG_INFINITY_NODE;
820
+ default:
821
+ break;
602
822
  }
603
- if (Object.is(current, Infinity)) {
604
- return createPrimitiveNode("1/0");
823
+ if (current !== current) {
824
+ return NAN_NODE;
605
825
  }
606
- if (Object.is(current, -Infinity)) {
607
- return createPrimitiveNode("-1/0");
826
+ if (Object.is(current, -0)) {
827
+ return NEG_ZERO_NODE;
608
828
  }
609
- return createPrimitiveNode(current);
829
+ return createNumberNode(current);
610
830
  case "bigint":
611
831
  return createBigIntNode(ctx, current);
612
832
  case "object": {
613
833
  if (!current) {
614
834
  return NULL_NODE;
615
835
  }
616
- const id = createRef(ctx, current, true);
836
+ const id = createRef(ctx, current);
617
837
  if (ctx.markedRefs.has(id)) {
618
838
  return createReferenceNode(id);
619
839
  }
@@ -682,8 +902,11 @@ async function parse(ctx, current) {
682
902
  default:
683
903
  break;
684
904
  }
685
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
686
- return generateAggregateErrorNode(ctx, id, current);
905
+ if (current instanceof AggregateError) {
906
+ if (ctx.features & 1 /* AggregateError */) {
907
+ return generateAggregateErrorNode(ctx, id, current);
908
+ }
909
+ return generateErrorNode(ctx, id, current);
687
910
  }
688
911
  if (current instanceof Error) {
689
912
  return generateErrorNode(ctx, id, current);
@@ -699,14 +922,205 @@ async function parse(ctx, current) {
699
922
  }
700
923
  throw new Error("Unsupported type");
701
924
  }
925
+ case "symbol":
926
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
927
+ assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
928
+ return createWKSymbolNode(current);
702
929
  default:
703
930
  throw new Error("Unsupported type");
704
931
  }
705
932
  }
706
933
  async function parseAsync(ctx, current) {
707
934
  const result = await parse(ctx, current);
708
- const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
709
- return [result, createRef(ctx, current, false), isObject];
935
+ const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
936
+ return [result, getRootID(ctx, current), isObject];
937
+ }
938
+
939
+ // src/tree/deserialize.ts
940
+ function assignRef(ctx, index, value) {
941
+ ctx.valueMap.set(index, value);
942
+ return value;
943
+ }
944
+ function deserializeNodeList(ctx, node, result) {
945
+ let item;
946
+ for (let i = 0, len = node.a.length; i < len; i++) {
947
+ item = node.a[i];
948
+ if (item) {
949
+ result[i] = deserializeTree(ctx, item);
950
+ }
951
+ }
952
+ return result;
953
+ }
954
+ function deserializeArray(ctx, node) {
955
+ const result = assignRef(
956
+ ctx,
957
+ node.i,
958
+ new Array(node.l)
959
+ );
960
+ ctx.stack.push(node.i);
961
+ deserializeNodeList(ctx, node, result);
962
+ ctx.stack.pop();
963
+ return result;
964
+ }
965
+ function deserializeProperties(ctx, node, result) {
966
+ if (node.s === 0) {
967
+ return {};
968
+ }
969
+ for (let i = 0; i < node.s; i++) {
970
+ result[node.k[i]] = deserializeTree(ctx, node.v[i]);
971
+ }
972
+ return result;
973
+ }
974
+ function deserializeNullConstructor(ctx, node) {
975
+ const result = assignRef(ctx, node.i, /* @__PURE__ */ Object.create(null));
976
+ ctx.stack.push(node.i);
977
+ deserializeProperties(ctx, node.d, result);
978
+ ctx.stack.pop();
979
+ return result;
980
+ }
981
+ function deserializeObject(ctx, node) {
982
+ const result = assignRef(ctx, node.i, {});
983
+ ctx.stack.push(node.i);
984
+ deserializeProperties(ctx, node.d, result);
985
+ ctx.stack.pop();
986
+ return result;
987
+ }
988
+ function deserializeSet(ctx, node) {
989
+ const result = assignRef(ctx, node.i, /* @__PURE__ */ new Set());
990
+ ctx.stack.push(node.i);
991
+ for (let i = 0, len = node.a.length; i < len; i++) {
992
+ result.add(deserializeTree(ctx, node.a[i]));
993
+ }
994
+ ctx.stack.pop();
995
+ return result;
996
+ }
997
+ function deserializeMap(ctx, node) {
998
+ const result = assignRef(
999
+ ctx,
1000
+ node.i,
1001
+ /* @__PURE__ */ new Map()
1002
+ );
1003
+ ctx.stack.push(node.i);
1004
+ for (let i = 0; i < node.d.s; i++) {
1005
+ result.set(
1006
+ deserializeTree(ctx, node.d.k[i]),
1007
+ deserializeTree(ctx, node.d.v[i])
1008
+ );
1009
+ }
1010
+ ctx.stack.pop();
1011
+ return result;
1012
+ }
1013
+ function deserializeDictionary(ctx, node, result) {
1014
+ if (node.d) {
1015
+ ctx.stack.push(node.i);
1016
+ const fields = deserializeProperties(ctx, node.d, {});
1017
+ ctx.stack.pop();
1018
+ Object.assign(result, fields);
1019
+ }
1020
+ return result;
1021
+ }
1022
+ function deserializeAggregateError(ctx, node) {
1023
+ const result = assignRef(ctx, node.i, new AggregateError([], node.m));
1024
+ ctx.stack.push(node.i);
1025
+ result.errors = deserializeNodeList(ctx, node, new Array(node.l));
1026
+ ctx.stack.pop();
1027
+ return deserializeDictionary(ctx, node, result);
1028
+ }
1029
+ function deserializeError(ctx, node) {
1030
+ const ErrorConstructor = getErrorConstructor(node.c);
1031
+ const result = assignRef(ctx, node.i, new ErrorConstructor(node.m));
1032
+ return deserializeDictionary(ctx, node, result);
1033
+ }
1034
+ function createDeferred() {
1035
+ let resolver;
1036
+ return {
1037
+ resolve(v) {
1038
+ resolver(v);
1039
+ },
1040
+ promise: new Promise((res) => {
1041
+ resolver = res;
1042
+ })
1043
+ };
1044
+ }
1045
+ function deserializePromise(ctx, node) {
1046
+ const deferred = createDeferred();
1047
+ const result = assignRef(ctx, node.i, deferred.promise);
1048
+ deferred.resolve(deserializeTree(ctx, node.f));
1049
+ return result;
1050
+ }
1051
+ function deserializeTypedArray(ctx, node) {
1052
+ const TypedArray = getTypedArrayConstructor(node.c);
1053
+ const dummy = new TypedArray();
1054
+ const result = assignRef(ctx, node.i, new TypedArray(
1055
+ dummy.buffer,
1056
+ node.l
1057
+ ));
1058
+ for (let i = 0, len = node.s.length; i < len; i++) {
1059
+ result[i] = node.t === 23 /* BigIntTypedArray */ ? BigInt(node.s[i]) : Number(node.s[i]);
1060
+ }
1061
+ return result;
1062
+ }
1063
+ function deserializeIterable(ctx, node) {
1064
+ const values = [];
1065
+ deserializeNodeList(ctx, node, values);
1066
+ const result = assignRef(ctx, node.i, {
1067
+ [Symbol.iterator]: () => values.values()
1068
+ });
1069
+ return deserializeDictionary(ctx, node, result);
1070
+ }
1071
+ function deserializeTree(ctx, node) {
1072
+ switch (node.t) {
1073
+ case 0 /* Number */:
1074
+ case 2 /* Boolean */:
1075
+ return node.s;
1076
+ case 1 /* String */:
1077
+ return invQuote(node.s);
1078
+ case 4 /* Undefined */:
1079
+ return void 0;
1080
+ case 3 /* Null */:
1081
+ return null;
1082
+ case 5 /* NegativeZero */:
1083
+ return -0;
1084
+ case 6 /* Infinity */:
1085
+ return Infinity;
1086
+ case 7 /* NegativeInfinity */:
1087
+ return -Infinity;
1088
+ case 8 /* NaN */:
1089
+ return NaN;
1090
+ case 9 /* BigInt */:
1091
+ return BigInt(node.s);
1092
+ case 10 /* Reference */:
1093
+ return ctx.valueMap.get(node.i);
1094
+ case 15 /* Array */:
1095
+ return deserializeArray(ctx, node);
1096
+ case 16 /* Object */:
1097
+ return deserializeObject(ctx, node);
1098
+ case 17 /* NullConstructor */:
1099
+ return deserializeNullConstructor(ctx, node);
1100
+ case 11 /* Date */:
1101
+ return assignRef(ctx, node.i, new Date(node.s));
1102
+ case 12 /* RegExp */:
1103
+ return assignRef(ctx, node.i, new RegExp(node.c, node.m));
1104
+ case 13 /* Set */:
1105
+ return deserializeSet(ctx, node);
1106
+ case 14 /* Map */:
1107
+ return deserializeMap(ctx, node);
1108
+ case 23 /* BigIntTypedArray */:
1109
+ case 22 /* TypedArray */:
1110
+ return deserializeTypedArray(ctx, node);
1111
+ case 20 /* AggregateError */:
1112
+ return deserializeAggregateError(ctx, node);
1113
+ case 19 /* Error */:
1114
+ return deserializeError(ctx, node);
1115
+ case 21 /* Iterable */:
1116
+ return deserializeIterable(ctx, node);
1117
+ case 18 /* Promise */:
1118
+ return deserializePromise(ctx, node);
1119
+ case 24 /* WKSymbol */:
1120
+ return SYMBOL_REF[node.s];
1121
+ default:
1122
+ throw new Error("Unsupported type");
1123
+ }
710
1124
  }
711
1125
 
712
1126
  // src/tree/serialize.ts
@@ -730,30 +1144,48 @@ function mergeAssignments(assignments) {
730
1144
  for (let i = 1, len = assignments.length; i < len; i++) {
731
1145
  item = assignments[i];
732
1146
  if (item.t === prev.t) {
733
- if (item.t === "index" && item.v === prev.v) {
734
- current = {
735
- t: "index",
736
- s: item.s,
737
- k: void 0,
738
- v: getAssignmentExpression(current)
739
- };
740
- } else if (item.t === "map" && item.s === prev.s) {
741
- current = {
742
- t: "map",
743
- s: getAssignmentExpression(current),
744
- k: item.k,
745
- v: item.v
746
- };
747
- } else if (item.t === "set" && item.s === prev.s) {
748
- current = {
749
- t: "set",
750
- s: getAssignmentExpression(current),
751
- k: void 0,
752
- v: item.v
753
- };
754
- } else {
755
- newAssignments.push(current);
756
- current = item;
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;
757
1189
  }
758
1190
  } else {
759
1191
  newAssignments.push(current);
@@ -806,24 +1238,23 @@ function createMapSet(ctx, ref, key, value) {
806
1238
  }
807
1239
  function createArrayAssign(ctx, ref, index, value) {
808
1240
  markRef(ctx, ref);
809
- createAssignment(ctx, getRefParam(ctx, ref) + "[" + index.toString() + "]", value);
1241
+ createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
810
1242
  }
811
1243
  function createObjectAssign(ctx, ref, key, value) {
812
1244
  markRef(ctx, ref);
813
1245
  createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
814
1246
  }
815
- function assignRef(ctx, index, value) {
1247
+ function assignRef2(ctx, index, value) {
816
1248
  if (ctx.markedRefs.has(index)) {
817
1249
  return getRefParam(ctx, index) + "=" + value;
818
1250
  }
819
1251
  return value;
820
1252
  }
821
1253
  function isReferenceInStack(ctx, node) {
822
- return node.t === 2 /* Reference */ && ctx.stack.includes(node.i);
1254
+ return node.t === 10 /* Reference */ && ctx.stack.includes(node.i);
823
1255
  }
824
- var IDENTIFIER_CHECK = /^([$A-Z_][0-9A-Z_$]*)$/i;
825
1256
  function serializeNodeList(ctx, node) {
826
- const size = node.a.length;
1257
+ const size = node.l;
827
1258
  let values = "";
828
1259
  let item;
829
1260
  let isHoley = false;
@@ -844,18 +1275,15 @@ function serializeNodeList(ctx, node) {
844
1275
  isHoley = true;
845
1276
  }
846
1277
  }
847
- if (isHoley) {
848
- values += ",";
849
- }
850
- return "[" + values + "]";
1278
+ return "[" + values + (isHoley ? ",]" : "]");
851
1279
  }
852
1280
  function serializeArray(ctx, node) {
853
1281
  ctx.stack.push(node.i);
854
1282
  const result = serializeNodeList(ctx, node);
855
1283
  ctx.stack.pop();
856
- return assignRef(ctx, node.i, result);
1284
+ return assignRef2(ctx, node.i, result);
857
1285
  }
858
- function serializeObject(ctx, sourceID, node) {
1286
+ function serializeProperties(ctx, sourceID, node) {
859
1287
  if (node.s === 0) {
860
1288
  return "{}";
861
1289
  }
@@ -871,20 +1299,16 @@ function serializeObject(ctx, sourceID, node) {
871
1299
  key = node.k[i];
872
1300
  val = node.v[i];
873
1301
  check = Number(key);
874
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1302
+ isIdentifier = check >= 0 || isValidIdentifier(key);
875
1303
  if (isReferenceInStack(ctx, val)) {
876
1304
  refParam = getRefParam(ctx, val.i);
877
1305
  if (isIdentifier && Number.isNaN(check)) {
878
1306
  createObjectAssign(ctx, sourceID, key, refParam);
879
1307
  } else {
880
- createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1308
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
881
1309
  }
882
1310
  } else {
883
- if (hasPrev) {
884
- result += ",";
885
- }
886
- result += isIdentifier ? key : quote(key);
887
- result += ":" + serializeTree(ctx, val);
1311
+ result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + quote(key) + '"') + ":" + serializeTree(ctx, val);
888
1312
  hasPrev = true;
889
1313
  }
890
1314
  }
@@ -892,7 +1316,7 @@ function serializeObject(ctx, sourceID, node) {
892
1316
  return "{" + result + "}";
893
1317
  }
894
1318
  function serializeWithObjectAssign(ctx, value, id, serialized) {
895
- const fields = serializeObject(ctx, id, value);
1319
+ const fields = serializeProperties(ctx, id, value);
896
1320
  if (fields !== "{}") {
897
1321
  return "Object.assign(" + serialized + "," + fields + ")";
898
1322
  }
@@ -916,11 +1340,11 @@ function serializeAssignments(ctx, sourceID, node) {
916
1340
  check = Number(key);
917
1341
  parentAssignment = ctx.assignments;
918
1342
  ctx.assignments = mainAssignments;
919
- isIdentifier = check >= 0 || IDENTIFIER_CHECK.test(key);
1343
+ isIdentifier = check >= 0 || isValidIdentifier(key);
920
1344
  if (isIdentifier && Number.isNaN(check)) {
921
1345
  createObjectAssign(ctx, sourceID, key, refParam);
922
1346
  } else {
923
- createArrayAssign(ctx, sourceID, isIdentifier ? key : quote(key), refParam);
1347
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + quote(key) + '"', refParam);
924
1348
  }
925
1349
  ctx.assignments = parentAssignment;
926
1350
  }
@@ -935,19 +1359,21 @@ function serializeDictionary(ctx, i, d, init) {
935
1359
  markRef(ctx, i);
936
1360
  const assignments = serializeAssignments(ctx, i, d);
937
1361
  if (assignments) {
938
- const ref = getRefParam(ctx, i);
939
- return "(" + assignRef(ctx, i, init) + "," + assignments + ref + ")";
1362
+ return "(" + assignRef2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
940
1363
  }
941
1364
  }
942
1365
  }
943
- return assignRef(ctx, i, init);
1366
+ return assignRef2(ctx, i, init);
944
1367
  }
945
1368
  function serializeNullConstructor(ctx, node) {
946
1369
  return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
947
1370
  }
1371
+ function serializeObject(ctx, node) {
1372
+ return assignRef2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
1373
+ }
948
1374
  function serializeSet(ctx, node) {
949
1375
  let serialized = "new Set";
950
- const size = node.a.length;
1376
+ const size = node.l;
951
1377
  if (size) {
952
1378
  let result = "";
953
1379
  ctx.stack.push(node.i);
@@ -958,10 +1384,7 @@ function serializeSet(ctx, node) {
958
1384
  if (isReferenceInStack(ctx, item)) {
959
1385
  createSetAdd(ctx, node.i, getRefParam(ctx, item.i));
960
1386
  } else {
961
- if (hasPrev) {
962
- result += ",";
963
- }
964
- result += serializeTree(ctx, item);
1387
+ result += (hasPrev ? "," : "") + serializeTree(ctx, item);
965
1388
  hasPrev = true;
966
1389
  }
967
1390
  }
@@ -970,7 +1393,7 @@ function serializeSet(ctx, node) {
970
1393
  serialized += "([" + result + "])";
971
1394
  }
972
1395
  }
973
- return assignRef(ctx, node.i, serialized);
1396
+ return assignRef2(ctx, node.i, serialized);
974
1397
  }
975
1398
  function serializeMap(ctx, node) {
976
1399
  let serialized = "new Map";
@@ -1004,10 +1427,7 @@ function serializeMap(ctx, node) {
1004
1427
  createMapSet(ctx, node.i, serializeTree(ctx, key), valueRef);
1005
1428
  ctx.stack = parent;
1006
1429
  } else {
1007
- if (hasPrev) {
1008
- result += ",";
1009
- }
1010
- result += "[" + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
1430
+ result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
1011
1431
  hasPrev = true;
1012
1432
  }
1013
1433
  }
@@ -1016,22 +1436,22 @@ function serializeMap(ctx, node) {
1016
1436
  serialized += "([" + result + "])";
1017
1437
  }
1018
1438
  }
1019
- return assignRef(ctx, node.i, serialized);
1439
+ return assignRef2(ctx, node.i, serialized);
1020
1440
  }
1021
1441
  function serializeAggregateError(ctx, node) {
1022
1442
  ctx.stack.push(node.i);
1023
- const serialized = "new AggregateError(" + serializeTree(ctx, node.n) + "," + quote(node.m) + ")";
1443
+ const serialized = "new AggregateError(" + serializeNodeList(ctx, node) + ',"' + quote(node.m) + '")';
1024
1444
  ctx.stack.pop();
1025
1445
  return serializeDictionary(ctx, node.i, node.d, serialized);
1026
1446
  }
1027
1447
  function serializeError(ctx, node) {
1028
- const serialized = "new " + node.c + "(" + quote(node.m) + ")";
1448
+ const serialized = "new " + node.c + '("' + quote(node.m) + '")';
1029
1449
  return serializeDictionary(ctx, node.i, node.d, serialized);
1030
1450
  }
1031
1451
  function serializePromise(ctx, node) {
1032
1452
  let serialized;
1033
- if (isReferenceInStack(ctx, node.n)) {
1034
- const ref = getRefParam(ctx, node.n.i);
1453
+ if (isReferenceInStack(ctx, node.f)) {
1454
+ const ref = getRefParam(ctx, node.f.i);
1035
1455
  if (ctx.features & 4 /* ArrowFunction */) {
1036
1456
  serialized = "Promise.resolve().then(()=>" + ref + ")";
1037
1457
  } else {
@@ -1039,18 +1459,20 @@ function serializePromise(ctx, node) {
1039
1459
  }
1040
1460
  } else {
1041
1461
  ctx.stack.push(node.i);
1042
- const result = serializeTree(ctx, node.n);
1462
+ const result = serializeTree(ctx, node.f);
1043
1463
  ctx.stack.pop();
1044
1464
  serialized = "Promise.resolve(" + result + ")";
1045
1465
  }
1046
- return assignRef(ctx, node.i, serialized);
1466
+ return assignRef2(ctx, node.i, serialized);
1047
1467
  }
1048
1468
  function serializeTypedArray(ctx, node) {
1049
- let args = "[" + node.s + "]";
1050
- if (node.l !== 0) {
1051
- args += "," + node.l.toString();
1469
+ let result = "";
1470
+ const isBigInt = node.t === 23 /* BigIntTypedArray */;
1471
+ for (let i = 0, len = node.s.length; i < len; i++) {
1472
+ result += (i !== 0 ? "," : "") + node.s[i] + (isBigInt ? "n" : "");
1052
1473
  }
1053
- return assignRef(ctx, node.i, "new " + node.c + "(" + args + ")");
1474
+ const args = "[" + result + "]" + (node.l !== 0 ? "," + node.l : "");
1475
+ return assignRef2(ctx, node.i, "new " + node.c + "(" + args + ")");
1054
1476
  }
1055
1477
  function serializeIterable(ctx, node) {
1056
1478
  const parent = ctx.stack;
@@ -1074,37 +1496,55 @@ function serializeIterable(ctx, node) {
1074
1496
  }
1075
1497
  function serializeTree(ctx, node) {
1076
1498
  switch (node.t) {
1077
- case 0 /* Primitive */:
1078
- return String(node.s);
1079
- case 1 /* BigInt */:
1080
- return node.s;
1081
- case 2 /* Reference */:
1499
+ case 0 /* Number */:
1500
+ return "" + node.s;
1501
+ case 1 /* String */:
1502
+ return '"' + node.s + '"';
1503
+ case 2 /* Boolean */:
1504
+ return node.s ? "!0" : "!1";
1505
+ case 4 /* Undefined */:
1506
+ return "void 0";
1507
+ case 3 /* Null */:
1508
+ return "null";
1509
+ case 5 /* NegativeZero */:
1510
+ return "-0";
1511
+ case 6 /* Infinity */:
1512
+ return "1/0";
1513
+ case 7 /* NegativeInfinity */:
1514
+ return "-1/0";
1515
+ case 8 /* NaN */:
1516
+ return "NaN";
1517
+ case 9 /* BigInt */:
1518
+ return node.s + "n";
1519
+ case 10 /* Reference */:
1082
1520
  return getRefParam(ctx, node.i);
1083
- case 7 /* Array */:
1521
+ case 15 /* Array */:
1084
1522
  return serializeArray(ctx, node);
1085
- case 8 /* Object */:
1086
- return assignRef(ctx, node.i, serializeObject(ctx, node.i, node.d));
1087
- case 9 /* NullConstructor */:
1523
+ case 16 /* Object */:
1524
+ return serializeObject(ctx, node);
1525
+ case 17 /* NullConstructor */:
1088
1526
  return serializeNullConstructor(ctx, node);
1089
- case 3 /* Date */:
1090
- return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
1091
- case 4 /* RegExp */:
1092
- return assignRef(ctx, node.i, node.s);
1093
- case 5 /* Set */:
1527
+ case 11 /* Date */:
1528
+ return assignRef2(ctx, node.i, 'new Date("' + node.s + '")');
1529
+ case 12 /* RegExp */:
1530
+ return assignRef2(ctx, node.i, "/" + node.c + "/" + node.m);
1531
+ case 13 /* Set */:
1094
1532
  return serializeSet(ctx, node);
1095
- case 6 /* Map */:
1533
+ case 14 /* Map */:
1096
1534
  return serializeMap(ctx, node);
1097
- case 15 /* BigIntTypedArray */:
1098
- case 14 /* TypedArray */:
1535
+ case 23 /* BigIntTypedArray */:
1536
+ case 22 /* TypedArray */:
1099
1537
  return serializeTypedArray(ctx, node);
1100
- case 12 /* AggregateError */:
1538
+ case 20 /* AggregateError */:
1101
1539
  return serializeAggregateError(ctx, node);
1102
- case 11 /* Error */:
1540
+ case 19 /* Error */:
1103
1541
  return serializeError(ctx, node);
1104
- case 13 /* Iterable */:
1542
+ case 21 /* Iterable */:
1105
1543
  return serializeIterable(ctx, node);
1106
- case 10 /* Promise */:
1544
+ case 18 /* Promise */:
1107
1545
  return serializePromise(ctx, node);
1546
+ case 24 /* WKSymbol */:
1547
+ return SYMBOL_STRING[node.s];
1108
1548
  default:
1109
1549
  throw new Error("Unsupported type");
1110
1550
  }
@@ -1135,15 +1575,15 @@ function generateNodeList2(ctx, current) {
1135
1575
  }
1136
1576
  function generateArrayNode2(ctx, id, current) {
1137
1577
  return {
1138
- t: 7 /* Array */,
1578
+ t: 15 /* Array */,
1139
1579
  i: id,
1140
1580
  s: void 0,
1141
- l: void 0,
1581
+ l: current.length,
1142
1582
  c: void 0,
1143
1583
  m: void 0,
1144
1584
  d: void 0,
1145
1585
  a: generateNodeList2(ctx, current),
1146
- n: void 0
1586
+ f: void 0
1147
1587
  };
1148
1588
  }
1149
1589
  function generateMapNode2(ctx, id, current) {
@@ -1171,7 +1611,7 @@ function generateMapNode2(ctx, id, current) {
1171
1611
  valueNodes[nodeSize + i] = parse2(ctx, deferredValue[i]);
1172
1612
  }
1173
1613
  return {
1174
- t: 6 /* Map */,
1614
+ t: 14 /* Map */,
1175
1615
  i: id,
1176
1616
  s: void 0,
1177
1617
  l: void 0,
@@ -1179,7 +1619,7 @@ function generateMapNode2(ctx, id, current) {
1179
1619
  m: void 0,
1180
1620
  d: { k: keyNodes, v: valueNodes, s: len },
1181
1621
  a: void 0,
1182
- n: void 0
1622
+ f: void 0
1183
1623
  };
1184
1624
  }
1185
1625
  function generateSetNode2(ctx, id, current) {
@@ -1200,15 +1640,15 @@ function generateSetNode2(ctx, id, current) {
1200
1640
  nodes[nodeSize + i] = parse2(ctx, deferred[i]);
1201
1641
  }
1202
1642
  return {
1203
- t: 5 /* Set */,
1643
+ t: 13 /* Set */,
1204
1644
  i: id,
1205
1645
  s: void 0,
1206
- l: void 0,
1646
+ l: len,
1207
1647
  c: void 0,
1208
1648
  m: void 0,
1209
1649
  d: void 0,
1210
1650
  a: nodes,
1211
- n: void 0
1651
+ f: void 0
1212
1652
  };
1213
1653
  }
1214
1654
  function generateProperties2(ctx, properties) {
@@ -1244,19 +1684,20 @@ function generateProperties2(ctx, properties) {
1244
1684
  };
1245
1685
  }
1246
1686
  function generateIterableNode2(ctx, id, current) {
1247
- assert(ctx.features & 1024 /* SymbolIterator */, 'Unsupported type "Iterable"');
1687
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
1248
1688
  const options = getIterableOptions(current);
1689
+ const array = Array.from(current);
1249
1690
  return {
1250
- t: 13 /* Iterable */,
1691
+ t: 21 /* Iterable */,
1251
1692
  i: id,
1252
1693
  s: void 0,
1253
- l: void 0,
1694
+ l: array.length,
1254
1695
  c: void 0,
1255
1696
  m: void 0,
1256
1697
  // Parse options first before the items
1257
1698
  d: options ? generateProperties2(ctx, options) : void 0,
1258
- a: generateNodeList2(ctx, Array.from(current)),
1259
- n: void 0
1699
+ a: generateNodeList2(ctx, array),
1700
+ f: void 0
1260
1701
  };
1261
1702
  }
1262
1703
  function generateObjectNode2(ctx, id, current, empty) {
@@ -1264,7 +1705,7 @@ function generateObjectNode2(ctx, id, current, empty) {
1264
1705
  return generateIterableNode2(ctx, id, current);
1265
1706
  }
1266
1707
  return {
1267
- t: empty ? 9 /* NullConstructor */ : 8 /* Object */,
1708
+ t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
1268
1709
  i: id,
1269
1710
  s: void 0,
1270
1711
  l: void 0,
@@ -1272,37 +1713,37 @@ function generateObjectNode2(ctx, id, current, empty) {
1272
1713
  m: void 0,
1273
1714
  d: generateProperties2(ctx, current),
1274
1715
  a: void 0,
1275
- n: void 0
1716
+ f: void 0
1276
1717
  };
1277
1718
  }
1278
1719
  function generateAggregateErrorNode2(ctx, id, current) {
1279
1720
  const options = getErrorOptions(ctx, current);
1280
1721
  const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1281
1722
  return {
1282
- t: 12 /* AggregateError */,
1723
+ t: 20 /* AggregateError */,
1283
1724
  i: id,
1284
1725
  s: void 0,
1285
- l: void 0,
1726
+ l: current.errors.length,
1286
1727
  c: void 0,
1287
1728
  m: current.message,
1288
1729
  d: optionsNode,
1289
- a: void 0,
1290
- n: parse2(ctx, current.errors)
1730
+ a: generateNodeList2(ctx, current.errors),
1731
+ f: void 0
1291
1732
  };
1292
1733
  }
1293
1734
  function generateErrorNode2(ctx, id, current) {
1294
1735
  const options = getErrorOptions(ctx, current);
1295
1736
  const optionsNode = options ? generateProperties2(ctx, options) : void 0;
1296
1737
  return {
1297
- t: 11 /* Error */,
1738
+ t: 19 /* Error */,
1298
1739
  i: id,
1299
1740
  s: void 0,
1300
1741
  l: void 0,
1301
- c: getErrorConstructor(current),
1742
+ c: getErrorConstructorName(current),
1302
1743
  m: current.message,
1303
1744
  d: optionsNode,
1304
1745
  a: void 0,
1305
- n: void 0
1746
+ f: void 0
1306
1747
  };
1307
1748
  }
1308
1749
  function parse2(ctx, current) {
@@ -1312,25 +1753,30 @@ function parse2(ctx, current) {
1312
1753
  case "undefined":
1313
1754
  return UNDEFINED_NODE;
1314
1755
  case "string":
1315
- return createPrimitiveNode(quote(current));
1756
+ return createStringNode(current);
1316
1757
  case "number":
1317
- if (Object.is(current, -0)) {
1318
- return NEG_ZERO_NODE;
1758
+ switch (current) {
1759
+ case Infinity:
1760
+ return INFINITY_NODE;
1761
+ case -Infinity:
1762
+ return NEG_INFINITY_NODE;
1763
+ default:
1764
+ break;
1319
1765
  }
1320
- if (Object.is(current, Infinity)) {
1321
- return createPrimitiveNode("1/0");
1766
+ if (current !== current) {
1767
+ return NAN_NODE;
1322
1768
  }
1323
- if (Object.is(current, -Infinity)) {
1324
- return createPrimitiveNode("-1/0");
1769
+ if (Object.is(current, -0)) {
1770
+ return NEG_ZERO_NODE;
1325
1771
  }
1326
- return createPrimitiveNode(current);
1772
+ return createNumberNode(current);
1327
1773
  case "bigint":
1328
1774
  return createBigIntNode(ctx, current);
1329
1775
  case "object": {
1330
1776
  if (!current) {
1331
1777
  return NULL_NODE;
1332
1778
  }
1333
- const id = createRef(ctx, current, true);
1779
+ const id = createRef(ctx, current);
1334
1780
  if (ctx.markedRefs.has(id)) {
1335
1781
  return createReferenceNode(id);
1336
1782
  }
@@ -1379,8 +1825,11 @@ function parse2(ctx, current) {
1379
1825
  default:
1380
1826
  break;
1381
1827
  }
1382
- if (current instanceof AggregateError && ctx.features & 1 /* AggregateError */) {
1383
- return generateAggregateErrorNode2(ctx, id, current);
1828
+ if (current instanceof AggregateError) {
1829
+ if (ctx.features & 1 /* AggregateError */) {
1830
+ return generateAggregateErrorNode2(ctx, id, current);
1831
+ }
1832
+ return generateErrorNode2(ctx, id, current);
1384
1833
  }
1385
1834
  if (current instanceof Error) {
1386
1835
  return generateErrorNode2(ctx, id, current);
@@ -1390,14 +1839,18 @@ function parse2(ctx, current) {
1390
1839
  }
1391
1840
  throw new Error("Unsupported type");
1392
1841
  }
1842
+ case "symbol":
1843
+ assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
1844
+ assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
1845
+ return createWKSymbolNode(current);
1393
1846
  default:
1394
1847
  throw new Error("Unsupported type");
1395
1848
  }
1396
1849
  }
1397
1850
  function parseSync(ctx, current) {
1398
1851
  const result = parse2(ctx, current);
1399
- const isObject = result.t === 8 /* Object */ || result.t === 13 /* Iterable */;
1400
- return [result, createRef(ctx, current, false), isObject];
1852
+ const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
1853
+ return [result, getRootID(ctx, current), isObject];
1401
1854
  }
1402
1855
 
1403
1856
  // src/index.ts
@@ -1472,7 +1925,11 @@ function compileJSON(source) {
1472
1925
  return finalize(serial, source.r, source.i, result);
1473
1926
  }
1474
1927
  function fromJSON(source) {
1475
- return deserialize(compileJSON(source));
1928
+ const serial = createSerializationContext({
1929
+ features: source.f,
1930
+ markedRefs: source.m
1931
+ });
1932
+ return deserializeTree(serial, source.t);
1476
1933
  }
1477
1934
  var src_default = serialize;
1478
1935
  //# sourceMappingURL=index.cjs.map