seroval 1.4.1 → 1.4.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 (50) hide show
  1. package/dist/cjs/development/index.cjs +54 -11
  2. package/dist/cjs/development/index.cjs.map +2 -2
  3. package/dist/cjs/production/index.cjs +2 -2
  4. package/dist/esm/development/index.mjs +54 -11
  5. package/dist/esm/development/index.mjs.map +2 -2
  6. package/dist/esm/production/index.mjs +2 -2
  7. package/dist/types/core/base-primitives.d.ts.map +1 -1
  8. package/dist/types/core/context/async-parser.d.ts.map +1 -1
  9. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  10. package/dist/types/core/context/parser.d.ts.map +1 -1
  11. package/dist/types/core/context/sync-parser.d.ts.map +1 -1
  12. package/dist/types/core/literals.d.ts.map +1 -1
  13. package/dist/types/core/node.d.ts +1 -1
  14. package/dist/types/core/node.d.ts.map +1 -1
  15. package/dist/types/core/types.d.ts +4 -0
  16. package/dist/types/core/types.d.ts.map +1 -1
  17. package/package.json +3 -2
  18. package/src/core/Serializer.ts +119 -0
  19. package/src/core/base-primitives.ts +514 -0
  20. package/src/core/compat.ts +23 -0
  21. package/src/core/constants.ts +201 -0
  22. package/src/core/constructors.ts +270 -0
  23. package/src/core/context/async-parser.ts +638 -0
  24. package/src/core/context/deserializer.ts +810 -0
  25. package/src/core/context/parser.ts +335 -0
  26. package/src/core/context/serializer.ts +1406 -0
  27. package/src/core/context/sync-parser.ts +907 -0
  28. package/src/core/cross/index.ts +188 -0
  29. package/src/core/errors.ts +196 -0
  30. package/src/core/function-string.ts +32 -0
  31. package/src/core/keys.ts +17 -0
  32. package/src/core/literals.ts +43 -0
  33. package/src/core/node.ts +40 -0
  34. package/src/core/opaque-reference.ts +9 -0
  35. package/src/core/plugin.ts +100 -0
  36. package/src/core/reference.ts +66 -0
  37. package/src/core/special-reference.ts +42 -0
  38. package/src/core/stream.ts +71 -0
  39. package/src/core/string.ts +86 -0
  40. package/src/core/symbols.ts +18 -0
  41. package/src/core/tree/index.ts +134 -0
  42. package/src/core/types.ts +366 -0
  43. package/src/core/utils/error.ts +73 -0
  44. package/src/core/utils/get-identifier.ts +18 -0
  45. package/src/core/utils/get-object-flag.ts +14 -0
  46. package/src/core/utils/is-valid-identifier.ts +12 -0
  47. package/src/core/utils/iterator-to-sequence.ts +44 -0
  48. package/src/core/utils/promise-to-result.ts +9 -0
  49. package/src/core/utils/typed-array.ts +56 -0
  50. package/src/index.ts +36 -0
@@ -0,0 +1,514 @@
1
+ import type { WellKnownSymbols } from './constants';
2
+ import { INV_SYMBOL_REF, NIL, SerovalNodeType } from './constants';
3
+ import {
4
+ INFINITY_NODE,
5
+ NAN_NODE,
6
+ NEG_INFINITY_NODE,
7
+ NEG_ZERO_NODE,
8
+ } from './literals';
9
+ import { createSerovalNode } from './node';
10
+ import { getReferenceID } from './reference';
11
+ import { serializeString } from './string';
12
+ import type {
13
+ SerovalAggregateErrorNode,
14
+ SerovalArrayNode,
15
+ SerovalAsyncIteratorFactoryInstanceNode,
16
+ SerovalBigIntNode,
17
+ SerovalBigIntTypedArrayNode,
18
+ SerovalBoxedNode,
19
+ SerovalConstantNode,
20
+ SerovalDataViewNode,
21
+ SerovalDateNode,
22
+ SerovalErrorNode,
23
+ SerovalIndexedValueNode,
24
+ SerovalIteratorFactoryInstanceNode,
25
+ SerovalNode,
26
+ SerovalNodeWithID,
27
+ SerovalNumberNode,
28
+ SerovalObjectRecordNode,
29
+ SerovalPluginNode,
30
+ SerovalReferenceNode,
31
+ SerovalRegExpNode,
32
+ SerovalSetNode,
33
+ SerovalStreamConstructorNode,
34
+ SerovalStreamNextNode,
35
+ SerovalStreamReturnNode,
36
+ SerovalStreamThrowNode,
37
+ SerovalStringNode,
38
+ SerovalTypedArrayNode,
39
+ SerovalWKSymbolNode,
40
+ } from './types';
41
+ import { getErrorConstructor } from './utils/error';
42
+ import { getObjectFlag } from './utils/get-object-flag';
43
+ import type {
44
+ BigIntTypedArrayValue,
45
+ TypedArrayValue,
46
+ } from './utils/typed-array';
47
+
48
+ export function createNumberNode(
49
+ value: number,
50
+ ): SerovalConstantNode | SerovalNumberNode {
51
+ switch (value) {
52
+ case Number.POSITIVE_INFINITY:
53
+ return INFINITY_NODE;
54
+ case Number.NEGATIVE_INFINITY:
55
+ return NEG_INFINITY_NODE;
56
+ }
57
+ if (value !== value) {
58
+ return NAN_NODE;
59
+ }
60
+ if (Object.is(value, -0)) {
61
+ return NEG_ZERO_NODE;
62
+ }
63
+ return createSerovalNode(
64
+ SerovalNodeType.Number,
65
+ NIL,
66
+ value,
67
+ NIL,
68
+ NIL,
69
+ NIL,
70
+ NIL,
71
+ NIL,
72
+ NIL,
73
+ NIL,
74
+ NIL,
75
+ NIL,
76
+ );
77
+ }
78
+
79
+ export function createStringNode(value: string): SerovalStringNode {
80
+ return createSerovalNode(
81
+ SerovalNodeType.String,
82
+ NIL,
83
+ serializeString(value),
84
+ NIL,
85
+ NIL,
86
+ NIL,
87
+ NIL,
88
+ NIL,
89
+ NIL,
90
+ NIL,
91
+ NIL,
92
+ NIL,
93
+ );
94
+ }
95
+
96
+ export function createBigIntNode(current: bigint): SerovalBigIntNode {
97
+ return createSerovalNode(
98
+ SerovalNodeType.BigInt,
99
+ NIL,
100
+ '' + current,
101
+ NIL,
102
+ NIL,
103
+ NIL,
104
+ NIL,
105
+ NIL,
106
+ NIL,
107
+ NIL,
108
+ NIL,
109
+ NIL,
110
+ );
111
+ }
112
+
113
+ export function createIndexedValueNode(id: number): SerovalIndexedValueNode {
114
+ return createSerovalNode(
115
+ SerovalNodeType.IndexedValue,
116
+ id,
117
+ NIL,
118
+ NIL,
119
+ NIL,
120
+ NIL,
121
+ NIL,
122
+ NIL,
123
+ NIL,
124
+ NIL,
125
+ NIL,
126
+ NIL,
127
+ );
128
+ }
129
+
130
+ export function createDateNode(id: number, current: Date): SerovalDateNode {
131
+ const timestamp = current.valueOf();
132
+ return createSerovalNode(
133
+ SerovalNodeType.Date,
134
+ id,
135
+ timestamp !== timestamp ? '' : current.toISOString(),
136
+ NIL,
137
+ NIL,
138
+ NIL,
139
+ NIL,
140
+ NIL,
141
+ NIL,
142
+ NIL,
143
+ NIL,
144
+ NIL,
145
+ );
146
+ }
147
+
148
+ export function createRegExpNode(
149
+ id: number,
150
+ current: RegExp,
151
+ ): SerovalRegExpNode {
152
+ return createSerovalNode(
153
+ SerovalNodeType.RegExp,
154
+ id,
155
+ NIL,
156
+ serializeString(current.source),
157
+ current.flags,
158
+ NIL,
159
+ NIL,
160
+ NIL,
161
+ NIL,
162
+ NIL,
163
+ NIL,
164
+ NIL,
165
+ );
166
+ }
167
+
168
+ export function createWKSymbolNode(
169
+ id: number,
170
+ current: WellKnownSymbols,
171
+ ): SerovalWKSymbolNode {
172
+ return createSerovalNode(
173
+ SerovalNodeType.WKSymbol,
174
+ id,
175
+ INV_SYMBOL_REF[current],
176
+ NIL,
177
+ NIL,
178
+ NIL,
179
+ NIL,
180
+ NIL,
181
+ NIL,
182
+ NIL,
183
+ NIL,
184
+ NIL,
185
+ );
186
+ }
187
+
188
+ export function createReferenceNode<T>(
189
+ id: number,
190
+ ref: T,
191
+ ): SerovalReferenceNode {
192
+ return createSerovalNode(
193
+ SerovalNodeType.Reference,
194
+ id,
195
+ serializeString(getReferenceID(ref)),
196
+ NIL,
197
+ NIL,
198
+ NIL,
199
+ NIL,
200
+ NIL,
201
+ NIL,
202
+ NIL,
203
+ NIL,
204
+ NIL,
205
+ );
206
+ }
207
+
208
+ export function createPluginNode(
209
+ id: number,
210
+ tag: string,
211
+ value: unknown,
212
+ ): SerovalPluginNode {
213
+ return createSerovalNode(
214
+ SerovalNodeType.Plugin,
215
+ id,
216
+ value,
217
+ serializeString(tag),
218
+ NIL,
219
+ NIL,
220
+ NIL,
221
+ NIL,
222
+ NIL,
223
+ NIL,
224
+ NIL,
225
+ NIL,
226
+ );
227
+ }
228
+
229
+ export function createArrayNode(
230
+ id: number,
231
+ current: unknown[],
232
+ parsedItems: SerovalArrayNode['a'],
233
+ ): SerovalArrayNode {
234
+ return createSerovalNode(
235
+ SerovalNodeType.Array,
236
+ id,
237
+ NIL,
238
+ NIL,
239
+ NIL,
240
+ NIL,
241
+ NIL,
242
+ parsedItems,
243
+ NIL,
244
+ NIL,
245
+ getObjectFlag(current),
246
+ NIL,
247
+ );
248
+ }
249
+
250
+ export function createBoxedNode(
251
+ id: number,
252
+ boxed: SerovalNode,
253
+ ): SerovalBoxedNode {
254
+ return createSerovalNode(
255
+ SerovalNodeType.Boxed,
256
+ id,
257
+ NIL,
258
+ NIL,
259
+ NIL,
260
+ NIL,
261
+ NIL,
262
+ NIL,
263
+ boxed,
264
+ NIL,
265
+ NIL,
266
+ NIL,
267
+ );
268
+ }
269
+
270
+ export function createTypedArrayNode(
271
+ id: number,
272
+ current: TypedArrayValue,
273
+ buffer: SerovalNode,
274
+ ): SerovalTypedArrayNode {
275
+ return createSerovalNode(
276
+ SerovalNodeType.TypedArray,
277
+ id,
278
+ NIL,
279
+ current.constructor.name,
280
+ NIL,
281
+ NIL,
282
+ NIL,
283
+ NIL,
284
+ buffer,
285
+ current.byteOffset,
286
+ NIL,
287
+ current.length,
288
+ );
289
+ }
290
+
291
+ export function createBigIntTypedArrayNode(
292
+ id: number,
293
+ current: BigIntTypedArrayValue,
294
+ buffer: SerovalNode,
295
+ ): SerovalBigIntTypedArrayNode {
296
+ return createSerovalNode(
297
+ SerovalNodeType.BigIntTypedArray,
298
+ id,
299
+ NIL,
300
+ current.constructor.name,
301
+ NIL,
302
+ NIL,
303
+ NIL,
304
+ NIL,
305
+ buffer,
306
+ current.byteOffset,
307
+ NIL,
308
+ current.byteLength,
309
+ );
310
+ }
311
+
312
+ export function createDataViewNode(
313
+ id: number,
314
+ current: DataView,
315
+ buffer: SerovalNode,
316
+ ): SerovalDataViewNode {
317
+ return createSerovalNode(
318
+ SerovalNodeType.DataView,
319
+ id,
320
+ NIL,
321
+ NIL,
322
+ NIL,
323
+ NIL,
324
+ NIL,
325
+ NIL,
326
+ buffer,
327
+ current.byteOffset,
328
+ NIL,
329
+ current.byteLength,
330
+ );
331
+ }
332
+
333
+ export function createErrorNode(
334
+ id: number,
335
+ current: Error,
336
+ options: SerovalObjectRecordNode | undefined,
337
+ ): SerovalErrorNode {
338
+ return createSerovalNode(
339
+ SerovalNodeType.Error,
340
+ id,
341
+ getErrorConstructor(current),
342
+ NIL,
343
+ serializeString(current.message),
344
+ options,
345
+ NIL,
346
+ NIL,
347
+ NIL,
348
+ NIL,
349
+ NIL,
350
+ NIL,
351
+ );
352
+ }
353
+
354
+ export function createAggregateErrorNode(
355
+ id: number,
356
+ current: AggregateError,
357
+ options: SerovalObjectRecordNode | undefined,
358
+ ): SerovalAggregateErrorNode {
359
+ return createSerovalNode(
360
+ SerovalNodeType.AggregateError,
361
+ id,
362
+ getErrorConstructor(current),
363
+ NIL,
364
+ serializeString(current.message),
365
+ options,
366
+ NIL,
367
+ NIL,
368
+ NIL,
369
+ NIL,
370
+ NIL,
371
+ NIL,
372
+ );
373
+ }
374
+
375
+ export function createSetNode(
376
+ id: number,
377
+ items: SerovalNode[],
378
+ ): SerovalSetNode {
379
+ return createSerovalNode(
380
+ SerovalNodeType.Set,
381
+ id,
382
+ NIL,
383
+ NIL,
384
+ NIL,
385
+ NIL,
386
+ NIL,
387
+ items,
388
+ NIL,
389
+ NIL,
390
+ NIL,
391
+ NIL,
392
+ );
393
+ }
394
+
395
+ export function createIteratorFactoryInstanceNode(
396
+ factory: SerovalNodeWithID,
397
+ items: SerovalNode,
398
+ ): SerovalIteratorFactoryInstanceNode {
399
+ return createSerovalNode(
400
+ SerovalNodeType.IteratorFactoryInstance,
401
+ NIL,
402
+ NIL,
403
+ NIL,
404
+ NIL,
405
+ NIL,
406
+ NIL,
407
+ [factory, items],
408
+ NIL,
409
+ NIL,
410
+ NIL,
411
+ NIL,
412
+ );
413
+ }
414
+
415
+ export function createAsyncIteratorFactoryInstanceNode(
416
+ factory: SerovalNodeWithID,
417
+ items: SerovalNode,
418
+ ): SerovalAsyncIteratorFactoryInstanceNode {
419
+ return createSerovalNode(
420
+ SerovalNodeType.AsyncIteratorFactoryInstance,
421
+ NIL,
422
+ NIL,
423
+ NIL,
424
+ NIL,
425
+ NIL,
426
+ NIL,
427
+ [factory, items],
428
+ NIL,
429
+ NIL,
430
+ NIL,
431
+ NIL,
432
+ );
433
+ }
434
+
435
+ export function createStreamConstructorNode(
436
+ id: number,
437
+ factory: SerovalNodeWithID,
438
+ sequence: SerovalNode[],
439
+ ): SerovalStreamConstructorNode {
440
+ return createSerovalNode(
441
+ SerovalNodeType.StreamConstructor,
442
+ id,
443
+ NIL,
444
+ NIL,
445
+ NIL,
446
+ NIL,
447
+ NIL,
448
+ sequence,
449
+ factory,
450
+ NIL,
451
+ NIL,
452
+ NIL,
453
+ );
454
+ }
455
+
456
+ export function createStreamNextNode(
457
+ id: number,
458
+ parsed: SerovalNode,
459
+ ): SerovalStreamNextNode {
460
+ return createSerovalNode(
461
+ SerovalNodeType.StreamNext,
462
+ id,
463
+ NIL,
464
+ NIL,
465
+ NIL,
466
+ NIL,
467
+ NIL,
468
+ NIL,
469
+ parsed,
470
+ NIL,
471
+ NIL,
472
+ NIL,
473
+ );
474
+ }
475
+
476
+ export function createStreamThrowNode(
477
+ id: number,
478
+ parsed: SerovalNode,
479
+ ): SerovalStreamThrowNode {
480
+ return createSerovalNode(
481
+ SerovalNodeType.StreamThrow,
482
+ id,
483
+ NIL,
484
+ NIL,
485
+ NIL,
486
+ NIL,
487
+ NIL,
488
+ NIL,
489
+ parsed,
490
+ NIL,
491
+ NIL,
492
+ NIL,
493
+ );
494
+ }
495
+
496
+ export function createStreamReturnNode(
497
+ id: number,
498
+ parsed: SerovalNode,
499
+ ): SerovalStreamReturnNode {
500
+ return createSerovalNode(
501
+ SerovalNodeType.StreamReturn,
502
+ id,
503
+ NIL,
504
+ NIL,
505
+ NIL,
506
+ NIL,
507
+ NIL,
508
+ NIL,
509
+ parsed,
510
+ NIL,
511
+ NIL,
512
+ NIL,
513
+ );
514
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * References
3
+ * - https://compat-table.github.io/compat-table/es6/
4
+ * - MDN
5
+ */
6
+
7
+ export enum Feature {
8
+ AggregateError = 0x01,
9
+ // @deprecated
10
+ ArrowFunction = 0x02,
11
+ ErrorPrototypeStack = 0x04,
12
+ ObjectAssign = 0x08,
13
+ BigIntTypedArray = 0x10,
14
+ RegExp = 0x20,
15
+ }
16
+
17
+ export const ALL_ENABLED =
18
+ Feature.AggregateError |
19
+ Feature.ArrowFunction |
20
+ Feature.ErrorPrototypeStack |
21
+ Feature.ObjectAssign |
22
+ Feature.BigIntTypedArray |
23
+ Feature.RegExp;
@@ -0,0 +1,201 @@
1
+ import {
2
+ SYM_ASYNC_ITERATOR,
3
+ SYM_HAS_INSTANCE,
4
+ SYM_IS_CONCAT_SPREADABLE,
5
+ SYM_ITERATOR,
6
+ SYM_MATCH,
7
+ SYM_MATCH_ALL,
8
+ SYM_REPLACE,
9
+ SYM_SEARCH,
10
+ SYM_SPECIES,
11
+ SYM_SPLIT,
12
+ SYM_TO_PRIMITIVE,
13
+ SYM_TO_STRING_TAG,
14
+ SYM_UNSCOPABLES,
15
+ } from './symbols';
16
+
17
+ export const enum SerovalConstant {
18
+ Null = 0,
19
+ Undefined = 1,
20
+ True = 2,
21
+ False = 3,
22
+ NegZero = 4,
23
+ Inf = 5,
24
+ NegInf = 6,
25
+ Nan = 7,
26
+ }
27
+
28
+ export const enum SerovalNodeType {
29
+ Number = 0,
30
+ String = 1,
31
+ Constant = 2,
32
+ BigInt = 3,
33
+ IndexedValue = 4,
34
+ Date = 5,
35
+ RegExp = 6,
36
+ Set = 7,
37
+ Map = 8,
38
+ Array = 9,
39
+ Object = 10,
40
+ NullConstructor = 11,
41
+ Promise = 12,
42
+ Error = 13,
43
+ AggregateError = 14,
44
+ TypedArray = 15,
45
+ BigIntTypedArray = 16,
46
+ WKSymbol = 17,
47
+ Reference = 18,
48
+ ArrayBuffer = 19,
49
+ DataView = 20,
50
+ Boxed = 21,
51
+ PromiseConstructor = 22,
52
+ PromiseSuccess = 23,
53
+ PromiseFailure = 24,
54
+ Plugin = 25,
55
+ SpecialReference = 26,
56
+ IteratorFactory = 27,
57
+ IteratorFactoryInstance = 28,
58
+ AsyncIteratorFactory = 29,
59
+ AsyncIteratorFactoryInstance = 30,
60
+ StreamConstructor = 31,
61
+ StreamNext = 32,
62
+ StreamThrow = 33,
63
+ StreamReturn = 34,
64
+ }
65
+
66
+ export const enum SerovalObjectFlags {
67
+ None = 0,
68
+ NonExtensible = 1,
69
+ Sealed = 2,
70
+ Frozen = 3,
71
+ }
72
+
73
+ export const enum Symbols {
74
+ AsyncIterator = 0,
75
+ HasInstance = 1,
76
+ IsConcatSpreadable = 2,
77
+ Iterator = 3,
78
+ Match = 4,
79
+ MatchAll = 5,
80
+ Replace = 6,
81
+ Search = 7,
82
+ Species = 8,
83
+ Split = 9,
84
+ ToPrimitive = 10,
85
+ ToStringTag = 11,
86
+ Unscopables = 12,
87
+ }
88
+
89
+ export const SYMBOL_STRING: Record<Symbols, string> = {
90
+ [Symbols.AsyncIterator]: 'Symbol.asyncIterator',
91
+ [Symbols.HasInstance]: 'Symbol.hasInstance',
92
+ [Symbols.IsConcatSpreadable]: 'Symbol.isConcatSpreadable',
93
+ [Symbols.Iterator]: 'Symbol.iterator',
94
+ [Symbols.Match]: 'Symbol.match',
95
+ [Symbols.MatchAll]: 'Symbol.matchAll',
96
+ [Symbols.Replace]: 'Symbol.replace',
97
+ [Symbols.Search]: 'Symbol.search',
98
+ [Symbols.Species]: 'Symbol.species',
99
+ [Symbols.Split]: 'Symbol.split',
100
+ [Symbols.ToPrimitive]: 'Symbol.toPrimitive',
101
+ [Symbols.ToStringTag]: 'Symbol.toStringTag',
102
+ [Symbols.Unscopables]: 'Symbol.unscopables',
103
+ };
104
+
105
+ export const INV_SYMBOL_REF = /* @__PURE__ */ {
106
+ [SYM_ASYNC_ITERATOR]: Symbols.AsyncIterator,
107
+ [SYM_HAS_INSTANCE]: Symbols.HasInstance,
108
+ [SYM_IS_CONCAT_SPREADABLE]: Symbols.IsConcatSpreadable,
109
+ [SYM_ITERATOR]: Symbols.Iterator,
110
+ [SYM_MATCH]: Symbols.Match,
111
+ [SYM_MATCH_ALL]: Symbols.MatchAll,
112
+ [SYM_REPLACE]: Symbols.Replace,
113
+ [SYM_SEARCH]: Symbols.Search,
114
+ [SYM_SPECIES]: Symbols.Species,
115
+ [SYM_SPLIT]: Symbols.Split,
116
+ [SYM_TO_PRIMITIVE]: Symbols.ToPrimitive,
117
+ [SYM_TO_STRING_TAG]: Symbols.ToStringTag,
118
+ [SYM_UNSCOPABLES]: Symbols.Unscopables,
119
+ };
120
+
121
+ export type WellKnownSymbols = keyof typeof INV_SYMBOL_REF;
122
+
123
+ export const SYMBOL_REF: Record<Symbols, WellKnownSymbols> = {
124
+ [Symbols.AsyncIterator]: SYM_ASYNC_ITERATOR,
125
+ [Symbols.HasInstance]: SYM_HAS_INSTANCE,
126
+ [Symbols.IsConcatSpreadable]: SYM_IS_CONCAT_SPREADABLE,
127
+ [Symbols.Iterator]: SYM_ITERATOR,
128
+ [Symbols.Match]: SYM_MATCH,
129
+ [Symbols.MatchAll]: SYM_MATCH_ALL,
130
+ [Symbols.Replace]: SYM_REPLACE,
131
+ [Symbols.Search]: SYM_SEARCH,
132
+ [Symbols.Species]: SYM_SPECIES,
133
+ [Symbols.Split]: SYM_SPLIT,
134
+ [Symbols.ToPrimitive]: SYM_TO_PRIMITIVE,
135
+ [Symbols.ToStringTag]: SYM_TO_STRING_TAG,
136
+ [Symbols.Unscopables]: SYM_UNSCOPABLES,
137
+ };
138
+
139
+ export const CONSTANT_STRING: Record<SerovalConstant, string> = {
140
+ [SerovalConstant.True]: '!0',
141
+ [SerovalConstant.False]: '!1',
142
+ [SerovalConstant.Undefined]: 'void 0',
143
+ [SerovalConstant.Null]: 'null',
144
+ [SerovalConstant.NegZero]: '-0',
145
+ [SerovalConstant.Inf]: '1/0',
146
+ [SerovalConstant.NegInf]: '-1/0',
147
+ [SerovalConstant.Nan]: '0/0',
148
+ };
149
+
150
+ export const NIL = void 0;
151
+
152
+ export const CONSTANT_VAL: Record<SerovalConstant, unknown> = {
153
+ [SerovalConstant.True]: true,
154
+ [SerovalConstant.False]: false,
155
+ [SerovalConstant.Undefined]: NIL,
156
+ [SerovalConstant.Null]: null,
157
+ [SerovalConstant.NegZero]: -0,
158
+ [SerovalConstant.Inf]: Number.POSITIVE_INFINITY,
159
+ [SerovalConstant.NegInf]: Number.NEGATIVE_INFINITY,
160
+ [SerovalConstant.Nan]: Number.NaN,
161
+ };
162
+
163
+ export const enum ErrorConstructorTag {
164
+ Error = 0,
165
+ EvalError = 1,
166
+ RangeError = 2,
167
+ ReferenceError = 3,
168
+ SyntaxError = 4,
169
+ TypeError = 5,
170
+ URIError = 6,
171
+ }
172
+
173
+ export const ERROR_CONSTRUCTOR_STRING: Record<ErrorConstructorTag, string> = {
174
+ [ErrorConstructorTag.Error]: 'Error',
175
+ [ErrorConstructorTag.EvalError]: 'EvalError',
176
+ [ErrorConstructorTag.RangeError]: 'RangeError',
177
+ [ErrorConstructorTag.ReferenceError]: 'ReferenceError',
178
+ [ErrorConstructorTag.SyntaxError]: 'SyntaxError',
179
+ [ErrorConstructorTag.TypeError]: 'TypeError',
180
+ [ErrorConstructorTag.URIError]: 'URIError',
181
+ };
182
+
183
+ type ErrorConstructors =
184
+ | ErrorConstructor
185
+ | EvalErrorConstructor
186
+ | RangeErrorConstructor
187
+ | ReferenceErrorConstructor
188
+ | SyntaxErrorConstructor
189
+ | TypeErrorConstructor
190
+ | URIErrorConstructor;
191
+
192
+ export const ERROR_CONSTRUCTOR: Record<ErrorConstructorTag, ErrorConstructors> =
193
+ {
194
+ [ErrorConstructorTag.Error]: Error,
195
+ [ErrorConstructorTag.EvalError]: EvalError,
196
+ [ErrorConstructorTag.RangeError]: RangeError,
197
+ [ErrorConstructorTag.ReferenceError]: ReferenceError,
198
+ [ErrorConstructorTag.SyntaxError]: SyntaxError,
199
+ [ErrorConstructorTag.TypeError]: TypeError,
200
+ [ErrorConstructorTag.URIError]: URIError,
201
+ };