seroval 0.9.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +4 -287
  2. package/dist/cjs/development/index.cjs +3529 -1140
  3. package/dist/cjs/development/index.cjs.map +4 -4
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +3533 -1142
  6. package/dist/esm/development/index.mjs.map +4 -4
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +15 -0
  9. package/dist/types/{tree → core}/UnsupportedTypeError.d.ts +4 -3
  10. package/dist/types/{assert.d.ts → core/assert.d.ts} +1 -1
  11. package/dist/types/core/assignments.d.ts +33 -0
  12. package/dist/types/core/base-primitives.d.ts +12 -0
  13. package/dist/types/{compat.d.ts → core/compat.d.ts} +22 -22
  14. package/dist/types/core/constants.d.ts +89 -0
  15. package/dist/types/core/context.d.ts +9 -0
  16. package/dist/types/core/cross/async.d.ts +3 -0
  17. package/dist/types/core/cross/context.d.ts +37 -0
  18. package/dist/types/core/cross/index.d.ts +8 -0
  19. package/dist/types/core/cross/primitives.d.ts +9 -0
  20. package/dist/types/core/cross/serialize.d.ts +5 -0
  21. package/dist/types/core/cross/stream.d.ts +3 -0
  22. package/dist/types/core/cross/sync.d.ts +3 -0
  23. package/dist/types/core/cross/web-api.d.ts +4 -0
  24. package/dist/types/{get-identifier.d.ts → core/get-identifier.d.ts} +1 -1
  25. package/dist/types/core/keys.d.ts +13 -0
  26. package/dist/types/{tree/constants.d.ts → core/literals.d.ts} +9 -11
  27. package/dist/types/core/promise-to-result.d.ts +1 -0
  28. package/dist/types/{tree → core}/reference.d.ts +5 -6
  29. package/dist/types/{tree → core}/shared.d.ts +13 -13
  30. package/dist/types/{string.d.ts → core/string.d.ts} +3 -3
  31. package/dist/types/core/tree/async.d.ts +3 -0
  32. package/dist/types/core/tree/context.d.ts +44 -0
  33. package/dist/types/core/tree/deserialize.d.ts +3 -0
  34. package/dist/types/core/tree/index.d.ts +14 -0
  35. package/dist/types/core/tree/primitives.d.ts +9 -0
  36. package/dist/types/core/tree/serialize.d.ts +4 -0
  37. package/dist/types/core/tree/sync.d.ts +3 -0
  38. package/dist/types/core/tree/web-api.d.ts +4 -0
  39. package/dist/types/{tree → core}/types.d.ts +228 -238
  40. package/dist/types/core/web-api.d.ts +4 -0
  41. package/dist/types/index.d.ts +9 -19
  42. package/dist/types/types.d.ts +20 -20
  43. package/package.json +5 -5
  44. package/src/core/Serializer.ts +48 -0
  45. package/src/{tree → core}/UnsupportedTypeError.ts +1 -1
  46. package/src/core/assignments.ts +159 -0
  47. package/src/{tree/primitives.ts → core/base-primitives.ts} +33 -136
  48. package/src/core/constants.ts +169 -0
  49. package/src/core/context.ts +15 -0
  50. package/src/core/cross/async.ts +614 -0
  51. package/src/core/cross/context.ts +102 -0
  52. package/src/core/cross/index.ts +169 -0
  53. package/src/core/cross/primitives.ts +137 -0
  54. package/src/core/cross/serialize.ts +847 -0
  55. package/src/core/cross/stream.ts +745 -0
  56. package/src/core/cross/sync.ts +561 -0
  57. package/src/core/cross/web-api.ts +55 -0
  58. package/src/core/header.js +61 -0
  59. package/src/core/keys.ts +41 -0
  60. package/src/core/literals.ts +28 -0
  61. package/src/core/promise-to-result.ts +9 -0
  62. package/src/{tree → core}/reference.ts +6 -7
  63. package/src/{tree → core}/shared.ts +4 -4
  64. package/src/{tree → core/tree}/async.ts +46 -34
  65. package/src/core/tree/context.ts +125 -0
  66. package/src/{tree → core/tree}/deserialize.ts +68 -55
  67. package/src/core/tree/index.ts +142 -0
  68. package/src/core/tree/primitives.ts +132 -0
  69. package/src/{tree → core/tree}/serialize.ts +87 -193
  70. package/src/{tree → core/tree}/sync.ts +50 -39
  71. package/src/{tree → core/tree}/web-api.ts +8 -52
  72. package/src/{tree → core}/types.ts +76 -60
  73. package/src/core/web-api.ts +51 -0
  74. package/src/index.ts +7 -141
  75. package/src/types.ts +1 -1
  76. package/dist/types/context.d.ts +0 -67
  77. package/dist/types/tree/async.d.ts +0 -3
  78. package/dist/types/tree/deserialize.d.ts +0 -3
  79. package/dist/types/tree/primitives.d.ts +0 -19
  80. package/dist/types/tree/serialize.d.ts +0 -4
  81. package/dist/types/tree/symbols.d.ts +0 -33
  82. package/dist/types/tree/sync.d.ts +0 -3
  83. package/dist/types/tree/web-api.d.ts +0 -6
  84. package/src/context.ts +0 -164
  85. package/src/tree/constants.ts +0 -73
  86. package/src/tree/symbols.ts +0 -65
  87. /package/src/{assert.ts → core/assert.ts} +0 -0
  88. /package/src/{compat.ts → core/compat.ts} +0 -0
  89. /package/src/{get-identifier.ts → core/get-identifier.ts} +0 -0
  90. /package/src/{string.ts → core/string.ts} +0 -0
package/src/index.ts CHANGED
@@ -1,21 +1,4 @@
1
- /* eslint-disable no-await-in-loop */
2
- import { Feature } from './compat';
3
- import type {
4
- SerializationContext,
5
- Options,
6
- } from './context';
7
- import {
8
- getRefParam,
9
- createParserContext,
10
- createSerializationContext,
11
- getRootID,
12
- } from './context';
13
- import parseSync from './tree/sync';
14
- import parseAsync from './tree/async';
15
- import deserializeTree from './tree/deserialize';
16
- import serializeTree, { resolvePatches } from './tree/serialize';
17
- import type { SerovalNode } from './tree/types';
18
- import { SerovalNodeType } from './tree/types';
1
+ import { serialize } from './core/tree';
19
2
 
20
3
  export type {
21
4
  AsyncServerValue,
@@ -25,131 +8,14 @@ export type {
25
8
  SemiPrimitiveValue,
26
9
  ErrorValue,
27
10
  } from './types';
28
- export { Feature } from './compat';
11
+ export { Feature } from './core/compat';
12
+ export { createReference } from './core/reference';
29
13
 
30
- function finalize(
31
- ctx: SerializationContext,
32
- rootID: number,
33
- isObject: boolean,
34
- result: string,
35
- ): string {
36
- // Shared references detected
37
- if (ctx.vars.length) {
38
- const patches = resolvePatches(ctx);
39
- let body = result;
40
- if (patches) {
41
- // Get (or create) a ref from the source
42
- const index = getRefParam(ctx, rootID);
43
- body = result + ',' + patches + index;
44
- if (!result.startsWith(index + '=')) {
45
- body = index + '=' + body;
46
- }
47
- }
48
- let params = ctx.vars.length > 1
49
- ? ctx.vars.join(',')
50
- : ctx.vars[0];
51
- // Source is probably already assigned
52
- if (ctx.features & Feature.ArrowFunction) {
53
- params = ctx.vars.length > 1 || ctx.vars.length === 0
54
- ? '(' + params + ')'
55
- : params;
56
- return '(' + params + '=>(' + body + '))()';
57
- }
58
- return '(function(' + params + '){return ' + body + '})()';
59
- }
60
- if (isObject) {
61
- return '(' + result + ')';
62
- }
63
- return result;
64
- }
14
+ export * from './core/tree';
15
+ export * from './core/cross';
65
16
 
66
- export function serialize<T>(
67
- source: T,
68
- options?: Partial<Options>,
69
- ): string {
70
- const ctx = createParserContext(options);
71
- const tree = parseSync(ctx, source);
72
- const serial = createSerializationContext(ctx);
73
- const result = serializeTree(serial, tree);
74
- return finalize(
75
- serial,
76
- getRootID(ctx, source),
77
- tree.t === SerovalNodeType.Object,
78
- result,
79
- );
80
- }
17
+ export { GLOBAL_CONTEXT_API_SCRIPT, getCrossReferenceHeader } from './core/keys';
81
18
 
82
- export async function serializeAsync<T>(
83
- source: T,
84
- options?: Partial<Options>,
85
- ): Promise<string> {
86
- const ctx = createParserContext(options);
87
- const tree = await parseAsync(ctx, source);
88
- const serial = createSerializationContext(ctx);
89
- const result = serializeTree(serial, tree);
90
- return finalize(
91
- serial,
92
- getRootID(ctx, source),
93
- tree.t === SerovalNodeType.Object,
94
- result,
95
- );
96
- }
97
-
98
- export function deserialize<T>(source: string): T {
99
- // eslint-disable-next-line no-eval
100
- return (0, eval)(source) as T;
101
- }
102
-
103
- export interface SerovalJSON {
104
- t: SerovalNode;
105
- r: number;
106
- f: number;
107
- m: number[];
108
- }
109
-
110
- export function toJSON<T>(
111
- source: T,
112
- options?: Partial<Options>,
113
- ): SerovalJSON {
114
- const ctx = createParserContext(options);
115
- return {
116
- t: parseSync(ctx, source),
117
- r: getRootID(ctx, source),
118
- f: ctx.features,
119
- m: Array.from(ctx.markedRefs),
120
- };
121
- }
122
-
123
- export async function toJSONAsync<T>(
124
- source: T,
125
- options?: Partial<Options>,
126
- ): Promise<SerovalJSON> {
127
- const ctx = createParserContext(options);
128
- return {
129
- t: await parseAsync(ctx, source),
130
- r: getRootID(ctx, source),
131
- f: ctx.features,
132
- m: Array.from(ctx.markedRefs),
133
- };
134
- }
135
-
136
- export function compileJSON(source: SerovalJSON): string {
137
- const serial = createSerializationContext({
138
- features: source.f,
139
- markedRefs: source.m,
140
- });
141
- const result = serializeTree(serial, source.t);
142
- return finalize(serial, source.r, source.t.i === SerovalNodeType.Object, result);
143
- }
144
-
145
- export function fromJSON<T>(source: SerovalJSON): T {
146
- const serial = createSerializationContext({
147
- features: source.f,
148
- markedRefs: source.m,
149
- });
150
- return deserializeTree(serial, source.t) as T;
151
- }
19
+ export { default as Serializer } from './core/Serializer';
152
20
 
153
21
  export default serialize;
154
-
155
- export { createReference } from './tree/reference';
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { WellKnownSymbols } from './tree/symbols';
1
+ import type { WellKnownSymbols } from './core/constants';
2
2
 
3
3
  // Values that are non-recursive
4
4
  export type PrimitiveValue =
@@ -1,67 +0,0 @@
1
- import type { SerovalObjectFlags } from './tree/types';
2
- interface IndexAssignment {
3
- t: 'index';
4
- s: string;
5
- k: undefined;
6
- v: string;
7
- }
8
- interface SetAssignment {
9
- t: 'set';
10
- s: string;
11
- k: string;
12
- v: string;
13
- }
14
- interface AddAssignment {
15
- t: 'add';
16
- s: string;
17
- k: undefined;
18
- v: string;
19
- }
20
- interface AppendAssignment {
21
- t: 'append';
22
- s: string;
23
- k: string;
24
- v: string;
25
- }
26
- export type Assignment = IndexAssignment | AddAssignment | SetAssignment | AppendAssignment;
27
- export interface ParserContext {
28
- refs: Map<unknown, number>;
29
- markedRefs: Set<number>;
30
- features: number;
31
- }
32
- export interface FlaggedObject {
33
- type: SerovalObjectFlags;
34
- value: string;
35
- }
36
- export interface SerializationContext {
37
- stack: number[];
38
- validRefs: (number | undefined)[];
39
- refSize: number;
40
- markedRefs: Set<number>;
41
- vars: (string | undefined)[];
42
- assignments: Assignment[];
43
- features: number;
44
- valueMap: Map<number, unknown>;
45
- flags: FlaggedObject[];
46
- }
47
- export interface Options {
48
- disabledFeatures: number;
49
- }
50
- export declare function createParserContext(options?: Partial<Options>): ParserContext;
51
- export interface SerializationOptions {
52
- markedRefs: number[] | Set<number>;
53
- features: number;
54
- }
55
- export declare function createSerializationContext(options: SerializationOptions): SerializationContext;
56
- /**
57
- * Increments the number of references the referenced value has
58
- */
59
- export declare function markRef(ctx: ParserContext | SerializationContext, current: number): void;
60
- /**
61
- * Creates the reference param (identifier) from the given reference ID
62
- * Calling this function means the value has been referenced somewhere
63
- */
64
- export declare function getRefParam(ctx: SerializationContext, index: number): string;
65
- export declare function getRootID<T>(ctx: ParserContext, current: T): number;
66
- export declare function createIndexedValue<T>(ctx: ParserContext, current: T): number;
67
- export {};
@@ -1,3 +0,0 @@
1
- import type { ParserContext } from '../context';
2
- import type { SerovalNode } from './types';
3
- export default function parseAsync<T>(ctx: ParserContext, current: T): Promise<SerovalNode>;
@@ -1,3 +0,0 @@
1
- import type { SerializationContext } from '../context';
2
- import type { SerovalNode } from './types';
3
- export default function deserializeTree(ctx: SerializationContext, node: SerovalNode): unknown;
@@ -1,19 +0,0 @@
1
- import type { ParserContext } from '../context';
2
- import type { BigIntTypedArrayValue, TypedArrayValue } from '../types';
3
- import type { WellKnownSymbols } from './symbols';
4
- import type { SerovalBigIntNode, SerovalBigIntTypedArrayNode, SerovalDateNode, SerovalIndexedValueNode, SerovalRegExpNode, SerovalStringNode, SerovalTypedArrayNode, SerovalWKSymbolNode, SerovalReferenceNode, SerovalArrayBufferNode, SerovalDataViewNode, SerovalNode } from './types';
5
- export declare function createNumberNode(value: number): SerovalNode;
6
- export declare function createStringNode(value: string): SerovalStringNode;
7
- export declare function createBigIntNode(ctx: ParserContext, current: bigint): SerovalBigIntNode;
8
- export declare function createIndexedValueNode(id: number): SerovalIndexedValueNode;
9
- export declare function createDateNode(id: number, current: Date): SerovalDateNode;
10
- export declare function createRegExpNode(id: number, current: RegExp): SerovalRegExpNode;
11
- export declare function createArrayBufferNode(id: number, current: ArrayBuffer): SerovalArrayBufferNode;
12
- export declare function serializeArrayBuffer(ctx: ParserContext, current: ArrayBuffer): SerovalNode;
13
- export declare function createTypedArrayNode(ctx: ParserContext, id: number, current: TypedArrayValue): SerovalTypedArrayNode;
14
- export declare function createBigIntTypedArrayNode(ctx: ParserContext, id: number, current: BigIntTypedArrayValue): SerovalBigIntTypedArrayNode;
15
- export declare function createWKSymbolNode(ctx: ParserContext, id: number, current: WellKnownSymbols): SerovalWKSymbolNode;
16
- export declare function createReferenceNode<T>(id: number, ref: T): SerovalReferenceNode;
17
- export declare function createDataViewNode(ctx: ParserContext, id: number, current: DataView): SerovalDataViewNode;
18
- export declare function createSymbolNode(ctx: ParserContext, current: symbol): SerovalNode;
19
- export declare function createFunctionNode(ctx: ParserContext, current: Function): SerovalNode;
@@ -1,4 +0,0 @@
1
- import type { SerializationContext } from '../context';
2
- import type { SerovalNode } from './types';
3
- export declare function resolvePatches(ctx: SerializationContext): string | undefined;
4
- export default function serializeTree(ctx: SerializationContext, node: SerovalNode): string;
@@ -1,33 +0,0 @@
1
- export declare const enum Symbols {
2
- AsyncIterator = 0,
3
- HasInstance = 1,
4
- IsConcatSpreadable = 2,
5
- Iterator = 3,
6
- Match = 4,
7
- MatchAll = 5,
8
- Replace = 6,
9
- Search = 7,
10
- Species = 8,
11
- Split = 9,
12
- ToPrimitive = 10,
13
- ToStringTag = 11,
14
- Unscopables = 12
15
- }
16
- export declare const SYMBOL_STRING: Record<Symbols, string>;
17
- export declare const INV_SYMBOL_REF: {
18
- [Symbol.asyncIterator]: Symbols;
19
- [Symbol.hasInstance]: Symbols;
20
- [Symbol.isConcatSpreadable]: Symbols;
21
- [Symbol.iterator]: Symbols;
22
- [Symbol.match]: Symbols;
23
- [Symbol.matchAll]: Symbols;
24
- [Symbol.replace]: Symbols;
25
- [Symbol.search]: Symbols;
26
- [Symbol.species]: Symbols;
27
- [Symbol.split]: Symbols;
28
- [Symbol.toPrimitive]: Symbols;
29
- [Symbol.toStringTag]: Symbols;
30
- [Symbol.unscopables]: Symbols;
31
- };
32
- export type WellKnownSymbols = keyof typeof INV_SYMBOL_REF;
33
- export declare const SYMBOL_REF: Record<Symbols, WellKnownSymbols>;
@@ -1,3 +0,0 @@
1
- import type { ParserContext } from '../context';
2
- import type { SerovalNode } from './types';
3
- export default function parseSync<T>(ctx: ParserContext, current: T): SerovalNode;
@@ -1,6 +0,0 @@
1
- import type { ParserContext } from '../context';
2
- import type { SerovalBlobNode, SerovalFileNode, SerovalURLNode, SerovalURLSearchParamsNode } from './types';
3
- export declare function createURLNode(ctx: ParserContext, id: number, current: URL): SerovalURLNode;
4
- export declare function createURLSearchParamsNode(ctx: ParserContext, id: number, current: URLSearchParams): SerovalURLSearchParamsNode;
5
- export declare function createBlobNode(ctx: ParserContext, id: number, current: Blob): Promise<SerovalBlobNode>;
6
- export declare function createFileNode(ctx: ParserContext, id: number, current: File): Promise<SerovalFileNode>;
package/src/context.ts DELETED
@@ -1,164 +0,0 @@
1
- import { ALL_ENABLED } from './compat';
2
- import getIdentifier from './get-identifier';
3
- import type { SerovalObjectFlags } from './tree/types';
4
-
5
- interface IndexAssignment {
6
- t: 'index';
7
- s: string;
8
- k: undefined;
9
- v: string;
10
- }
11
-
12
- interface SetAssignment {
13
- t: 'set';
14
- s: string;
15
- k: string;
16
- v: string;
17
- }
18
-
19
- interface AddAssignment {
20
- t: 'add';
21
- s: string;
22
- k: undefined;
23
- v: string;
24
- }
25
-
26
- interface AppendAssignment {
27
- t: 'append';
28
- s: string;
29
- k: string;
30
- v: string;
31
- }
32
-
33
- // Array of assignments to be done (used for recursion)
34
- export type Assignment =
35
- | IndexAssignment
36
- | AddAssignment
37
- | SetAssignment
38
- | AppendAssignment;
39
-
40
- export interface ParserContext {
41
- refs: Map<unknown, number>;
42
- markedRefs: Set<number>;
43
- features: number;
44
- }
45
-
46
- export interface FlaggedObject {
47
- type: SerovalObjectFlags;
48
- value: string;
49
- }
50
-
51
- export interface SerializationContext {
52
- stack: number[];
53
- // Map tree refs to actual refs
54
- validRefs: (number | undefined)[];
55
- refSize: number;
56
- // Refs that are...referenced
57
- markedRefs: Set<number>;
58
- // Variables
59
- vars: (string | undefined)[];
60
- // Array of assignments to be done (used for recursion)
61
- assignments: Assignment[];
62
- // Supported features
63
- features: number;
64
-
65
- valueMap: Map<number, unknown>;
66
-
67
- // Object flags
68
- flags: FlaggedObject[];
69
- }
70
-
71
- export interface Options {
72
- disabledFeatures: number;
73
- }
74
-
75
- const DEFAULT_OPTIONS: Options = {
76
- disabledFeatures: 0,
77
- };
78
-
79
- export function createParserContext(options: Partial<Options> = {}): ParserContext {
80
- // eslint-disable-next-line prefer-object-spread
81
- const result = Object.assign({}, DEFAULT_OPTIONS, options);
82
- return {
83
- markedRefs: new Set(),
84
- refs: new Map(),
85
- features: ALL_ENABLED ^ result.disabledFeatures,
86
- };
87
- }
88
-
89
- export interface SerializationOptions {
90
- markedRefs: number[] | Set<number>;
91
- features: number;
92
- }
93
-
94
- export function createSerializationContext(options: SerializationOptions): SerializationContext {
95
- return {
96
- stack: [],
97
- vars: [],
98
- assignments: [],
99
- validRefs: [],
100
- refSize: 0,
101
- features: options.features,
102
- markedRefs: new Set(options.markedRefs),
103
- valueMap: new Map(),
104
- flags: [],
105
- };
106
- }
107
-
108
- /**
109
- * Increments the number of references the referenced value has
110
- */
111
- export function markRef(
112
- ctx: ParserContext | SerializationContext,
113
- current: number,
114
- ): void {
115
- ctx.markedRefs.add(current);
116
- }
117
- /**
118
- * Creates the reference param (identifier) from the given reference ID
119
- * Calling this function means the value has been referenced somewhere
120
- */
121
- export function getRefParam(ctx: SerializationContext, index: number): string {
122
- /**
123
- * Creates a new reference ID from a given reference ID
124
- * This new reference ID means that the reference itself
125
- * has been referenced at least once, and is used to generate
126
- * the variables
127
- */
128
- let actualIndex = ctx.validRefs[index];
129
- if (actualIndex == null) {
130
- actualIndex = ctx.refSize++;
131
- ctx.validRefs[index] = actualIndex;
132
- }
133
- let identifier = ctx.vars[actualIndex];
134
- if (identifier == null) {
135
- identifier = getIdentifier(actualIndex);
136
- ctx.vars[actualIndex] = identifier;
137
- }
138
- return identifier;
139
- }
140
-
141
- export function getRootID<T>(
142
- ctx: ParserContext,
143
- current: T,
144
- ): number {
145
- const ref = ctx.refs.get(current);
146
- if (ref == null) {
147
- return ctx.refs.size;
148
- }
149
- return ref;
150
- }
151
-
152
- export function createIndexedValue<T>(
153
- ctx: ParserContext,
154
- current: T,
155
- ): number {
156
- const ref = ctx.refs.get(current);
157
- if (ref == null) {
158
- const id = ctx.refs.size;
159
- ctx.refs.set(current, id);
160
- return id;
161
- }
162
- markRef(ctx, ref);
163
- return ref;
164
- }
@@ -1,73 +0,0 @@
1
- import type { SerovalConstantNode } from './types';
2
- import { SerovalConstant, SerovalNodeType } from './types';
3
-
4
- function createConstantNode(value: SerovalConstant): SerovalConstantNode {
5
- return {
6
- t: SerovalNodeType.Constant,
7
- i: undefined,
8
- s: value,
9
- l: undefined,
10
- c: undefined,
11
- m: undefined,
12
- d: undefined,
13
- a: undefined,
14
- f: undefined,
15
- b: undefined,
16
- o: undefined,
17
- };
18
- }
19
-
20
- export const TRUE_NODE = createConstantNode(SerovalConstant.True);
21
- export const FALSE_NODE = createConstantNode(SerovalConstant.False);
22
- export const UNDEFINED_NODE = createConstantNode(SerovalConstant.Undefined);
23
- export const NULL_NODE = createConstantNode(SerovalConstant.Null);
24
- export const NEG_ZERO_NODE = createConstantNode(SerovalConstant.NegativeZero);
25
- export const INFINITY_NODE = createConstantNode(SerovalConstant.Infinity);
26
- export const NEG_INFINITY_NODE = createConstantNode(SerovalConstant.NegativeInfinity);
27
- export const NAN_NODE = createConstantNode(SerovalConstant.NaN);
28
-
29
- export function serializeConstant(node: SerovalConstantNode): string {
30
- switch (node.s) {
31
- case SerovalConstant.True:
32
- return '!0';
33
- case SerovalConstant.False:
34
- return '!1';
35
- case SerovalConstant.Undefined:
36
- return 'void 0';
37
- case SerovalConstant.Null:
38
- return 'null';
39
- case SerovalConstant.NegativeZero:
40
- return '-0';
41
- case SerovalConstant.Infinity:
42
- return '1/0';
43
- case SerovalConstant.NegativeInfinity:
44
- return '-1/0';
45
- case SerovalConstant.NaN:
46
- return 'NaN';
47
- default:
48
- throw new Error('invariant');
49
- }
50
- }
51
-
52
- export function deserializeConstant(node: SerovalConstantNode): unknown {
53
- switch (node.s) {
54
- case SerovalConstant.True:
55
- return true;
56
- case SerovalConstant.False:
57
- return false;
58
- case SerovalConstant.Undefined:
59
- return undefined;
60
- case SerovalConstant.Null:
61
- return null;
62
- case SerovalConstant.NegativeZero:
63
- return -0;
64
- case SerovalConstant.Infinity:
65
- return Infinity;
66
- case SerovalConstant.NegativeInfinity:
67
- return -Infinity;
68
- case SerovalConstant.NaN:
69
- return NaN;
70
- default:
71
- throw new Error('invariant');
72
- }
73
- }
@@ -1,65 +0,0 @@
1
- export const enum Symbols {
2
- AsyncIterator = 0,
3
- HasInstance = 1,
4
- IsConcatSpreadable = 2,
5
- Iterator = 3,
6
- Match = 4,
7
- MatchAll = 5,
8
- Replace = 6,
9
- Search = 7,
10
- Species = 8,
11
- Split = 9,
12
- ToPrimitive = 10,
13
- ToStringTag = 11,
14
- Unscopables = 12,
15
- }
16
-
17
- export const SYMBOL_STRING: Record<Symbols, string> = {
18
- [Symbols.AsyncIterator]: 'Symbol.asyncIterator',
19
- [Symbols.HasInstance]: 'Symbol.hasInstance',
20
- [Symbols.IsConcatSpreadable]: 'Symbol.isConcatSpreadable',
21
- [Symbols.Iterator]: 'Symbol.iterator',
22
- [Symbols.Match]: 'Symbol.match',
23
- [Symbols.MatchAll]: 'Symbol.matchAll',
24
- [Symbols.Replace]: 'Symbol.replace',
25
- [Symbols.Search]: 'Symbol.search',
26
- [Symbols.Species]: 'Symbol.species',
27
- [Symbols.Split]: 'Symbol.split',
28
- [Symbols.ToPrimitive]: 'Symbol.toPrimitive',
29
- [Symbols.ToStringTag]: 'Symbol.toStringTag',
30
- [Symbols.Unscopables]: 'Symbol.unscopables',
31
- };
32
-
33
- export const INV_SYMBOL_REF = {
34
- [Symbol.asyncIterator]: Symbols.AsyncIterator,
35
- [Symbol.hasInstance]: Symbols.HasInstance,
36
- [Symbol.isConcatSpreadable]: Symbols.IsConcatSpreadable,
37
- [Symbol.iterator]: Symbols.Iterator,
38
- [Symbol.match]: Symbols.Match,
39
- [Symbol.matchAll]: Symbols.MatchAll,
40
- [Symbol.replace]: Symbols.Replace,
41
- [Symbol.search]: Symbols.Search,
42
- [Symbol.species]: Symbols.Species,
43
- [Symbol.split]: Symbols.Split,
44
- [Symbol.toPrimitive]: Symbols.ToPrimitive,
45
- [Symbol.toStringTag]: Symbols.ToStringTag,
46
- [Symbol.unscopables]: Symbols.Unscopables,
47
- };
48
-
49
- export type WellKnownSymbols = keyof typeof INV_SYMBOL_REF;
50
-
51
- export const SYMBOL_REF: Record<Symbols, WellKnownSymbols> = {
52
- [Symbols.AsyncIterator]: Symbol.asyncIterator,
53
- [Symbols.HasInstance]: Symbol.hasInstance,
54
- [Symbols.IsConcatSpreadable]: Symbol.isConcatSpreadable,
55
- [Symbols.Iterator]: Symbol.iterator,
56
- [Symbols.Match]: Symbol.match,
57
- [Symbols.MatchAll]: Symbol.matchAll,
58
- [Symbols.Replace]: Symbol.replace,
59
- [Symbols.Search]: Symbol.search,
60
- [Symbols.Species]: Symbol.species,
61
- [Symbols.Split]: Symbol.split,
62
- [Symbols.ToPrimitive]: Symbol.toPrimitive,
63
- [Symbols.ToStringTag]: Symbol.toStringTag,
64
- [Symbols.Unscopables]: Symbol.unscopables,
65
- };
File without changes
File without changes
File without changes