seroval 0.9.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +4 -287
  2. package/dist/cjs/development/index.cjs +3529 -1140
  3. package/dist/cjs/development/index.cjs.map +4 -4
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +3533 -1142
  6. package/dist/esm/development/index.mjs.map +4 -4
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +15 -0
  9. package/dist/types/{tree → core}/UnsupportedTypeError.d.ts +4 -3
  10. package/dist/types/{assert.d.ts → core/assert.d.ts} +1 -1
  11. package/dist/types/core/assignments.d.ts +33 -0
  12. package/dist/types/core/base-primitives.d.ts +12 -0
  13. package/dist/types/{compat.d.ts → core/compat.d.ts} +22 -22
  14. package/dist/types/core/constants.d.ts +89 -0
  15. package/dist/types/core/context.d.ts +9 -0
  16. package/dist/types/core/cross/async.d.ts +3 -0
  17. package/dist/types/core/cross/context.d.ts +37 -0
  18. package/dist/types/core/cross/index.d.ts +8 -0
  19. package/dist/types/core/cross/primitives.d.ts +9 -0
  20. package/dist/types/core/cross/serialize.d.ts +5 -0
  21. package/dist/types/core/cross/stream.d.ts +3 -0
  22. package/dist/types/core/cross/sync.d.ts +3 -0
  23. package/dist/types/core/cross/web-api.d.ts +4 -0
  24. package/dist/types/{get-identifier.d.ts → core/get-identifier.d.ts} +1 -1
  25. package/dist/types/core/keys.d.ts +13 -0
  26. package/dist/types/{tree/constants.d.ts → core/literals.d.ts} +9 -11
  27. package/dist/types/core/promise-to-result.d.ts +1 -0
  28. package/dist/types/{tree → core}/reference.d.ts +5 -6
  29. package/dist/types/{tree → core}/shared.d.ts +13 -13
  30. package/dist/types/{string.d.ts → core/string.d.ts} +3 -3
  31. package/dist/types/core/tree/async.d.ts +3 -0
  32. package/dist/types/core/tree/context.d.ts +44 -0
  33. package/dist/types/core/tree/deserialize.d.ts +3 -0
  34. package/dist/types/core/tree/index.d.ts +14 -0
  35. package/dist/types/core/tree/primitives.d.ts +9 -0
  36. package/dist/types/core/tree/serialize.d.ts +4 -0
  37. package/dist/types/core/tree/sync.d.ts +3 -0
  38. package/dist/types/core/tree/web-api.d.ts +4 -0
  39. package/dist/types/{tree → core}/types.d.ts +228 -238
  40. package/dist/types/core/web-api.d.ts +4 -0
  41. package/dist/types/index.d.ts +9 -19
  42. package/dist/types/types.d.ts +20 -20
  43. package/package.json +5 -5
  44. package/src/core/Serializer.ts +48 -0
  45. package/src/{tree → core}/UnsupportedTypeError.ts +1 -1
  46. package/src/core/assignments.ts +159 -0
  47. package/src/{tree/primitives.ts → core/base-primitives.ts} +33 -136
  48. package/src/core/constants.ts +169 -0
  49. package/src/core/context.ts +15 -0
  50. package/src/core/cross/async.ts +614 -0
  51. package/src/core/cross/context.ts +102 -0
  52. package/src/core/cross/index.ts +169 -0
  53. package/src/core/cross/primitives.ts +137 -0
  54. package/src/core/cross/serialize.ts +847 -0
  55. package/src/core/cross/stream.ts +745 -0
  56. package/src/core/cross/sync.ts +561 -0
  57. package/src/core/cross/web-api.ts +55 -0
  58. package/src/core/header.js +61 -0
  59. package/src/core/keys.ts +41 -0
  60. package/src/core/literals.ts +28 -0
  61. package/src/core/promise-to-result.ts +9 -0
  62. package/src/{tree → core}/reference.ts +6 -7
  63. package/src/{tree → core}/shared.ts +4 -4
  64. package/src/{tree → core/tree}/async.ts +46 -34
  65. package/src/core/tree/context.ts +125 -0
  66. package/src/{tree → core/tree}/deserialize.ts +68 -55
  67. package/src/core/tree/index.ts +142 -0
  68. package/src/core/tree/primitives.ts +132 -0
  69. package/src/{tree → core/tree}/serialize.ts +87 -193
  70. package/src/{tree → core/tree}/sync.ts +50 -39
  71. package/src/{tree → core/tree}/web-api.ts +8 -52
  72. package/src/{tree → core}/types.ts +76 -60
  73. package/src/core/web-api.ts +51 -0
  74. package/src/index.ts +7 -141
  75. package/src/types.ts +1 -1
  76. package/dist/types/context.d.ts +0 -67
  77. package/dist/types/tree/async.d.ts +0 -3
  78. package/dist/types/tree/deserialize.d.ts +0 -3
  79. package/dist/types/tree/primitives.d.ts +0 -19
  80. package/dist/types/tree/serialize.d.ts +0 -4
  81. package/dist/types/tree/symbols.d.ts +0 -33
  82. package/dist/types/tree/sync.d.ts +0 -3
  83. package/dist/types/tree/web-api.d.ts +0 -6
  84. package/src/context.ts +0 -164
  85. package/src/tree/constants.ts +0 -73
  86. package/src/tree/symbols.ts +0 -65
  87. /package/src/{assert.ts → core/assert.ts} +0 -0
  88. /package/src/{compat.ts → core/compat.ts} +0 -0
  89. /package/src/{get-identifier.ts → core/get-identifier.ts} +0 -0
  90. /package/src/{string.ts → core/string.ts} +0 -0
@@ -1,17 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
2
  import { Feature } from '../compat';
3
3
  import type {
4
- SerializationContext,
5
- Assignment,
6
- } from '../context';
4
+ SerializerContext,
5
+ } from './context';
7
6
  import {
8
7
  getRefParam,
9
8
  markRef,
10
- } from '../context';
11
- import { serializeConstant } from './constants';
12
- import { GLOBAL_KEY } from './reference';
13
- import { isValidIdentifier } from './shared';
14
- import { SYMBOL_STRING } from './symbols';
9
+ } from './context';
10
+ import { isValidIdentifier } from '../shared';
15
11
  import type {
16
12
  SerovalAggregateErrorNode,
17
13
  SerovalArrayNode,
@@ -40,124 +36,21 @@ import type {
40
36
  SerovalObjectRecordKey,
41
37
  SerovalBoxedNode,
42
38
  SerovalWKSymbolNode,
43
- } from './types';
39
+ } from '../types';
40
+ import {
41
+ SerovalObjectRecordSpecialKey,
42
+ } from '../types';
44
43
  import {
45
44
  SerovalObjectFlags,
46
-
47
45
  SerovalNodeType,
48
- SerovalObjectRecordSpecialKey,
49
- } from './types';
50
-
51
- function getAssignmentExpression(assignment: Assignment): string {
52
- switch (assignment.t) {
53
- case 'index':
54
- return assignment.s + '=' + assignment.v;
55
- case 'set':
56
- return assignment.s + '.set(' + assignment.k + ',' + assignment.v + ')';
57
- case 'add':
58
- return assignment.s + '.add(' + assignment.v + ')';
59
- case 'append':
60
- return assignment.s + '.append(' + assignment.k + ',' + assignment.v + ')';
61
- default:
62
- return '';
63
- }
64
- }
65
-
66
- const OBJECT_FLAG_CONSTRUCTOR: Record<SerovalObjectFlags, string | undefined> = {
67
- [SerovalObjectFlags.Frozen]: 'Object.freeze',
68
- [SerovalObjectFlags.Sealed]: 'Object.seal',
69
- [SerovalObjectFlags.NonExtensible]: 'Object.preventExtensions',
70
- [SerovalObjectFlags.None]: undefined,
71
- };
72
-
73
- function mergeAssignments(assignments: Assignment[]): Assignment[] {
74
- const newAssignments: Assignment[] = [];
75
- let current = assignments[0];
76
- let prev = current;
77
- let item: Assignment;
78
- for (let i = 1, len = assignments.length; i < len; i++) {
79
- item = assignments[i];
80
- if (item.t === prev.t) {
81
- switch (item.t) {
82
- case 'index':
83
- if (item.v === prev.v) {
84
- // Merge if the right-hand value is the same
85
- // saves at least 2 chars
86
- current = {
87
- t: 'index',
88
- s: item.s,
89
- k: undefined,
90
- v: getAssignmentExpression(current),
91
- };
92
- } else {
93
- // Different assignment, push current
94
- newAssignments.push(current);
95
- current = item;
96
- }
97
- break;
98
- case 'set':
99
- if (item.s === prev.s) {
100
- // Maps has chaining methods, merge if source is the same
101
- current = {
102
- t: 'set',
103
- s: getAssignmentExpression(current),
104
- k: item.k,
105
- v: item.v,
106
- };
107
- } else {
108
- // Different assignment, push current
109
- newAssignments.push(current);
110
- current = item;
111
- }
112
- break;
113
- case 'add':
114
- if (item.s === prev.s) {
115
- // Sets has chaining methods too
116
- current = {
117
- t: 'add',
118
- s: getAssignmentExpression(current),
119
- k: undefined,
120
- v: item.v,
121
- };
122
- } else {
123
- // Different assignment, push current
124
- newAssignments.push(current);
125
- current = item;
126
- }
127
- break;
128
- case 'append':
129
- // Different assignment, push current
130
- newAssignments.push(current);
131
- current = item;
132
- break;
133
- default:
134
- break;
135
- }
136
- } else {
137
- newAssignments.push(current);
138
- current = item;
139
- }
140
- prev = item;
141
- }
142
-
143
- newAssignments.push(current);
144
-
145
- return newAssignments;
146
- }
147
-
148
- function resolveAssignments(assignments: Assignment[]): string | undefined {
149
- if (assignments.length) {
150
- let result = '';
151
- const merged = mergeAssignments(assignments);
152
- for (let i = 0, len = merged.length; i < len; i++) {
153
- result += getAssignmentExpression(merged[i]) + ',';
154
- }
155
- return result;
156
- }
157
- return undefined;
158
- }
159
-
160
- function pushObjectFlag(ctx: SerializationContext, flag: SerovalObjectFlags, id: number): void {
46
+ SYMBOL_STRING,
47
+ serializeConstant,
48
+ } from '../constants';
49
+ import type { Assignment } from '../assignments';
50
+ import { resolveAssignments, resolveFlags } from '../assignments';
51
+ import { REFERENCES_KEY } from '../keys';
52
+
53
+ function pushObjectFlag(ctx: SerializerContext, flag: SerovalObjectFlags, id: number): void {
161
54
  if (flag !== SerovalObjectFlags.None) {
162
55
  markRef(ctx, id);
163
56
  ctx.flags.push({
@@ -167,18 +60,9 @@ function pushObjectFlag(ctx: SerializationContext, flag: SerovalObjectFlags, id:
167
60
  }
168
61
  }
169
62
 
170
- function resolveFlags(ctx: SerializationContext): string | undefined {
171
- let result = '';
172
- for (let i = 0, len = ctx.flags.length; i < len; i++) {
173
- const flag = ctx.flags[i];
174
- result += OBJECT_FLAG_CONSTRUCTOR[flag.type] + '(' + flag.value + '),';
175
- }
176
- return result;
177
- }
178
-
179
- export function resolvePatches(ctx: SerializationContext): string | undefined {
63
+ export function resolvePatches(ctx: SerializerContext): string | undefined {
180
64
  const assignments = resolveAssignments(ctx.assignments);
181
- const flags = resolveFlags(ctx);
65
+ const flags = resolveFlags(ctx.flags);
182
66
  if (assignments) {
183
67
  if (flags) {
184
68
  return assignments + flags;
@@ -195,7 +79,7 @@ export function resolvePatches(ctx: SerializationContext): string | undefined {
195
79
  */
196
80
 
197
81
  function createAssignment(
198
- ctx: SerializationContext,
82
+ ctx: SerializerContext,
199
83
  source: string,
200
84
  value: string,
201
85
  ): void {
@@ -208,7 +92,7 @@ function createAssignment(
208
92
  }
209
93
 
210
94
  function createAddAssignment(
211
- ctx: SerializationContext,
95
+ ctx: SerializerContext,
212
96
  ref: number,
213
97
  value: string,
214
98
  ): void {
@@ -221,7 +105,7 @@ function createAddAssignment(
221
105
  }
222
106
 
223
107
  function createSetAssignment(
224
- ctx: SerializationContext,
108
+ ctx: SerializerContext,
225
109
  ref: number,
226
110
  key: string,
227
111
  value: string,
@@ -235,7 +119,7 @@ function createSetAssignment(
235
119
  }
236
120
 
237
121
  function createAppendAssignment(
238
- ctx: SerializationContext,
122
+ ctx: SerializerContext,
239
123
  ref: number,
240
124
  key: string,
241
125
  value: string,
@@ -249,7 +133,7 @@ function createAppendAssignment(
249
133
  }
250
134
 
251
135
  function createArrayAssign(
252
- ctx: SerializationContext,
136
+ ctx: SerializerContext,
253
137
  ref: number,
254
138
  index: number | string,
255
139
  value: string,
@@ -258,7 +142,7 @@ function createArrayAssign(
258
142
  }
259
143
 
260
144
  function createObjectAssign(
261
- ctx: SerializationContext,
145
+ ctx: SerializerContext,
262
146
  ref: number,
263
147
  key: string,
264
148
  value: string,
@@ -268,25 +152,25 @@ function createObjectAssign(
268
152
  }
269
153
 
270
154
  function assignIndexedValue(
271
- ctx: SerializationContext,
155
+ ctx: SerializerContext,
272
156
  index: number,
273
157
  value: string,
274
158
  ): string {
275
- if (ctx.markedRefs.has(index)) {
159
+ if (ctx.reference.marked.has(index)) {
276
160
  return getRefParam(ctx, index) + '=' + value;
277
161
  }
278
162
  return value;
279
163
  }
280
164
 
281
165
  function isIndexedValueInStack(
282
- ctx: SerializationContext,
166
+ ctx: SerializerContext,
283
167
  node: SerovalNode,
284
168
  ): node is SerovalIndexedValueNode {
285
169
  return node.t === SerovalNodeType.IndexedValue && ctx.stack.includes(node.i);
286
170
  }
287
171
 
288
172
  function serializeArray(
289
- ctx: SerializationContext,
173
+ ctx: SerializerContext,
290
174
  node: SerovalArrayNode,
291
175
  ): string {
292
176
  const id = node.i;
@@ -324,14 +208,14 @@ function serializeArray(
324
208
  return assignIndexedValue(ctx, id, '[' + values + (isHoley ? ',]' : ']'));
325
209
  }
326
210
 
327
- function getIterableAccess(ctx: SerializationContext): string {
211
+ function getIterableAccess(ctx: SerializerContext): string {
328
212
  return ctx.features & Feature.ArrayPrototypeValues
329
213
  ? '.values()'
330
214
  : '[Symbol.iterator]()';
331
215
  }
332
216
 
333
217
  function serializeIterable(
334
- ctx: SerializationContext,
218
+ ctx: SerializerContext,
335
219
  node: SerovalNode,
336
220
  ): string {
337
221
  const parent = ctx.stack;
@@ -349,7 +233,7 @@ function serializeIterable(
349
233
  }
350
234
 
351
235
  function serializeProperties(
352
- ctx: SerializationContext,
236
+ ctx: SerializerContext,
353
237
  sourceID: number,
354
238
  node: SerovalObjectRecordNode,
355
239
  ): string {
@@ -402,7 +286,7 @@ function serializeProperties(
402
286
  }
403
287
 
404
288
  function serializeWithObjectAssign(
405
- ctx: SerializationContext,
289
+ ctx: SerializerContext,
406
290
  value: SerovalObjectRecordNode,
407
291
  id: number,
408
292
  serialized: string,
@@ -415,7 +299,7 @@ function serializeWithObjectAssign(
415
299
  }
416
300
 
417
301
  function serializeAssignments(
418
- ctx: SerializationContext,
302
+ ctx: SerializerContext,
419
303
  sourceID: number,
420
304
  node: SerovalObjectRecordNode,
421
305
  ): string | undefined {
@@ -480,17 +364,17 @@ function serializeAssignments(
480
364
  }
481
365
 
482
366
  function serializeDictionary(
483
- ctx: SerializationContext,
367
+ ctx: SerializerContext,
484
368
  i: number,
485
- d: SerovalObjectRecordNode | undefined,
369
+ p: SerovalObjectRecordNode | undefined,
486
370
  init: string,
487
371
  ): string {
488
- if (d) {
372
+ if (p) {
489
373
  if (ctx.features & Feature.ObjectAssign) {
490
- init = serializeWithObjectAssign(ctx, d, i, init);
374
+ init = serializeWithObjectAssign(ctx, p, i, init);
491
375
  } else {
492
376
  markRef(ctx, i);
493
- const assignments = serializeAssignments(ctx, i, d);
377
+ const assignments = serializeAssignments(ctx, i, p);
494
378
  if (assignments) {
495
379
  return '(' + assignIndexedValue(ctx, i, init) + ',' + assignments + getRefParam(ctx, i) + ')';
496
380
  }
@@ -502,23 +386,23 @@ function serializeDictionary(
502
386
  const NULL_CONSTRUCTOR = 'Object.create(null)';
503
387
 
504
388
  function serializeNullConstructor(
505
- ctx: SerializationContext,
389
+ ctx: SerializerContext,
506
390
  node: SerovalNullConstructorNode,
507
391
  ): string {
508
392
  pushObjectFlag(ctx, node.o, node.i);
509
- return serializeDictionary(ctx, node.i, node.d, NULL_CONSTRUCTOR);
393
+ return serializeDictionary(ctx, node.i, node.p, NULL_CONSTRUCTOR);
510
394
  }
511
395
 
512
396
  function serializeObject(
513
- ctx: SerializationContext,
397
+ ctx: SerializerContext,
514
398
  node: SerovalObjectNode,
515
399
  ): string {
516
400
  pushObjectFlag(ctx, node.o, node.i);
517
- return assignIndexedValue(ctx, node.i, serializeProperties(ctx, node.i, node.d));
401
+ return assignIndexedValue(ctx, node.i, serializeProperties(ctx, node.i, node.p));
518
402
  }
519
403
 
520
404
  function serializeSet(
521
- ctx: SerializationContext,
405
+ ctx: SerializerContext,
522
406
  node: SerovalSetNode,
523
407
  ): string {
524
408
  let serialized = 'new Set';
@@ -550,11 +434,11 @@ function serializeSet(
550
434
  }
551
435
 
552
436
  function serializeMap(
553
- ctx: SerializationContext,
437
+ ctx: SerializerContext,
554
438
  node: SerovalMapNode,
555
439
  ): string {
556
440
  let serialized = 'new Map';
557
- const size = node.d.s;
441
+ const size = node.e.s;
558
442
  const id = node.i;
559
443
  if (size) {
560
444
  let result = '';
@@ -564,8 +448,8 @@ function serializeMap(
564
448
  let valueRef: string;
565
449
  let parent: number[];
566
450
  let hasPrev = false;
567
- const keys = node.d.k;
568
- const vals = node.d.v;
451
+ const keys = node.e.k;
452
+ const vals = node.e.v;
569
453
  ctx.stack.push(id);
570
454
  for (let i = 0; i < size; i++) {
571
455
  // Check if key is a parent
@@ -619,7 +503,7 @@ function serializeMap(
619
503
  }
620
504
 
621
505
  function serializeAggregateError(
622
- ctx: SerializationContext,
506
+ ctx: SerializerContext,
623
507
  node: SerovalAggregateErrorNode,
624
508
  ): string {
625
509
  // Serialize the required arguments
@@ -630,24 +514,28 @@ function serializeAggregateError(
630
514
  // `AggregateError` might've been extended
631
515
  // either through class or custom properties
632
516
  // Make sure to assign extra properties
633
- return serializeDictionary(ctx, id, node.d, serialized);
517
+ return serializeDictionary(ctx, id, node.p, serialized);
634
518
  }
635
519
 
636
520
  function serializeError(
637
- ctx: SerializationContext,
521
+ ctx: SerializerContext,
638
522
  node: SerovalErrorNode,
639
523
  ): string {
640
- return serializeDictionary(ctx, node.i, node.d, 'new ' + node.c + '("' + node.m + '")');
524
+ return serializeDictionary(ctx, node.i, node.p, 'new ' + node.c + '("' + node.m + '")');
641
525
  }
642
526
 
527
+ const PROMISE_RESOLVE = 'Promise.resolve';
528
+ const PROMISE_REJECT = 'Promise.reject';
529
+
643
530
  function serializePromise(
644
- ctx: SerializationContext,
531
+ ctx: SerializerContext,
645
532
  node: SerovalPromiseNode,
646
533
  ): string {
647
534
  let serialized: string;
648
535
  // Check if resolved value is a parent expression
649
536
  const fulfilled = node.f;
650
537
  const id = node.i;
538
+ const constructor = node.s ? PROMISE_RESOLVE : PROMISE_REJECT;
651
539
  if (isIndexedValueInStack(ctx, fulfilled)) {
652
540
  // A Promise trick, reference the value
653
541
  // inside the `then` expression so that
@@ -655,22 +543,28 @@ function serializePromise(
655
543
  // has initialized
656
544
  const ref = getRefParam(ctx, fulfilled.i);
657
545
  if (ctx.features & Feature.ArrowFunction) {
658
- serialized = 'Promise.resolve().then(()=>' + ref + ')';
546
+ if (node.s) {
547
+ serialized = constructor + '().then(()=>' + ref + ')';
548
+ } else {
549
+ serialized = constructor + '().catch(()=>{throw ' + ref + '})';
550
+ }
551
+ } else if (node.s) {
552
+ serialized = constructor + '().then(function(){return ' + ref + '})';
659
553
  } else {
660
- serialized = 'Promise.resolve().then(function(){return ' + ref + '})';
554
+ serialized = constructor + '().catch(function(){throw ' + ref + '})';
661
555
  }
662
556
  } else {
663
557
  ctx.stack.push(id);
664
558
  const result = serializeTree(ctx, fulfilled);
665
559
  ctx.stack.pop();
666
560
  // just inline the value/reference here
667
- serialized = 'Promise.resolve(' + result + ')';
561
+ serialized = constructor + '(' + result + ')';
668
562
  }
669
563
  return assignIndexedValue(ctx, id, serialized);
670
564
  }
671
565
 
672
566
  function serializeArrayBuffer(
673
- ctx: SerializationContext,
567
+ ctx: SerializerContext,
674
568
  node: SerovalArrayBufferNode,
675
569
  ): string {
676
570
  let result = 'new Uint8Array(';
@@ -687,7 +581,7 @@ function serializeArrayBuffer(
687
581
  }
688
582
 
689
583
  function serializeTypedArray(
690
- ctx: SerializationContext,
584
+ ctx: SerializerContext,
691
585
  node: SerovalTypedArrayNode | SerovalBigIntTypedArrayNode,
692
586
  ): string {
693
587
  return assignIndexedValue(
@@ -698,28 +592,28 @@ function serializeTypedArray(
698
592
  }
699
593
 
700
594
  function serializeDate(
701
- ctx: SerializationContext,
595
+ ctx: SerializerContext,
702
596
  node: SerovalDateNode,
703
597
  ): string {
704
598
  return assignIndexedValue(ctx, node.i, 'new Date("' + node.s + '")');
705
599
  }
706
600
 
707
601
  function serializeRegExp(
708
- ctx: SerializationContext,
602
+ ctx: SerializerContext,
709
603
  node: SerovalRegExpNode,
710
604
  ): string {
711
605
  return assignIndexedValue(ctx, node.i, '/' + node.c + '/' + node.m);
712
606
  }
713
607
 
714
608
  function serializeURL(
715
- ctx: SerializationContext,
609
+ ctx: SerializerContext,
716
610
  node: SerovalURLNode,
717
611
  ): string {
718
612
  return assignIndexedValue(ctx, node.i, 'new URL("' + node.s + '")');
719
613
  }
720
614
 
721
615
  function serializeURLSearchParams(
722
- ctx: SerializationContext,
616
+ ctx: SerializerContext,
723
617
  node: SerovalURLSearchParamsNode,
724
618
  ): string {
725
619
  return assignIndexedValue(
@@ -730,14 +624,14 @@ function serializeURLSearchParams(
730
624
  }
731
625
 
732
626
  function serializeReference(
733
- ctx: SerializationContext,
627
+ ctx: SerializerContext,
734
628
  node: SerovalReferenceNode,
735
629
  ): string {
736
- return assignIndexedValue(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
630
+ return assignIndexedValue(ctx, node.i, REFERENCES_KEY + '.get("' + node.s + '")');
737
631
  }
738
632
 
739
633
  function serializeDataView(
740
- ctx: SerializationContext,
634
+ ctx: SerializerContext,
741
635
  node: SerovalDataViewNode,
742
636
  ): string {
743
637
  return assignIndexedValue(
@@ -748,7 +642,7 @@ function serializeDataView(
748
642
  }
749
643
 
750
644
  function serializeBlob(
751
- ctx: SerializationContext,
645
+ ctx: SerializerContext,
752
646
  node: SerovalBlobNode,
753
647
  ): string {
754
648
  return assignIndexedValue(
@@ -759,7 +653,7 @@ function serializeBlob(
759
653
  }
760
654
 
761
655
  function serializeFile(
762
- ctx: SerializationContext,
656
+ ctx: SerializerContext,
763
657
  node: SerovalFileNode,
764
658
  ): string {
765
659
  return assignIndexedValue(
@@ -770,29 +664,29 @@ function serializeFile(
770
664
  }
771
665
 
772
666
  function serializeHeaders(
773
- ctx: SerializationContext,
667
+ ctx: SerializerContext,
774
668
  node: SerovalHeadersNode,
775
669
  ): string {
776
670
  return assignIndexedValue(
777
671
  ctx,
778
672
  node.i,
779
- 'new Headers(' + serializeProperties(ctx, node.i, node.d) + ')',
673
+ 'new Headers(' + serializeProperties(ctx, node.i, node.e) + ')',
780
674
  );
781
675
  }
782
676
 
783
677
  function serializeFormDataEntries(
784
- ctx: SerializationContext,
678
+ ctx: SerializerContext,
785
679
  node: SerovalFormDataNode,
786
680
  ): string | undefined {
787
681
  let value: string;
788
682
  let key: string;
789
- const keys = node.d.k;
790
- const vals = node.d.v;
683
+ const keys = node.e.k;
684
+ const vals = node.e.v;
791
685
  const id = node.i;
792
686
  const mainAssignments: Assignment[] = [];
793
687
  let parentAssignment: Assignment[];
794
688
  ctx.stack.push(id);
795
- for (let i = 0, len = node.d.s; i < len; i++) {
689
+ for (let i = 0, len = node.e.s; i < len; i++) {
796
690
  key = keys[i];
797
691
  value = serializeTree(ctx, vals[i]);
798
692
  parentAssignment = ctx.assignments;
@@ -805,10 +699,10 @@ function serializeFormDataEntries(
805
699
  }
806
700
 
807
701
  function serializeFormData(
808
- ctx: SerializationContext,
702
+ ctx: SerializerContext,
809
703
  node: SerovalFormDataNode,
810
704
  ): string {
811
- const size = node.d.s;
705
+ const size = node.e.s;
812
706
  const id = node.i;
813
707
  if (size) {
814
708
  markRef(ctx, id);
@@ -822,21 +716,21 @@ function serializeFormData(
822
716
  }
823
717
 
824
718
  function serializeBoxed(
825
- ctx: SerializationContext,
719
+ ctx: SerializerContext,
826
720
  node: SerovalBoxedNode,
827
721
  ): string {
828
722
  return assignIndexedValue(ctx, node.i, 'Object(' + serializeTree(ctx, node.f) + ')');
829
723
  }
830
724
 
831
725
  function serializeWKSymbol(
832
- ctx: SerializationContext,
726
+ ctx: SerializerContext,
833
727
  node: SerovalWKSymbolNode,
834
728
  ): string {
835
729
  return assignIndexedValue(ctx, node.i, SYMBOL_STRING[node.s]);
836
730
  }
837
731
 
838
732
  export default function serializeTree(
839
- ctx: SerializationContext,
733
+ ctx: SerializerContext,
840
734
  node: SerovalNode,
841
735
  ): string {
842
736
  switch (node.t) {