seroval 0.15.1 → 1.0.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 (114) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/development/index.cjs +1287 -1945
  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 +1288 -1946
  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 +26 -5
  26. package/dist/types/core/context/parser.d.ts.map +1 -1
  27. package/dist/types/core/context/serializer.d.ts +21 -30
  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 +110 -381
  76. package/src/core/context/parser/sync.ts +125 -266
  77. package/src/core/context/parser.ts +119 -68
  78. package/src/core/context/serializer.ts +396 -473
  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,11 @@ 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';
30
23
  import {
31
24
  FALSE_NODE,
32
25
  NULL_NODE,
@@ -36,7 +29,6 @@ import {
36
29
  import { iteratorToSequence } from '../../utils/iterator-to-sequence';
37
30
  import type { BaseParserContextOptions } from '../parser';
38
31
  import { BaseParserContext } from '../parser';
39
- import { hasReferenceID } from '../../reference';
40
32
  import { getErrorOptions } from '../../utils/error';
41
33
  import { serializeString } from '../../string';
42
34
  import type {
@@ -52,34 +44,25 @@ import type {
52
44
  SerovalSetNode,
53
45
  SerovalPluginNode,
54
46
  SerovalAggregateErrorNode,
55
- SerovalCustomEventNode,
56
- SerovalEventNode,
57
- SerovalHeadersNode,
58
- SerovalPlainRecordNode,
59
- SerovalFormDataNode,
60
47
  SerovalTypedArrayNode,
61
48
  SerovalBigIntTypedArrayNode,
62
49
  SerovalDataViewNode,
50
+ SerovalPromiseConstructorNode,
63
51
  } 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';
52
+ import { SpecialReference } from '../../special-reference';
53
+ import type { Stream } from '../../stream';
54
+ import { createStream, isStream } from '../../stream';
55
+ import type {
56
+ BigIntTypedArrayValue,
57
+ TypedArrayValue,
58
+ } from '../../utils/typed-array';
72
59
 
73
- type ObjectLikeNode =
74
- | SerovalObjectNode
75
- | SerovalNullConstructorNode;
60
+ type ObjectLikeNode = SerovalObjectNode | SerovalNullConstructorNode;
76
61
 
77
- export type BaseSyncParserContextOptions = BaseParserContextOptions
62
+ export type BaseSyncParserContextOptions = BaseParserContextOptions;
78
63
 
79
64
  export default abstract class BaseSyncParserContext extends BaseParserContext {
80
- protected parseItems(
81
- current: unknown[],
82
- ): SerovalNode[] {
65
+ protected parseItems(current: unknown[]): SerovalNode[] {
83
66
  const nodes = [];
84
67
  for (let i = 0, len = current.length; i < len; i++) {
85
68
  if (i in current) {
@@ -89,15 +72,8 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
89
72
  return nodes;
90
73
  }
91
74
 
92
- protected parseArray(
93
- id: number,
94
- current: unknown[],
95
- ): SerovalArrayNode {
96
- return createArrayNode(
97
- id,
98
- current,
99
- this.parseItems(current),
100
- );
75
+ protected parseArray(id: number, current: unknown[]): SerovalArrayNode {
76
+ return createArrayNode(id, current, this.parseItems(current));
101
77
  }
102
78
 
103
79
  protected parseProperties(
@@ -106,40 +82,42 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
106
82
  const entries = Object.entries(properties);
107
83
  const keyNodes: SerovalObjectRecordKey[] = [];
108
84
  const valueNodes: SerovalNode[] = [];
109
- for (
110
- let i = 0, len = entries.length;
111
- i < len;
112
- i++
113
- ) {
85
+ for (let i = 0, len = entries.length; i < len; i++) {
114
86
  keyNodes.push(serializeString(entries[i][0]));
115
87
  valueNodes.push(this.parse(entries[i][1]));
116
88
  }
117
89
  // 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
- ),
90
+ let symbol = Symbol.iterator;
91
+ if (symbol in properties) {
92
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
93
+ valueNodes.push(
94
+ createIteratorFactoryInstanceNode(
95
+ this.parseIteratorFactory(),
96
+ this.parse(
97
+ iteratorToSequence(properties as unknown as Iterable<unknown>),
130
98
  ),
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
- }
99
+ ),
100
+ );
101
+ }
102
+ symbol = Symbol.asyncIterator;
103
+ if (symbol in properties) {
104
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
105
+ valueNodes.push(
106
+ createAsyncIteratorFactoryInstanceNode(
107
+ this.parseAsyncIteratorFactory(),
108
+ this.parse(createStream()),
109
+ ),
110
+ );
111
+ }
112
+ symbol = Symbol.toStringTag;
113
+ if (symbol in properties) {
114
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
115
+ valueNodes.push(createStringNode(properties[symbol] as string));
116
+ }
117
+ symbol = Symbol.isConcatSpreadable;
118
+ if (symbol in properties) {
119
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
120
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
143
121
  }
144
122
  return {
145
123
  k: keyNodes,
@@ -161,10 +139,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
161
139
  );
162
140
  }
163
141
 
164
- protected parseBoxed(
165
- id: number,
166
- current: object,
167
- ): SerovalBoxedNode {
142
+ protected parseBoxed(id: number, current: object): SerovalBoxedNode {
168
143
  return createBoxedNode(id, this.parse(current.valueOf()));
169
144
  }
170
145
 
@@ -182,24 +157,16 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
182
157
  return createBigIntTypedArrayNode(id, current, this.parse(current.buffer));
183
158
  }
184
159
 
185
- protected parseDataView(
186
- id: number,
187
- current: DataView,
188
- ): SerovalDataViewNode {
160
+ protected parseDataView(id: number, current: DataView): SerovalDataViewNode {
189
161
  return createDataViewNode(id, current, this.parse(current.buffer));
190
162
  }
191
163
 
192
- protected parseError(
193
- id: number,
194
- current: Error,
195
- ): SerovalErrorNode {
164
+ protected parseError(id: number, current: Error): SerovalErrorNode {
196
165
  const options = getErrorOptions(current, this.features);
197
166
  return createErrorNode(
198
167
  id,
199
168
  current,
200
- options
201
- ? this.parseProperties(options)
202
- : undefined,
169
+ options ? this.parseProperties(options) : undefined,
203
170
  );
204
171
  }
205
172
 
@@ -211,9 +178,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
211
178
  return createAggregateErrorNode(
212
179
  id,
213
180
  current,
214
- options
215
- ? this.parseProperties(options)
216
- : undefined,
181
+ options ? this.parseProperties(options) : undefined,
217
182
  );
218
183
  }
219
184
 
@@ -227,18 +192,10 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
227
192
  keyNodes.push(this.parse(key));
228
193
  valueNodes.push(this.parse(value));
229
194
  }
230
- return this.createMapNode(
231
- id,
232
- keyNodes,
233
- valueNodes,
234
- current.size,
235
- );
195
+ return this.createMapNode(id, keyNodes, valueNodes, current.size);
236
196
  }
237
197
 
238
- protected parseSet(
239
- id: number,
240
- current: Set<unknown>,
241
- ): SerovalSetNode {
198
+ protected parseSet(id: number, current: Set<unknown>): SerovalSetNode {
242
199
  const items: SerovalNode[] = [];
243
200
  for (const item of current.keys()) {
244
201
  items.push(this.parse(item));
@@ -246,85 +203,6 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
246
203
  return createSetNode(id, current.size, items);
247
204
  }
248
205
 
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
206
  protected parsePlugin(
329
207
  id: number,
330
208
  current: unknown,
@@ -347,13 +225,32 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
347
225
  return undefined;
348
226
  }
349
227
 
350
- protected parseObject(
228
+ protected parseStream(id: number, _current: Stream<unknown>): SerovalNode {
229
+ return createStreamConstructorNode(
230
+ id,
231
+ this.parseSpecialReference(SpecialReference.StreamConstructor),
232
+ [],
233
+ );
234
+ }
235
+
236
+ protected parsePromise(
351
237
  id: number,
352
- current: object,
353
- ): SerovalNode {
238
+ _current: Promise<unknown>,
239
+ ): SerovalPromiseConstructorNode {
240
+ return this.createPromiseConstructorNode(id);
241
+ }
242
+
243
+ protected parseObject(id: number, current: object): SerovalNode {
354
244
  if (Array.isArray(current)) {
355
245
  return this.parseArray(id, current);
356
246
  }
247
+ if (isStream(current)) {
248
+ return this.parseStream(id, current);
249
+ }
250
+ const parsed = this.parsePlugin(id, current);
251
+ if (parsed) {
252
+ return parsed;
253
+ }
357
254
  const currentClass = current.constructor;
358
255
  switch (currentClass) {
359
256
  case Object:
@@ -385,83 +282,49 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
385
282
  case String:
386
283
  case BigInt:
387
284
  return this.parseBoxed(id, current);
285
+ case ArrayBuffer:
286
+ return createArrayBufferNode(id, current as unknown as ArrayBuffer);
287
+ case Int8Array:
288
+ case Int16Array:
289
+ case Int32Array:
290
+ case Uint8Array:
291
+ case Uint16Array:
292
+ case Uint32Array:
293
+ case Uint8ClampedArray:
294
+ case Float32Array:
295
+ case Float64Array:
296
+ return this.parseTypedArray(id, current as unknown as TypedArrayValue);
297
+ case DataView:
298
+ return this.parseDataView(id, current as unknown as DataView);
299
+ case Map:
300
+ return this.parseMap(id, current as unknown as Map<unknown, unknown>);
301
+ case Set:
302
+ return this.parseSet(id, current as unknown as Set<unknown>);
388
303
  default:
389
304
  break;
390
305
  }
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
- }
306
+ // Promises
307
+ if (currentClass === Promise || current instanceof Promise) {
308
+ return this.parsePromise(id, current as unknown as Promise<unknown>);
412
309
  }
310
+ const currentFeatures = this.features;
413
311
  // BigInt Typed Arrays
414
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
312
+ if (currentFeatures & Feature.BigIntTypedArray) {
415
313
  switch (currentClass) {
416
314
  case BigInt64Array:
417
315
  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);
316
+ return this.parseBigIntTypedArray(
317
+ id,
318
+ current as unknown as BigIntTypedArrayValue,
319
+ );
453
320
  default:
454
321
  break;
455
322
  }
456
323
  }
457
- const parsed = this.parsePlugin(id, current);
458
- if (parsed) {
459
- return parsed;
460
- }
461
324
  if (
462
- (currentFeatures & Feature.AggregateError)
463
- && typeof AggregateError !== 'undefined'
464
- && (currentClass === AggregateError || current instanceof AggregateError)
325
+ currentFeatures & Feature.AggregateError &&
326
+ typeof AggregateError !== 'undefined' &&
327
+ (currentClass === AggregateError || current instanceof AggregateError)
465
328
  ) {
466
329
  return this.parseAggregateError(id, current as unknown as AggregateError);
467
330
  }
@@ -472,41 +335,37 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
472
335
  }
473
336
  // Generator functions don't have a global constructor
474
337
  // despite existing
475
- if (
476
- currentFeatures & Feature.Symbol
477
- && Symbol.iterator in current
478
- ) {
338
+ if (Symbol.iterator in current || Symbol.asyncIterator in current) {
479
339
  return this.parsePlainObject(id, current, !!currentClass);
480
340
  }
481
341
  throw new UnsupportedTypeError(current);
482
342
  }
483
343
 
484
344
  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
345
  switch (typeof current) {
493
- case 'string': return createStringNode(current as string);
494
- case 'number': return createNumberNode(current as number);
346
+ case 'boolean':
347
+ return current ? TRUE_NODE : FALSE_NODE;
348
+ case 'undefined':
349
+ return UNDEFINED_NODE;
350
+ case 'string':
351
+ return createStringNode(current as string);
352
+ case 'number':
353
+ return createNumberNode(current as number);
495
354
  case 'bigint':
496
- assert(this.features & Feature.BigInt, new UnsupportedTypeError(current));
497
355
  return createBigIntNode(current as bigint);
498
356
  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;
357
+ if (current) {
358
+ const ref = this.getReference(current);
359
+ return ref.type === 0
360
+ ? this.parseObject(ref.value, current as object)
361
+ : ref.value;
362
+ }
363
+ return NULL_NODE;
506
364
  }
365
+ case 'symbol':
366
+ return this.parseWellKnownSymbol(current);
507
367
  case 'function':
508
- assert(hasReferenceID(current), new Error('Cannot serialize function without reference ID.'));
509
- return this.getStrictReference(current);
368
+ return this.parseFunction(current as (...args: unknown[]) => unknown);
510
369
  default:
511
370
  throw new UnsupportedTypeError(current);
512
371
  }