seroval 0.8.0 → 0.10.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.
Files changed (91) hide show
  1. package/README.md +4 -287
  2. package/dist/cjs/development/index.cjs +3858 -1385
  3. package/dist/cjs/development/index.cjs.map +4 -4
  4. package/dist/cjs/production/index.cjs +12 -3
  5. package/dist/esm/development/index.mjs +3611 -1136
  6. package/dist/esm/development/index.mjs.map +4 -4
  7. package/dist/esm/production/index.mjs +12 -3
  8. package/dist/types/core/Serializer.d.ts +14 -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 +30 -0
  18. package/dist/types/core/cross/index.d.ts +7 -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 +12 -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 -11
  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 +45 -0
  33. package/dist/types/core/tree/deserialize.d.ts +3 -0
  34. package/dist/types/core/tree/index.d.ts +15 -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 -228
  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 +7 -7
  44. package/src/core/Serializer.ts +46 -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} +42 -133
  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 +79 -0
  52. package/src/core/cross/index.ts +154 -0
  53. package/src/core/cross/primitives.ts +137 -0
  54. package/src/core/cross/serialize.ts +846 -0
  55. package/src/core/cross/stream.ts +740 -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 +65 -0
  59. package/src/core/keys.ts +33 -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 -8
  63. package/src/{tree → core}/shared.ts +17 -3
  64. package/src/{tree → core/tree}/async.ts +57 -34
  65. package/src/core/tree/context.ts +136 -0
  66. package/src/{tree → core/tree}/deserialize.ts +83 -54
  67. package/src/core/tree/index.ts +146 -0
  68. package/src/core/tree/primitives.ts +132 -0
  69. package/src/{tree → core/tree}/serialize.ts +124 -178
  70. package/src/{tree → core/tree}/sync.ts +60 -39
  71. package/src/{tree → core/tree}/web-api.ts +10 -50
  72. package/src/{tree → core}/types.ts +82 -54
  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 -61
  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 -154
  85. package/src/tree/constants.ts +0 -72
  86. package/src/tree/iterator.ts +0 -14
  87. package/src/tree/symbols.ts +0 -65
  88. /package/src/{assert.ts → core/assert.ts} +0 -0
  89. /package/src/{compat.ts → core/compat.ts} +0 -0
  90. /package/src/{get-identifier.ts → core/get-identifier.ts} +0 -0
  91. /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,116 +36,40 @@ import type {
40
36
  SerovalObjectRecordKey,
41
37
  SerovalBoxedNode,
42
38
  SerovalWKSymbolNode,
43
- } from './types';
39
+ } from '../types';
44
40
  import {
45
- SerovalNodeType,
46
41
  SerovalObjectRecordSpecialKey,
47
- } from './types';
48
-
49
- function getAssignmentExpression(assignment: Assignment): string {
50
- switch (assignment.t) {
51
- case 'index':
52
- return assignment.s + '=' + assignment.v;
53
- case 'set':
54
- return assignment.s + '.set(' + assignment.k + ',' + assignment.v + ')';
55
- case 'add':
56
- return assignment.s + '.add(' + assignment.v + ')';
57
- case 'append':
58
- return assignment.s + '.append(' + assignment.k + ',' + assignment.v + ')';
59
- default:
60
- return '';
61
- }
62
- }
63
-
64
- function mergeAssignments(assignments: Assignment[]): Assignment[] {
65
- const newAssignments: Assignment[] = [];
66
- let current = assignments[0];
67
- let prev = current;
68
- let item: Assignment;
69
- for (let i = 1, len = assignments.length; i < len; i++) {
70
- item = assignments[i];
71
- if (item.t === prev.t) {
72
- switch (item.t) {
73
- case 'index':
74
- if (item.v === prev.v) {
75
- // Merge if the right-hand value is the same
76
- // saves at least 2 chars
77
- current = {
78
- t: 'index',
79
- s: item.s,
80
- k: undefined,
81
- v: getAssignmentExpression(current),
82
- };
83
- } else {
84
- // Different assignment, push current
85
- newAssignments.push(current);
86
- current = item;
87
- }
88
- break;
89
- case 'set':
90
- if (item.s === prev.s) {
91
- // Maps has chaining methods, merge if source is the same
92
- current = {
93
- t: 'set',
94
- s: getAssignmentExpression(current),
95
- k: item.k,
96
- v: item.v,
97
- };
98
- } else {
99
- // Different assignment, push current
100
- newAssignments.push(current);
101
- current = item;
102
- }
103
- break;
104
- case 'add':
105
- if (item.s === prev.s) {
106
- // Sets has chaining methods too
107
- current = {
108
- t: 'add',
109
- s: getAssignmentExpression(current),
110
- k: undefined,
111
- v: item.v,
112
- };
113
- } else {
114
- // Different assignment, push current
115
- newAssignments.push(current);
116
- current = item;
117
- }
118
- break;
119
- case 'append':
120
- // Different assignment, push current
121
- newAssignments.push(current);
122
- current = item;
123
- break;
124
- default:
125
- break;
126
- }
127
- } else {
128
- newAssignments.push(current);
129
- current = item;
130
- }
131
- prev = item;
42
+ } from '../types';
43
+ import {
44
+ SerovalObjectFlags,
45
+ SerovalNodeType,
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 {
54
+ if (flag !== SerovalObjectFlags.None) {
55
+ markRef(ctx, id);
56
+ ctx.flags.push({
57
+ type: flag,
58
+ value: getRefParam(ctx, id),
59
+ });
132
60
  }
133
-
134
- newAssignments.push(current);
135
-
136
- return newAssignments;
137
61
  }
138
62
 
139
- function resolveAssignments(assignments: Assignment[]): string | undefined {
140
- if (assignments.length) {
141
- let result = '';
142
- const merged = mergeAssignments(assignments);
143
- for (let i = 0, len = merged.length; i < len; i++) {
144
- result += getAssignmentExpression(merged[i]) + ',';
63
+ export function resolvePatches(ctx: SerializerContext): string | undefined {
64
+ const assignments = resolveAssignments(ctx.assignments);
65
+ const flags = resolveFlags(ctx.flags);
66
+ if (assignments) {
67
+ if (flags) {
68
+ return assignments + flags;
145
69
  }
146
- return result;
70
+ return assignments;
147
71
  }
148
- return undefined;
149
- }
150
-
151
- export function resolvePatches(ctx: SerializationContext): string | undefined {
152
- return resolveAssignments(ctx.assignments);
72
+ return flags;
153
73
  }
154
74
 
155
75
  /**
@@ -159,7 +79,7 @@ export function resolvePatches(ctx: SerializationContext): string | undefined {
159
79
  */
160
80
 
161
81
  function createAssignment(
162
- ctx: SerializationContext,
82
+ ctx: SerializerContext,
163
83
  source: string,
164
84
  value: string,
165
85
  ): void {
@@ -172,7 +92,7 @@ function createAssignment(
172
92
  }
173
93
 
174
94
  function createAddAssignment(
175
- ctx: SerializationContext,
95
+ ctx: SerializerContext,
176
96
  ref: number,
177
97
  value: string,
178
98
  ): void {
@@ -185,7 +105,7 @@ function createAddAssignment(
185
105
  }
186
106
 
187
107
  function createSetAssignment(
188
- ctx: SerializationContext,
108
+ ctx: SerializerContext,
189
109
  ref: number,
190
110
  key: string,
191
111
  value: string,
@@ -199,7 +119,7 @@ function createSetAssignment(
199
119
  }
200
120
 
201
121
  function createAppendAssignment(
202
- ctx: SerializationContext,
122
+ ctx: SerializerContext,
203
123
  ref: number,
204
124
  key: string,
205
125
  value: string,
@@ -213,7 +133,7 @@ function createAppendAssignment(
213
133
  }
214
134
 
215
135
  function createArrayAssign(
216
- ctx: SerializationContext,
136
+ ctx: SerializerContext,
217
137
  ref: number,
218
138
  index: number | string,
219
139
  value: string,
@@ -222,7 +142,7 @@ function createArrayAssign(
222
142
  }
223
143
 
224
144
  function createObjectAssign(
225
- ctx: SerializationContext,
145
+ ctx: SerializerContext,
226
146
  ref: number,
227
147
  key: string,
228
148
  value: string,
@@ -232,25 +152,25 @@ function createObjectAssign(
232
152
  }
233
153
 
234
154
  function assignIndexedValue(
235
- ctx: SerializationContext,
155
+ ctx: SerializerContext,
236
156
  index: number,
237
157
  value: string,
238
158
  ): string {
239
- if (ctx.markedRefs.has(index)) {
159
+ if (ctx.reference.marked.has(index)) {
240
160
  return getRefParam(ctx, index) + '=' + value;
241
161
  }
242
162
  return value;
243
163
  }
244
164
 
245
165
  function isIndexedValueInStack(
246
- ctx: SerializationContext,
166
+ ctx: SerializerContext,
247
167
  node: SerovalNode,
248
168
  ): node is SerovalIndexedValueNode {
249
169
  return node.t === SerovalNodeType.IndexedValue && ctx.stack.includes(node.i);
250
170
  }
251
171
 
252
172
  function serializeArray(
253
- ctx: SerializationContext,
173
+ ctx: SerializerContext,
254
174
  node: SerovalArrayNode,
255
175
  ): string {
256
176
  const id = node.i;
@@ -284,17 +204,18 @@ function serializeArray(
284
204
  }
285
205
  }
286
206
  ctx.stack.pop();
207
+ pushObjectFlag(ctx, node.o, node.i);
287
208
  return assignIndexedValue(ctx, id, '[' + values + (isHoley ? ',]' : ']'));
288
209
  }
289
210
 
290
- function getIterableAccess(ctx: SerializationContext): string {
211
+ function getIterableAccess(ctx: SerializerContext): string {
291
212
  return ctx.features & Feature.ArrayPrototypeValues
292
213
  ? '.values()'
293
214
  : '[Symbol.iterator]()';
294
215
  }
295
216
 
296
217
  function serializeIterable(
297
- ctx: SerializationContext,
218
+ ctx: SerializerContext,
298
219
  node: SerovalNode,
299
220
  ): string {
300
221
  const parent = ctx.stack;
@@ -312,7 +233,7 @@ function serializeIterable(
312
233
  }
313
234
 
314
235
  function serializeProperties(
315
- ctx: SerializationContext,
236
+ ctx: SerializerContext,
316
237
  sourceID: number,
317
238
  node: SerovalObjectRecordNode,
318
239
  ): string {
@@ -365,7 +286,7 @@ function serializeProperties(
365
286
  }
366
287
 
367
288
  function serializeWithObjectAssign(
368
- ctx: SerializationContext,
289
+ ctx: SerializerContext,
369
290
  value: SerovalObjectRecordNode,
370
291
  id: number,
371
292
  serialized: string,
@@ -378,7 +299,7 @@ function serializeWithObjectAssign(
378
299
  }
379
300
 
380
301
  function serializeAssignments(
381
- ctx: SerializationContext,
302
+ ctx: SerializerContext,
382
303
  sourceID: number,
383
304
  node: SerovalObjectRecordNode,
384
305
  ): string | undefined {
@@ -392,14 +313,14 @@ function serializeAssignments(
392
313
  for (let i = 0, len = node.s; i < len; i++) {
393
314
  key = keys[i];
394
315
  value = values[i];
395
- parentAssignment = ctx.assignments;
396
- ctx.assignments = mainAssignments;
397
316
  switch (key) {
398
317
  case SerovalObjectRecordSpecialKey.SymbolIterator: {
399
318
  const parent = ctx.stack;
400
319
  ctx.stack = [];
401
320
  const serialized = serializeTree(ctx, value) + getIterableAccess(ctx);
402
321
  ctx.stack = parent;
322
+ parentAssignment = ctx.assignments;
323
+ ctx.assignments = mainAssignments;
403
324
  createArrayAssign(
404
325
  ctx,
405
326
  sourceID,
@@ -408,39 +329,52 @@ function serializeAssignments(
408
329
  ? '()=>' + serialized
409
330
  : 'function(){return ' + serialized + '}',
410
331
  );
332
+ ctx.assignments = parentAssignment;
411
333
  }
412
334
  break;
413
335
  default: {
414
336
  const serialized = serializeTree(ctx, value);
415
337
  const check = Number(key);
416
- // Test if key is a valid number or JS identifier
417
- // so that we don't have to serialize the key and wrap with brackets
418
338
  const isIdentifier = check >= 0 || isValidIdentifier(key);
419
- if (isIdentifier && Number.isNaN(check)) {
420
- createObjectAssign(ctx, sourceID, key, serialized);
339
+ if (isIndexedValueInStack(ctx, value)) {
340
+ // Test if key is a valid number or JS identifier
341
+ // so that we don't have to serialize the key and wrap with brackets
342
+ if (isIdentifier && Number.isNaN(check)) {
343
+ createObjectAssign(ctx, sourceID, key, serialized);
344
+ } else {
345
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : ('"' + key + '"'), serialized);
346
+ }
421
347
  } else {
422
- createArrayAssign(ctx, sourceID, isIdentifier ? key : ('"' + key + '"'), serialized);
348
+ // Test if key is a valid number or JS identifier
349
+ // so that we don't have to serialize the key and wrap with brackets
350
+ parentAssignment = ctx.assignments;
351
+ ctx.assignments = mainAssignments;
352
+ if (isIdentifier && Number.isNaN(check)) {
353
+ createObjectAssign(ctx, sourceID, key, serialized);
354
+ } else {
355
+ createArrayAssign(ctx, sourceID, isIdentifier ? key : ('"' + key + '"'), serialized);
356
+ }
357
+ ctx.assignments = parentAssignment;
423
358
  }
424
359
  }
425
360
  }
426
- ctx.assignments = parentAssignment;
427
361
  }
428
362
  ctx.stack.pop();
429
363
  return resolveAssignments(mainAssignments);
430
364
  }
431
365
 
432
366
  function serializeDictionary(
433
- ctx: SerializationContext,
367
+ ctx: SerializerContext,
434
368
  i: number,
435
- d: SerovalObjectRecordNode | undefined,
369
+ p: SerovalObjectRecordNode | undefined,
436
370
  init: string,
437
371
  ): string {
438
- if (d) {
372
+ if (p) {
439
373
  if (ctx.features & Feature.ObjectAssign) {
440
- init = serializeWithObjectAssign(ctx, d, i, init);
374
+ init = serializeWithObjectAssign(ctx, p, i, init);
441
375
  } else {
442
376
  markRef(ctx, i);
443
- const assignments = serializeAssignments(ctx, i, d);
377
+ const assignments = serializeAssignments(ctx, i, p);
444
378
  if (assignments) {
445
379
  return '(' + assignIndexedValue(ctx, i, init) + ',' + assignments + getRefParam(ctx, i) + ')';
446
380
  }
@@ -452,21 +386,23 @@ function serializeDictionary(
452
386
  const NULL_CONSTRUCTOR = 'Object.create(null)';
453
387
 
454
388
  function serializeNullConstructor(
455
- ctx: SerializationContext,
389
+ ctx: SerializerContext,
456
390
  node: SerovalNullConstructorNode,
457
391
  ): string {
458
- return serializeDictionary(ctx, node.i, node.d, NULL_CONSTRUCTOR);
392
+ pushObjectFlag(ctx, node.o, node.i);
393
+ return serializeDictionary(ctx, node.i, node.p, NULL_CONSTRUCTOR);
459
394
  }
460
395
 
461
396
  function serializeObject(
462
- ctx: SerializationContext,
397
+ ctx: SerializerContext,
463
398
  node: SerovalObjectNode,
464
399
  ): string {
465
- return assignIndexedValue(ctx, node.i, serializeProperties(ctx, node.i, node.d));
400
+ pushObjectFlag(ctx, node.o, node.i);
401
+ return assignIndexedValue(ctx, node.i, serializeProperties(ctx, node.i, node.p));
466
402
  }
467
403
 
468
404
  function serializeSet(
469
- ctx: SerializationContext,
405
+ ctx: SerializerContext,
470
406
  node: SerovalSetNode,
471
407
  ): string {
472
408
  let serialized = 'new Set';
@@ -498,11 +434,11 @@ function serializeSet(
498
434
  }
499
435
 
500
436
  function serializeMap(
501
- ctx: SerializationContext,
437
+ ctx: SerializerContext,
502
438
  node: SerovalMapNode,
503
439
  ): string {
504
440
  let serialized = 'new Map';
505
- const size = node.d.s;
441
+ const size = node.e.s;
506
442
  const id = node.i;
507
443
  if (size) {
508
444
  let result = '';
@@ -512,8 +448,8 @@ function serializeMap(
512
448
  let valueRef: string;
513
449
  let parent: number[];
514
450
  let hasPrev = false;
515
- const keys = node.d.k;
516
- const vals = node.d.v;
451
+ const keys = node.e.k;
452
+ const vals = node.e.v;
517
453
  ctx.stack.push(id);
518
454
  for (let i = 0; i < size; i++) {
519
455
  // Check if key is a parent
@@ -567,7 +503,7 @@ function serializeMap(
567
503
  }
568
504
 
569
505
  function serializeAggregateError(
570
- ctx: SerializationContext,
506
+ ctx: SerializerContext,
571
507
  node: SerovalAggregateErrorNode,
572
508
  ): string {
573
509
  // Serialize the required arguments
@@ -578,24 +514,28 @@ function serializeAggregateError(
578
514
  // `AggregateError` might've been extended
579
515
  // either through class or custom properties
580
516
  // Make sure to assign extra properties
581
- return serializeDictionary(ctx, id, node.d, serialized);
517
+ return serializeDictionary(ctx, id, node.p, serialized);
582
518
  }
583
519
 
584
520
  function serializeError(
585
- ctx: SerializationContext,
521
+ ctx: SerializerContext,
586
522
  node: SerovalErrorNode,
587
523
  ): string {
588
- 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 + '")');
589
525
  }
590
526
 
527
+ const PROMISE_RESOLVE = 'Promise.resolve';
528
+ const PROMISE_REJECT = 'Promise.reject';
529
+
591
530
  function serializePromise(
592
- ctx: SerializationContext,
531
+ ctx: SerializerContext,
593
532
  node: SerovalPromiseNode,
594
533
  ): string {
595
534
  let serialized: string;
596
535
  // Check if resolved value is a parent expression
597
536
  const fulfilled = node.f;
598
537
  const id = node.i;
538
+ const constructor = node.s ? PROMISE_RESOLVE : PROMISE_REJECT;
599
539
  if (isIndexedValueInStack(ctx, fulfilled)) {
600
540
  // A Promise trick, reference the value
601
541
  // inside the `then` expression so that
@@ -603,22 +543,28 @@ function serializePromise(
603
543
  // has initialized
604
544
  const ref = getRefParam(ctx, fulfilled.i);
605
545
  if (ctx.features & Feature.ArrowFunction) {
606
- 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 + '})';
607
553
  } else {
608
- serialized = 'Promise.resolve().then(function(){return ' + ref + '})';
554
+ serialized = constructor + '().catch(function(){throw ' + ref + '})';
609
555
  }
610
556
  } else {
611
557
  ctx.stack.push(id);
612
558
  const result = serializeTree(ctx, fulfilled);
613
559
  ctx.stack.pop();
614
560
  // just inline the value/reference here
615
- serialized = 'Promise.resolve(' + result + ')';
561
+ serialized = constructor + '(' + result + ')';
616
562
  }
617
563
  return assignIndexedValue(ctx, id, serialized);
618
564
  }
619
565
 
620
566
  function serializeArrayBuffer(
621
- ctx: SerializationContext,
567
+ ctx: SerializerContext,
622
568
  node: SerovalArrayBufferNode,
623
569
  ): string {
624
570
  let result = 'new Uint8Array(';
@@ -635,7 +581,7 @@ function serializeArrayBuffer(
635
581
  }
636
582
 
637
583
  function serializeTypedArray(
638
- ctx: SerializationContext,
584
+ ctx: SerializerContext,
639
585
  node: SerovalTypedArrayNode | SerovalBigIntTypedArrayNode,
640
586
  ): string {
641
587
  return assignIndexedValue(
@@ -646,28 +592,28 @@ function serializeTypedArray(
646
592
  }
647
593
 
648
594
  function serializeDate(
649
- ctx: SerializationContext,
595
+ ctx: SerializerContext,
650
596
  node: SerovalDateNode,
651
597
  ): string {
652
598
  return assignIndexedValue(ctx, node.i, 'new Date("' + node.s + '")');
653
599
  }
654
600
 
655
601
  function serializeRegExp(
656
- ctx: SerializationContext,
602
+ ctx: SerializerContext,
657
603
  node: SerovalRegExpNode,
658
604
  ): string {
659
605
  return assignIndexedValue(ctx, node.i, '/' + node.c + '/' + node.m);
660
606
  }
661
607
 
662
608
  function serializeURL(
663
- ctx: SerializationContext,
609
+ ctx: SerializerContext,
664
610
  node: SerovalURLNode,
665
611
  ): string {
666
612
  return assignIndexedValue(ctx, node.i, 'new URL("' + node.s + '")');
667
613
  }
668
614
 
669
615
  function serializeURLSearchParams(
670
- ctx: SerializationContext,
616
+ ctx: SerializerContext,
671
617
  node: SerovalURLSearchParamsNode,
672
618
  ): string {
673
619
  return assignIndexedValue(
@@ -678,14 +624,14 @@ function serializeURLSearchParams(
678
624
  }
679
625
 
680
626
  function serializeReference(
681
- ctx: SerializationContext,
627
+ ctx: SerializerContext,
682
628
  node: SerovalReferenceNode,
683
629
  ): string {
684
- return assignIndexedValue(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
630
+ return assignIndexedValue(ctx, node.i, REFERENCES_KEY + '.get("' + node.s + '")');
685
631
  }
686
632
 
687
633
  function serializeDataView(
688
- ctx: SerializationContext,
634
+ ctx: SerializerContext,
689
635
  node: SerovalDataViewNode,
690
636
  ): string {
691
637
  return assignIndexedValue(
@@ -696,7 +642,7 @@ function serializeDataView(
696
642
  }
697
643
 
698
644
  function serializeBlob(
699
- ctx: SerializationContext,
645
+ ctx: SerializerContext,
700
646
  node: SerovalBlobNode,
701
647
  ): string {
702
648
  return assignIndexedValue(
@@ -707,7 +653,7 @@ function serializeBlob(
707
653
  }
708
654
 
709
655
  function serializeFile(
710
- ctx: SerializationContext,
656
+ ctx: SerializerContext,
711
657
  node: SerovalFileNode,
712
658
  ): string {
713
659
  return assignIndexedValue(
@@ -718,29 +664,29 @@ function serializeFile(
718
664
  }
719
665
 
720
666
  function serializeHeaders(
721
- ctx: SerializationContext,
667
+ ctx: SerializerContext,
722
668
  node: SerovalHeadersNode,
723
669
  ): string {
724
670
  return assignIndexedValue(
725
671
  ctx,
726
672
  node.i,
727
- 'new Headers(' + serializeProperties(ctx, node.i, node.d) + ')',
673
+ 'new Headers(' + serializeProperties(ctx, node.i, node.e) + ')',
728
674
  );
729
675
  }
730
676
 
731
677
  function serializeFormDataEntries(
732
- ctx: SerializationContext,
678
+ ctx: SerializerContext,
733
679
  node: SerovalFormDataNode,
734
680
  ): string | undefined {
735
681
  let value: string;
736
682
  let key: string;
737
- const keys = node.d.k;
738
- const vals = node.d.v;
683
+ const keys = node.e.k;
684
+ const vals = node.e.v;
739
685
  const id = node.i;
740
686
  const mainAssignments: Assignment[] = [];
741
687
  let parentAssignment: Assignment[];
742
688
  ctx.stack.push(id);
743
- for (let i = 0, len = node.d.s; i < len; i++) {
689
+ for (let i = 0, len = node.e.s; i < len; i++) {
744
690
  key = keys[i];
745
691
  value = serializeTree(ctx, vals[i]);
746
692
  parentAssignment = ctx.assignments;
@@ -753,10 +699,10 @@ function serializeFormDataEntries(
753
699
  }
754
700
 
755
701
  function serializeFormData(
756
- ctx: SerializationContext,
702
+ ctx: SerializerContext,
757
703
  node: SerovalFormDataNode,
758
704
  ): string {
759
- const size = node.d.s;
705
+ const size = node.e.s;
760
706
  const id = node.i;
761
707
  if (size) {
762
708
  markRef(ctx, id);
@@ -770,21 +716,21 @@ function serializeFormData(
770
716
  }
771
717
 
772
718
  function serializeBoxed(
773
- ctx: SerializationContext,
719
+ ctx: SerializerContext,
774
720
  node: SerovalBoxedNode,
775
721
  ): string {
776
722
  return assignIndexedValue(ctx, node.i, 'Object(' + serializeTree(ctx, node.f) + ')');
777
723
  }
778
724
 
779
725
  function serializeWKSymbol(
780
- ctx: SerializationContext,
726
+ ctx: SerializerContext,
781
727
  node: SerovalWKSymbolNode,
782
728
  ): string {
783
729
  return assignIndexedValue(ctx, node.i, SYMBOL_STRING[node.s]);
784
730
  }
785
731
 
786
732
  export default function serializeTree(
787
- ctx: SerializationContext,
733
+ ctx: SerializerContext,
788
734
  node: SerovalNode,
789
735
  ): string {
790
736
  switch (node.t) {