seroval 0.8.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +4 -287
  2. package/dist/cjs/development/index.cjs +3858 -1385
  3. package/dist/cjs/development/index.cjs.map +4 -4
  4. package/dist/cjs/production/index.cjs +12 -3
  5. package/dist/esm/development/index.mjs +3611 -1136
  6. package/dist/esm/development/index.mjs.map +4 -4
  7. package/dist/esm/production/index.mjs +12 -3
  8. package/dist/types/core/Serializer.d.ts +14 -0
  9. package/dist/types/{tree → core}/UnsupportedTypeError.d.ts +4 -3
  10. package/dist/types/{assert.d.ts → core/assert.d.ts} +1 -1
  11. package/dist/types/core/assignments.d.ts +33 -0
  12. package/dist/types/core/base-primitives.d.ts +12 -0
  13. package/dist/types/{compat.d.ts → core/compat.d.ts} +22 -22
  14. package/dist/types/core/constants.d.ts +89 -0
  15. package/dist/types/core/context.d.ts +9 -0
  16. package/dist/types/core/cross/async.d.ts +3 -0
  17. package/dist/types/core/cross/context.d.ts +30 -0
  18. package/dist/types/core/cross/index.d.ts +7 -0
  19. package/dist/types/core/cross/primitives.d.ts +9 -0
  20. package/dist/types/core/cross/serialize.d.ts +5 -0
  21. package/dist/types/core/cross/stream.d.ts +3 -0
  22. package/dist/types/core/cross/sync.d.ts +3 -0
  23. package/dist/types/core/cross/web-api.d.ts +4 -0
  24. package/dist/types/{get-identifier.d.ts → core/get-identifier.d.ts} +1 -1
  25. package/dist/types/core/keys.d.ts +12 -0
  26. package/dist/types/{tree/constants.d.ts → core/literals.d.ts} +9 -11
  27. package/dist/types/core/promise-to-result.d.ts +1 -0
  28. package/dist/types/{tree → core}/reference.d.ts +5 -6
  29. package/dist/types/{tree → core}/shared.d.ts +13 -11
  30. package/dist/types/{string.d.ts → core/string.d.ts} +3 -3
  31. package/dist/types/core/tree/async.d.ts +3 -0
  32. package/dist/types/core/tree/context.d.ts +45 -0
  33. package/dist/types/core/tree/deserialize.d.ts +3 -0
  34. package/dist/types/core/tree/index.d.ts +15 -0
  35. package/dist/types/core/tree/primitives.d.ts +9 -0
  36. package/dist/types/core/tree/serialize.d.ts +4 -0
  37. package/dist/types/core/tree/sync.d.ts +3 -0
  38. package/dist/types/core/tree/web-api.d.ts +4 -0
  39. package/dist/types/{tree → core}/types.d.ts +228 -228
  40. package/dist/types/core/web-api.d.ts +4 -0
  41. package/dist/types/index.d.ts +9 -19
  42. package/dist/types/types.d.ts +20 -20
  43. package/package.json +7 -7
  44. package/src/core/Serializer.ts +46 -0
  45. package/src/{tree → core}/UnsupportedTypeError.ts +1 -1
  46. package/src/core/assignments.ts +159 -0
  47. package/src/{tree/primitives.ts → core/base-primitives.ts} +42 -133
  48. package/src/core/constants.ts +169 -0
  49. package/src/core/context.ts +15 -0
  50. package/src/core/cross/async.ts +614 -0
  51. package/src/core/cross/context.ts +79 -0
  52. package/src/core/cross/index.ts +154 -0
  53. package/src/core/cross/primitives.ts +137 -0
  54. package/src/core/cross/serialize.ts +846 -0
  55. package/src/core/cross/stream.ts +740 -0
  56. package/src/core/cross/sync.ts +561 -0
  57. package/src/core/cross/web-api.ts +55 -0
  58. package/src/core/header.js +65 -0
  59. package/src/core/keys.ts +33 -0
  60. package/src/core/literals.ts +28 -0
  61. package/src/core/promise-to-result.ts +9 -0
  62. package/src/{tree → core}/reference.ts +6 -8
  63. package/src/{tree → core}/shared.ts +17 -3
  64. package/src/{tree → core/tree}/async.ts +57 -34
  65. package/src/core/tree/context.ts +136 -0
  66. package/src/{tree → core/tree}/deserialize.ts +83 -54
  67. package/src/core/tree/index.ts +146 -0
  68. package/src/core/tree/primitives.ts +132 -0
  69. package/src/{tree → core/tree}/serialize.ts +124 -178
  70. package/src/{tree → core/tree}/sync.ts +60 -39
  71. package/src/{tree → core/tree}/web-api.ts +10 -50
  72. package/src/{tree → core}/types.ts +82 -54
  73. package/src/core/web-api.ts +51 -0
  74. package/src/index.ts +7 -141
  75. package/src/types.ts +1 -1
  76. package/dist/types/context.d.ts +0 -61
  77. package/dist/types/tree/async.d.ts +0 -3
  78. package/dist/types/tree/deserialize.d.ts +0 -3
  79. package/dist/types/tree/primitives.d.ts +0 -19
  80. package/dist/types/tree/serialize.d.ts +0 -4
  81. package/dist/types/tree/symbols.d.ts +0 -33
  82. package/dist/types/tree/sync.d.ts +0 -3
  83. package/dist/types/tree/web-api.d.ts +0 -6
  84. package/src/context.ts +0 -154
  85. package/src/tree/constants.ts +0 -72
  86. package/src/tree/iterator.ts +0 -14
  87. package/src/tree/symbols.ts +0 -65
  88. /package/src/{assert.ts → core/assert.ts} +0 -0
  89. /package/src/{compat.ts → core/compat.ts} +0 -0
  90. /package/src/{get-identifier.ts → core/get-identifier.ts} +0 -0
  91. /package/src/{string.ts → core/string.ts} +0 -0
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 { CROSS_REFERENCE_HEADER } 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,61 +0,0 @@
1
- interface IndexAssignment {
2
- t: 'index';
3
- s: string;
4
- k: undefined;
5
- v: string;
6
- }
7
- interface SetAssignment {
8
- t: 'set';
9
- s: string;
10
- k: string;
11
- v: string;
12
- }
13
- interface AddAssignment {
14
- t: 'add';
15
- s: string;
16
- k: undefined;
17
- v: string;
18
- }
19
- interface AppendAssignment {
20
- t: 'append';
21
- s: string;
22
- k: string;
23
- v: string;
24
- }
25
- export type Assignment = IndexAssignment | AddAssignment | SetAssignment | AppendAssignment;
26
- export interface ParserContext {
27
- refs: Map<unknown, number>;
28
- markedRefs: Set<number>;
29
- features: number;
30
- }
31
- export interface SerializationContext {
32
- stack: number[];
33
- validRefs: (number | undefined)[];
34
- refSize: number;
35
- markedRefs: Set<number>;
36
- vars: (string | undefined)[];
37
- assignments: Assignment[];
38
- features: number;
39
- valueMap: Map<number, unknown>;
40
- }
41
- export interface Options {
42
- disabledFeatures: number;
43
- }
44
- export declare function createParserContext(options?: Partial<Options>): ParserContext;
45
- export interface SerializationOptions {
46
- markedRefs: number[] | Set<number>;
47
- features: number;
48
- }
49
- export declare function createSerializationContext(options: SerializationOptions): SerializationContext;
50
- /**
51
- * Increments the number of references the referenced value has
52
- */
53
- export declare function markRef(ctx: ParserContext | SerializationContext, current: number): void;
54
- /**
55
- * Creates the reference param (identifier) from the given reference ID
56
- * Calling this function means the value has been referenced somewhere
57
- */
58
- export declare function getRefParam(ctx: SerializationContext, index: number): string;
59
- export declare function getRootID<T>(ctx: ParserContext, current: T): number;
60
- export declare function createIndexedValue<T>(ctx: ParserContext, current: T): number;
61
- 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,154 +0,0 @@
1
- import { ALL_ENABLED } from './compat';
2
- import getIdentifier from './get-identifier';
3
-
4
- interface IndexAssignment {
5
- t: 'index';
6
- s: string;
7
- k: undefined;
8
- v: string;
9
- }
10
-
11
- interface SetAssignment {
12
- t: 'set';
13
- s: string;
14
- k: string;
15
- v: string;
16
- }
17
-
18
- interface AddAssignment {
19
- t: 'add';
20
- s: string;
21
- k: undefined;
22
- v: string;
23
- }
24
-
25
- interface AppendAssignment {
26
- t: 'append';
27
- s: string;
28
- k: string;
29
- v: string;
30
- }
31
-
32
- // Array of assignments to be done (used for recursion)
33
- export type Assignment =
34
- | IndexAssignment
35
- | AddAssignment
36
- | SetAssignment
37
- | AppendAssignment;
38
-
39
- export interface ParserContext {
40
- refs: Map<unknown, number>;
41
- markedRefs: Set<number>;
42
- features: number;
43
- }
44
-
45
- export interface SerializationContext {
46
- stack: number[];
47
- // Map tree refs to actual refs
48
- validRefs: (number | undefined)[];
49
- refSize: number;
50
- // Refs that are...referenced
51
- markedRefs: Set<number>;
52
- // Variables
53
- vars: (string | undefined)[];
54
- // Array of assignments to be done (used for recursion)
55
- assignments: Assignment[];
56
- // Supported features
57
- features: number;
58
-
59
- valueMap: Map<number, unknown>;
60
- }
61
-
62
- export interface Options {
63
- disabledFeatures: number;
64
- }
65
-
66
- const DEFAULT_OPTIONS: Options = {
67
- disabledFeatures: 0,
68
- };
69
-
70
- export function createParserContext(options: Partial<Options> = {}): ParserContext {
71
- // eslint-disable-next-line prefer-object-spread
72
- const result = Object.assign({}, DEFAULT_OPTIONS, options);
73
- return {
74
- markedRefs: new Set(),
75
- refs: new Map(),
76
- features: ALL_ENABLED ^ result.disabledFeatures,
77
- };
78
- }
79
-
80
- export interface SerializationOptions {
81
- markedRefs: number[] | Set<number>;
82
- features: number;
83
- }
84
-
85
- export function createSerializationContext(options: SerializationOptions): SerializationContext {
86
- return {
87
- stack: [],
88
- vars: [],
89
- assignments: [],
90
- validRefs: [],
91
- refSize: 0,
92
- features: options.features,
93
- markedRefs: new Set(options.markedRefs),
94
- valueMap: new Map(),
95
- };
96
- }
97
-
98
- /**
99
- * Increments the number of references the referenced value has
100
- */
101
- export function markRef(
102
- ctx: ParserContext | SerializationContext,
103
- current: number,
104
- ): void {
105
- ctx.markedRefs.add(current);
106
- }
107
- /**
108
- * Creates the reference param (identifier) from the given reference ID
109
- * Calling this function means the value has been referenced somewhere
110
- */
111
- export function getRefParam(ctx: SerializationContext, index: number): string {
112
- /**
113
- * Creates a new reference ID from a given reference ID
114
- * This new reference ID means that the reference itself
115
- * has been referenced at least once, and is used to generate
116
- * the variables
117
- */
118
- let actualIndex = ctx.validRefs[index];
119
- if (actualIndex == null) {
120
- actualIndex = ctx.refSize++;
121
- ctx.validRefs[index] = actualIndex;
122
- }
123
- let identifier = ctx.vars[actualIndex];
124
- if (identifier == null) {
125
- identifier = getIdentifier(actualIndex);
126
- ctx.vars[actualIndex] = identifier;
127
- }
128
- return identifier;
129
- }
130
-
131
- export function getRootID<T>(
132
- ctx: ParserContext,
133
- current: T,
134
- ): number {
135
- const ref = ctx.refs.get(current);
136
- if (ref == null) {
137
- return ctx.refs.size;
138
- }
139
- return ref;
140
- }
141
-
142
- export function createIndexedValue<T>(
143
- ctx: ParserContext,
144
- current: T,
145
- ): number {
146
- const ref = ctx.refs.get(current);
147
- if (ref == null) {
148
- const id = ctx.refs.size;
149
- ctx.refs.set(current, id);
150
- return id;
151
- }
152
- markRef(ctx, ref);
153
- return ref;
154
- }
@@ -1,72 +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
- };
17
- }
18
-
19
- export const TRUE_NODE = createConstantNode(SerovalConstant.True);
20
- export const FALSE_NODE = createConstantNode(SerovalConstant.False);
21
- export const UNDEFINED_NODE = createConstantNode(SerovalConstant.Undefined);
22
- export const NULL_NODE = createConstantNode(SerovalConstant.Null);
23
- export const NEG_ZERO_NODE = createConstantNode(SerovalConstant.NegativeZero);
24
- export const INFINITY_NODE = createConstantNode(SerovalConstant.Infinity);
25
- export const NEG_INFINITY_NODE = createConstantNode(SerovalConstant.NegativeInfinity);
26
- export const NAN_NODE = createConstantNode(SerovalConstant.NaN);
27
-
28
- export function serializeConstant(node: SerovalConstantNode): string {
29
- switch (node.s) {
30
- case SerovalConstant.True:
31
- return '!0';
32
- case SerovalConstant.False:
33
- return '!1';
34
- case SerovalConstant.Undefined:
35
- return 'void 0';
36
- case SerovalConstant.Null:
37
- return 'null';
38
- case SerovalConstant.NegativeZero:
39
- return '-0';
40
- case SerovalConstant.Infinity:
41
- return '1/0';
42
- case SerovalConstant.NegativeInfinity:
43
- return '-1/0';
44
- case SerovalConstant.NaN:
45
- return 'NaN';
46
- default:
47
- throw new Error('invariant');
48
- }
49
- }
50
-
51
- export function deserializeConstant(node: SerovalConstantNode): unknown {
52
- switch (node.s) {
53
- case SerovalConstant.True:
54
- return true;
55
- case SerovalConstant.False:
56
- return false;
57
- case SerovalConstant.Undefined:
58
- return undefined;
59
- case SerovalConstant.Null:
60
- return null;
61
- case SerovalConstant.NegativeZero:
62
- return -0;
63
- case SerovalConstant.Infinity:
64
- return Infinity;
65
- case SerovalConstant.NegativeInfinity:
66
- return -Infinity;
67
- case SerovalConstant.NaN:
68
- return NaN;
69
- default:
70
- throw new Error('invariant');
71
- }
72
- }
@@ -1,14 +0,0 @@
1
- export default function createIterator<T>(
2
- values: Array<T>,
3
- ): Iterator<T> {
4
- let index = 0;
5
- const len = values.length;
6
- return {
7
- next() {
8
- return {
9
- value: values[index++],
10
- done: index >= len,
11
- };
12
- },
13
- };
14
- }
@@ -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