seroval 0.15.1 → 1.0.0

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 (114) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/development/index.cjs +1221 -1867
  3. package/dist/cjs/development/index.cjs.map +3 -3
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +1222 -1868
  6. package/dist/esm/development/index.mjs.map +3 -3
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +2 -1
  9. package/dist/types/core/Serializer.d.ts.map +1 -1
  10. package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
  11. package/dist/types/core/base-primitives.d.ts +6 -2
  12. package/dist/types/core/base-primitives.d.ts.map +1 -1
  13. package/dist/types/core/compat.d.ts +5 -13
  14. package/dist/types/core/compat.d.ts.map +1 -1
  15. package/dist/types/core/constants.d.ts +17 -29
  16. package/dist/types/core/constants.d.ts.map +1 -1
  17. package/dist/types/core/context/deserializer.d.ts +6 -16
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser/async.d.ts +2 -11
  20. package/dist/types/core/context/parser/async.d.ts.map +1 -1
  21. package/dist/types/core/context/parser/stream.d.ts +10 -10
  22. package/dist/types/core/context/parser/stream.d.ts.map +1 -1
  23. package/dist/types/core/context/parser/sync.d.ts +5 -7
  24. package/dist/types/core/context/parser/sync.d.ts.map +1 -1
  25. package/dist/types/core/context/parser.d.ts +19 -4
  26. package/dist/types/core/context/parser.d.ts.map +1 -1
  27. package/dist/types/core/context/serializer.d.ts +11 -25
  28. package/dist/types/core/context/serializer.d.ts.map +1 -1
  29. package/dist/types/core/cross/async.d.ts.map +1 -1
  30. package/dist/types/core/cross/deserializer.d.ts.map +1 -1
  31. package/dist/types/core/cross/index.d.ts.map +1 -1
  32. package/dist/types/core/cross/parser.d.ts.map +1 -1
  33. package/dist/types/core/cross/serializer.d.ts +1 -1
  34. package/dist/types/core/cross/serializer.d.ts.map +1 -1
  35. package/dist/types/core/cross/stream.d.ts.map +1 -1
  36. package/dist/types/core/cross/sync.d.ts.map +1 -1
  37. package/dist/types/core/keys.d.ts.map +1 -1
  38. package/dist/types/core/literals.d.ts.map +1 -1
  39. package/dist/types/core/plugin.d.ts +21 -0
  40. package/dist/types/core/plugin.d.ts.map +1 -1
  41. package/dist/types/core/reference.d.ts.map +1 -1
  42. package/dist/types/core/special-reference.d.ts +4 -9
  43. package/dist/types/core/special-reference.d.ts.map +1 -1
  44. package/dist/types/core/stream.d.ts +18 -0
  45. package/dist/types/core/stream.d.ts.map +1 -0
  46. package/dist/types/core/string.d.ts.map +1 -1
  47. package/dist/types/core/tree/async.d.ts.map +1 -1
  48. package/dist/types/core/tree/deserializer.d.ts.map +1 -1
  49. package/dist/types/core/tree/index.d.ts +1 -1
  50. package/dist/types/core/tree/index.d.ts.map +1 -1
  51. package/dist/types/core/tree/serializer.d.ts +3 -11
  52. package/dist/types/core/tree/serializer.d.ts.map +1 -1
  53. package/dist/types/core/types.d.ts +28 -122
  54. package/dist/types/core/types.d.ts.map +1 -1
  55. package/dist/types/core/utils/deferred.d.ts +0 -7
  56. package/dist/types/core/utils/deferred.d.ts.map +1 -1
  57. package/dist/types/core/utils/error.d.ts +2 -1
  58. package/dist/types/core/utils/error.d.ts.map +1 -1
  59. package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
  60. package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
  61. package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
  62. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  63. package/dist/types/core/utils/typed-array.d.ts +2 -0
  64. package/dist/types/core/utils/typed-array.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +2 -3
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/package.json +7 -7
  68. package/src/core/Serializer.ts +44 -28
  69. package/src/core/UnsupportedTypeError.ts +2 -3
  70. package/src/core/base-primitives.ts +124 -38
  71. package/src/core/compat.ts +5 -14
  72. package/src/core/constants.ts +28 -39
  73. package/src/core/context/deserializer.ts +122 -308
  74. package/src/core/context/parser/async.ts +163 -375
  75. package/src/core/context/parser/stream.ts +109 -367
  76. package/src/core/context/parser/sync.ts +139 -266
  77. package/src/core/context/parser.ts +93 -68
  78. package/src/core/context/serializer.ts +370 -439
  79. package/src/core/cross/async.ts +1 -1
  80. package/src/core/cross/deserializer.ts +1 -4
  81. package/src/core/cross/index.ts +26 -20
  82. package/src/core/cross/parser.ts +1 -1
  83. package/src/core/cross/serializer.ts +30 -20
  84. package/src/core/cross/stream.ts +1 -1
  85. package/src/core/cross/sync.ts +1 -1
  86. package/src/core/keys.ts +3 -1
  87. package/src/core/literals.ts +22 -8
  88. package/src/core/plugin.ts +48 -10
  89. package/src/core/reference.ts +4 -5
  90. package/src/core/special-reference.ts +5 -15
  91. package/src/core/stream.ts +205 -0
  92. package/src/core/string.ts +53 -22
  93. package/src/core/tree/async.ts +1 -1
  94. package/src/core/tree/deserializer.ts +4 -9
  95. package/src/core/tree/index.ts +15 -10
  96. package/src/core/tree/serializer.ts +6 -50
  97. package/src/core/types.ts +39 -179
  98. package/src/core/utils/deferred.ts +0 -27
  99. package/src/core/utils/error.ts +26 -15
  100. package/src/core/utils/get-identifier.ts +5 -4
  101. package/src/core/utils/is-valid-identifier.ts +6 -5
  102. package/src/core/utils/iterator-to-sequence.ts +0 -174
  103. package/src/core/utils/typed-array.ts +35 -11
  104. package/src/index.ts +3 -12
  105. package/dist/types/core/utils/constructors.d.ts +0 -5
  106. package/dist/types/core/utils/constructors.d.ts.map +0 -1
  107. package/dist/types/core/web-api.d.ts +0 -8
  108. package/dist/types/core/web-api.d.ts.map +0 -1
  109. package/dist/types/types.d.ts +0 -21
  110. package/dist/types/types.d.ts.map +0 -1
  111. package/src/core/utils/constructors.ts +0 -49
  112. package/src/core/web-api.ts +0 -138
  113. package/src/example.ts +0 -25
  114. package/src/types.ts +0 -84
@@ -1,11 +1,9 @@
1
- /* eslint-disable prefer-destructuring */
2
- import type { BigIntTypedArrayValue, TypedArrayValue } from '../../../types';
3
1
  import UnsupportedTypeError from '../../UnsupportedTypeError';
4
- import assert from '../../utils/assert';
5
2
  import {
6
3
  createAggregateErrorNode,
7
4
  createArrayBufferNode,
8
5
  createArrayNode,
6
+ createAsyncIteratorFactoryInstanceNode,
9
7
  createBigIntNode,
10
8
  createBigIntTypedArrayNode,
11
9
  createBoxedNode,
@@ -17,16 +15,12 @@ import {
17
15
  createPluginNode,
18
16
  createRegExpNode,
19
17
  createSetNode,
18
+ createStreamConstructorNode,
20
19
  createStringNode,
21
20
  createTypedArrayNode,
22
- createWKSymbolNode,
23
21
  } from '../../base-primitives';
24
- import { BIGINT_FLAG, Feature } from '../../compat';
25
- import type { WellKnownSymbols } from '../../constants';
26
- import {
27
- SerovalNodeType,
28
- } from '../../constants';
29
- import { createCustomEventOptions, createEventOptions } from '../../utils/constructors';
22
+ import { Feature } from '../../compat';
23
+ import { SerovalNodeType } from '../../constants';
30
24
  import {
31
25
  FALSE_NODE,
32
26
  NULL_NODE,
@@ -36,7 +30,6 @@ import {
36
30
  import { iteratorToSequence } from '../../utils/iterator-to-sequence';
37
31
  import type { BaseParserContextOptions } from '../parser';
38
32
  import { BaseParserContext } from '../parser';
39
- import { hasReferenceID } from '../../reference';
40
33
  import { getErrorOptions } from '../../utils/error';
41
34
  import { serializeString } from '../../string';
42
35
  import type {
@@ -52,34 +45,25 @@ import type {
52
45
  SerovalSetNode,
53
46
  SerovalPluginNode,
54
47
  SerovalAggregateErrorNode,
55
- SerovalCustomEventNode,
56
- SerovalEventNode,
57
- SerovalHeadersNode,
58
- SerovalPlainRecordNode,
59
- SerovalFormDataNode,
60
48
  SerovalTypedArrayNode,
61
49
  SerovalBigIntTypedArrayNode,
62
50
  SerovalDataViewNode,
51
+ SerovalPromiseConstructorNode,
63
52
  } from '../../types';
64
- import {
65
- createCustomEventNode,
66
- createDOMExceptionNode,
67
- createEventNode,
68
- createURLNode,
69
- createURLSearchParamsNode,
70
- } from '../../web-api';
71
- import { UNIVERSAL_SENTINEL } from '../../special-reference';
53
+ import { SpecialReference } from '../../special-reference';
54
+ import type { Stream } from '../../stream';
55
+ import { createStream, isStream } from '../../stream';
56
+ import type {
57
+ BigIntTypedArrayValue,
58
+ TypedArrayValue,
59
+ } from '../../utils/typed-array';
72
60
 
73
- type ObjectLikeNode =
74
- | SerovalObjectNode
75
- | SerovalNullConstructorNode;
61
+ type ObjectLikeNode = SerovalObjectNode | SerovalNullConstructorNode;
76
62
 
77
- export type BaseSyncParserContextOptions = BaseParserContextOptions
63
+ export type BaseSyncParserContextOptions = BaseParserContextOptions;
78
64
 
79
65
  export default abstract class BaseSyncParserContext extends BaseParserContext {
80
- protected parseItems(
81
- current: unknown[],
82
- ): SerovalNode[] {
66
+ protected parseItems(current: unknown[]): SerovalNode[] {
83
67
  const nodes = [];
84
68
  for (let i = 0, len = current.length; i < len; i++) {
85
69
  if (i in current) {
@@ -89,15 +73,8 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
89
73
  return nodes;
90
74
  }
91
75
 
92
- protected parseArray(
93
- id: number,
94
- current: unknown[],
95
- ): SerovalArrayNode {
96
- return createArrayNode(
97
- id,
98
- current,
99
- this.parseItems(current),
100
- );
76
+ protected parseArray(id: number, current: unknown[]): SerovalArrayNode {
77
+ return createArrayNode(id, current, this.parseItems(current));
101
78
  }
102
79
 
103
80
  protected parseProperties(
@@ -106,40 +83,42 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
106
83
  const entries = Object.entries(properties);
107
84
  const keyNodes: SerovalObjectRecordKey[] = [];
108
85
  const valueNodes: SerovalNode[] = [];
109
- for (
110
- let i = 0, len = entries.length;
111
- i < len;
112
- i++
113
- ) {
86
+ for (let i = 0, len = entries.length; i < len; i++) {
114
87
  keyNodes.push(serializeString(entries[i][0]));
115
88
  valueNodes.push(this.parse(entries[i][1]));
116
89
  }
117
90
  // Check special properties, symbols in this case
118
- if (this.features & Feature.Symbol) {
119
- let symbol = Symbol.iterator;
120
- if (symbol in properties) {
121
- keyNodes.push(
122
- this.parseWKSymbol(symbol),
123
- );
124
- valueNodes.push(
125
- createIteratorFactoryInstanceNode(
126
- this.parseIteratorFactory(),
127
- this.parse(
128
- iteratorToSequence(properties as unknown as Iterable<unknown>),
129
- ),
91
+ let symbol = Symbol.iterator;
92
+ if (symbol in properties) {
93
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
94
+ valueNodes.push(
95
+ createIteratorFactoryInstanceNode(
96
+ this.parseIteratorFactory(),
97
+ this.parse(
98
+ iteratorToSequence(properties as unknown as Iterable<unknown>),
130
99
  ),
131
- );
132
- }
133
- symbol = Symbol.toStringTag;
134
- if (symbol in properties) {
135
- keyNodes.push(this.parseWKSymbol(symbol));
136
- valueNodes.push(createStringNode(properties[symbol] as string));
137
- }
138
- symbol = Symbol.isConcatSpreadable;
139
- if (symbol in properties) {
140
- keyNodes.push(this.parseWKSymbol(symbol));
141
- valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
142
- }
100
+ ),
101
+ );
102
+ }
103
+ symbol = Symbol.asyncIterator;
104
+ if (symbol in properties) {
105
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
106
+ valueNodes.push(
107
+ createAsyncIteratorFactoryInstanceNode(
108
+ this.parseAsyncIteratorFactory(),
109
+ this.parse(createStream()),
110
+ ),
111
+ );
112
+ }
113
+ symbol = Symbol.toStringTag;
114
+ if (symbol in properties) {
115
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
116
+ valueNodes.push(createStringNode(properties[symbol] as string));
117
+ }
118
+ symbol = Symbol.isConcatSpreadable;
119
+ if (symbol in properties) {
120
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
121
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
143
122
  }
144
123
  return {
145
124
  k: keyNodes,
@@ -161,10 +140,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
161
140
  );
162
141
  }
163
142
 
164
- protected parseBoxed(
165
- id: number,
166
- current: object,
167
- ): SerovalBoxedNode {
143
+ protected parseBoxed(id: number, current: object): SerovalBoxedNode {
168
144
  return createBoxedNode(id, this.parse(current.valueOf()));
169
145
  }
170
146
 
@@ -182,24 +158,16 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
182
158
  return createBigIntTypedArrayNode(id, current, this.parse(current.buffer));
183
159
  }
184
160
 
185
- protected parseDataView(
186
- id: number,
187
- current: DataView,
188
- ): SerovalDataViewNode {
161
+ protected parseDataView(id: number, current: DataView): SerovalDataViewNode {
189
162
  return createDataViewNode(id, current, this.parse(current.buffer));
190
163
  }
191
164
 
192
- protected parseError(
193
- id: number,
194
- current: Error,
195
- ): SerovalErrorNode {
165
+ protected parseError(id: number, current: Error): SerovalErrorNode {
196
166
  const options = getErrorOptions(current, this.features);
197
167
  return createErrorNode(
198
168
  id,
199
169
  current,
200
- options
201
- ? this.parseProperties(options)
202
- : undefined,
170
+ options ? this.parseProperties(options) : undefined,
203
171
  );
204
172
  }
205
173
 
@@ -211,9 +179,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
211
179
  return createAggregateErrorNode(
212
180
  id,
213
181
  current,
214
- options
215
- ? this.parseProperties(options)
216
- : undefined,
182
+ options ? this.parseProperties(options) : undefined,
217
183
  );
218
184
  }
219
185
 
@@ -227,18 +193,10 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
227
193
  keyNodes.push(this.parse(key));
228
194
  valueNodes.push(this.parse(value));
229
195
  }
230
- return this.createMapNode(
231
- id,
232
- keyNodes,
233
- valueNodes,
234
- current.size,
235
- );
196
+ return this.createMapNode(id, keyNodes, valueNodes, current.size);
236
197
  }
237
198
 
238
- protected parseSet(
239
- id: number,
240
- current: Set<unknown>,
241
- ): SerovalSetNode {
199
+ protected parseSet(id: number, current: Set<unknown>): SerovalSetNode {
242
200
  const items: SerovalNode[] = [];
243
201
  for (const item of current.keys()) {
244
202
  items.push(this.parse(item));
@@ -246,85 +204,6 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
246
204
  return createSetNode(id, current.size, items);
247
205
  }
248
206
 
249
- protected parsePlainProperties(
250
- entries: [key: string, value: unknown][],
251
- ): SerovalPlainRecordNode {
252
- const size = entries.length;
253
- const keyNodes: string[] = [];
254
- const valueNodes: SerovalNode[] = [];
255
- for (let i = 0; i < size; i++) {
256
- keyNodes.push(serializeString(entries[i][0]));
257
- valueNodes.push(this.parse(entries[i][1]));
258
- }
259
- return {
260
- k: keyNodes,
261
- v: valueNodes,
262
- s: size,
263
- };
264
- }
265
-
266
- protected parseHeaders(
267
- id: number,
268
- current: Headers,
269
- ): SerovalHeadersNode {
270
- const items: [key: string, value: unknown][] = [];
271
- current.forEach((value, key) => {
272
- items.push([key, value]);
273
- });
274
- return {
275
- t: SerovalNodeType.Headers,
276
- i: id,
277
- s: undefined,
278
- l: undefined,
279
- c: undefined,
280
- m: undefined,
281
- p: undefined,
282
- e: this.parsePlainProperties(items),
283
- a: undefined,
284
- f: undefined,
285
- b: undefined,
286
- o: undefined,
287
- };
288
- }
289
-
290
- protected parseFormData(
291
- id: number,
292
- current: FormData,
293
- ): SerovalFormDataNode {
294
- const items: [key: string, value: unknown][] = [];
295
- current.forEach((value, key) => {
296
- items.push([key, value]);
297
- });
298
- return {
299
- t: SerovalNodeType.FormData,
300
- i: id,
301
- s: undefined,
302
- l: undefined,
303
- c: undefined,
304
- m: undefined,
305
- p: undefined,
306
- e: this.parsePlainProperties(items),
307
- a: undefined,
308
- f: undefined,
309
- b: undefined,
310
- o: undefined,
311
- };
312
- }
313
-
314
- protected parseEvent(
315
- id: number,
316
- current: Event,
317
- ): SerovalEventNode {
318
- return createEventNode(id, current.type, this.parse(createEventOptions(current)));
319
- }
320
-
321
- protected parseCustomEvent(
322
- id: number,
323
- current: CustomEvent,
324
- ): SerovalCustomEventNode {
325
- return createCustomEventNode(id, current.type, this.parse(createCustomEventOptions(current)));
326
- }
327
-
328
207
  protected parsePlugin(
329
208
  id: number,
330
209
  current: unknown,
@@ -347,13 +226,45 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
347
226
  return undefined;
348
227
  }
349
228
 
350
- protected parseObject(
229
+ protected parseStream(id: number, _current: Stream<unknown>): SerovalNode {
230
+ return createStreamConstructorNode(
231
+ id,
232
+ this.parseSpecialReference(SpecialReference.StreamConstructor),
233
+ [],
234
+ );
235
+ }
236
+
237
+ protected parsePromise(
351
238
  id: number,
352
- current: object,
353
- ): SerovalNode {
239
+ _current: Promise<unknown>,
240
+ ): SerovalPromiseConstructorNode {
241
+ return {
242
+ t: SerovalNodeType.PromiseConstructor,
243
+ i: id,
244
+ s: undefined,
245
+ l: undefined,
246
+ c: undefined,
247
+ m: undefined,
248
+ p: undefined,
249
+ e: undefined,
250
+ a: undefined,
251
+ f: this.parseSpecialReference(SpecialReference.PromiseConstructor),
252
+ b: undefined,
253
+ o: undefined,
254
+ };
255
+ }
256
+
257
+ protected parseObject(id: number, current: object): SerovalNode {
354
258
  if (Array.isArray(current)) {
355
259
  return this.parseArray(id, current);
356
260
  }
261
+ if (isStream(current)) {
262
+ return this.parseStream(id, current);
263
+ }
264
+ const parsed = this.parsePlugin(id, current);
265
+ if (parsed) {
266
+ return parsed;
267
+ }
357
268
  const currentClass = current.constructor;
358
269
  switch (currentClass) {
359
270
  case Object:
@@ -385,83 +296,49 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
385
296
  case String:
386
297
  case BigInt:
387
298
  return this.parseBoxed(id, current);
299
+ case ArrayBuffer:
300
+ return createArrayBufferNode(id, current as unknown as ArrayBuffer);
301
+ case Int8Array:
302
+ case Int16Array:
303
+ case Int32Array:
304
+ case Uint8Array:
305
+ case Uint16Array:
306
+ case Uint32Array:
307
+ case Uint8ClampedArray:
308
+ case Float32Array:
309
+ case Float64Array:
310
+ return this.parseTypedArray(id, current as unknown as TypedArrayValue);
311
+ case DataView:
312
+ return this.parseDataView(id, current as unknown as DataView);
313
+ case Map:
314
+ return this.parseMap(id, current as unknown as Map<unknown, unknown>);
315
+ case Set:
316
+ return this.parseSet(id, current as unknown as Set<unknown>);
388
317
  default:
389
318
  break;
390
319
  }
391
- const currentFeatures = this.features;
392
- // Typed Arrays
393
- if (currentFeatures & Feature.TypedArray) {
394
- switch (currentClass) {
395
- case ArrayBuffer:
396
- return createArrayBufferNode(id, current as unknown as ArrayBuffer);
397
- case Int8Array:
398
- case Int16Array:
399
- case Int32Array:
400
- case Uint8Array:
401
- case Uint16Array:
402
- case Uint32Array:
403
- case Uint8ClampedArray:
404
- case Float32Array:
405
- case Float64Array:
406
- return this.parseTypedArray(id, current as unknown as TypedArrayValue);
407
- case DataView:
408
- return this.parseDataView(id, current as unknown as DataView);
409
- default:
410
- break;
411
- }
320
+ // Promises
321
+ if (currentClass === Promise || current instanceof Promise) {
322
+ return this.parsePromise(id, current as unknown as Promise<unknown>);
412
323
  }
324
+ const currentFeatures = this.features;
413
325
  // BigInt Typed Arrays
414
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
326
+ if (currentFeatures & Feature.BigIntTypedArray) {
415
327
  switch (currentClass) {
416
328
  case BigInt64Array:
417
329
  case BigUint64Array:
418
- return this.parseBigIntTypedArray(id, current as unknown as BigIntTypedArrayValue);
419
- default:
420
- break;
421
- }
422
- }
423
- // ES Collection
424
- if (currentFeatures & Feature.Map && currentClass === Map) {
425
- return this.parseMap(
426
- id,
427
- current as unknown as Map<unknown, unknown>,
428
- );
429
- }
430
- if (currentFeatures & Feature.Set && currentClass === Set) {
431
- return this.parseSet(
432
- id,
433
- current as unknown as Set<unknown>,
434
- );
435
- }
436
- // Web APIs
437
- if (currentFeatures & Feature.WebAPI) {
438
- switch (currentClass) {
439
- case (typeof URL !== 'undefined' ? URL : UNIVERSAL_SENTINEL):
440
- return createURLNode(id, current as unknown as URL);
441
- case (typeof URLSearchParams !== 'undefined' ? URLSearchParams : UNIVERSAL_SENTINEL):
442
- return createURLSearchParamsNode(id, current as unknown as URLSearchParams);
443
- case (typeof Headers !== 'undefined' ? Headers : UNIVERSAL_SENTINEL):
444
- return this.parseHeaders(id, current as unknown as Headers);
445
- case (typeof FormData !== 'undefined' ? FormData : UNIVERSAL_SENTINEL):
446
- return this.parseFormData(id, current as unknown as FormData);
447
- case (typeof Event !== 'undefined' ? Event : UNIVERSAL_SENTINEL):
448
- return this.parseEvent(id, current as unknown as Event);
449
- case (typeof CustomEvent !== 'undefined' ? CustomEvent : UNIVERSAL_SENTINEL):
450
- return this.parseCustomEvent(id, current as unknown as CustomEvent);
451
- case (typeof DOMException !== 'undefined' ? DOMException : UNIVERSAL_SENTINEL):
452
- return createDOMExceptionNode(id, current as unknown as DOMException);
330
+ return this.parseBigIntTypedArray(
331
+ id,
332
+ current as unknown as BigIntTypedArrayValue,
333
+ );
453
334
  default:
454
335
  break;
455
336
  }
456
337
  }
457
- const parsed = this.parsePlugin(id, current);
458
- if (parsed) {
459
- return parsed;
460
- }
461
338
  if (
462
- (currentFeatures & Feature.AggregateError)
463
- && typeof AggregateError !== 'undefined'
464
- && (currentClass === AggregateError || current instanceof AggregateError)
339
+ currentFeatures & Feature.AggregateError &&
340
+ typeof AggregateError !== 'undefined' &&
341
+ (currentClass === AggregateError || current instanceof AggregateError)
465
342
  ) {
466
343
  return this.parseAggregateError(id, current as unknown as AggregateError);
467
344
  }
@@ -472,41 +349,37 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
472
349
  }
473
350
  // Generator functions don't have a global constructor
474
351
  // despite existing
475
- if (
476
- currentFeatures & Feature.Symbol
477
- && Symbol.iterator in current
478
- ) {
352
+ if (Symbol.iterator in current || Symbol.asyncIterator in current) {
479
353
  return this.parsePlainObject(id, current, !!currentClass);
480
354
  }
481
355
  throw new UnsupportedTypeError(current);
482
356
  }
483
357
 
484
358
  parse<T>(current: T): SerovalNode {
485
- switch (current) {
486
- case true: return TRUE_NODE;
487
- case false: return FALSE_NODE;
488
- case undefined: return UNDEFINED_NODE;
489
- case null: return NULL_NODE;
490
- default: break;
491
- }
492
359
  switch (typeof current) {
493
- case 'string': return createStringNode(current as string);
494
- case 'number': return createNumberNode(current as number);
360
+ case 'boolean':
361
+ return current ? TRUE_NODE : FALSE_NODE;
362
+ case 'undefined':
363
+ return UNDEFINED_NODE;
364
+ case 'string':
365
+ return createStringNode(current as string);
366
+ case 'number':
367
+ return createNumberNode(current as number);
495
368
  case 'bigint':
496
- assert(this.features & Feature.BigInt, new UnsupportedTypeError(current));
497
369
  return createBigIntNode(current as bigint);
498
370
  case 'object': {
499
- const id = this.getReference(current);
500
- return typeof id === 'number' ? this.parseObject(id, current as object) : id;
501
- }
502
- case 'symbol': {
503
- assert(this.features & Feature.Symbol, new UnsupportedTypeError(current));
504
- const id = this.getReference(current);
505
- return typeof id === 'number' ? createWKSymbolNode(id, current as WellKnownSymbols) : id;
371
+ if (current) {
372
+ const ref = this.getReference(current);
373
+ return ref.type === 0
374
+ ? this.parseObject(ref.value, current as object)
375
+ : ref.value;
376
+ }
377
+ return NULL_NODE;
506
378
  }
379
+ case 'symbol':
380
+ return this.parseWellKnownSymbol(current);
507
381
  case 'function':
508
- assert(hasReferenceID(current), new Error('Cannot serialize function without reference ID.'));
509
- return this.getStrictReference(current);
382
+ return this.parseFunction(current as (...args: unknown[]) => unknown);
510
383
  default:
511
384
  throw new UnsupportedTypeError(current);
512
385
  }