seroval 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/development/index.cjs +1109 -1039
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1109 -1039
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/assert.d.ts +1 -1
- package/dist/types/context.d.ts +2 -2
- package/dist/types/index.d.ts +3 -4
- package/dist/types/string.d.ts +1 -1
- package/dist/types/tree/UnsupportedTypeError.d.ts +3 -0
- package/dist/types/tree/async.d.ts +3 -3
- package/dist/types/tree/constants.d.ts +11 -0
- package/dist/types/tree/deserialize.d.ts +2 -2
- package/dist/types/tree/primitives.d.ts +9 -15
- package/dist/types/tree/serialize.d.ts +2 -2
- package/dist/types/tree/shared.d.ts +10 -8
- package/dist/types/tree/sync.d.ts +3 -3
- package/dist/types/tree/types.d.ts +64 -71
- package/dist/types/tree/web-api.d.ts +2 -2
- package/dist/types/types.d.ts +4 -4
- package/package.json +10 -8
- package/src/assert.ts +2 -2
- package/src/compat.ts +0 -1
- package/src/context.ts +10 -7
- package/src/get-identifier.ts +1 -1
- package/src/index.ts +35 -26
- package/src/string.ts +2 -2
- package/src/tree/UnsupportedTypeError.ts +8 -0
- package/src/tree/async.ts +245 -233
- package/src/tree/constants.ts +72 -0
- package/src/tree/deserialize.ts +96 -93
- package/src/tree/primitives.ts +81 -134
- package/src/tree/reference.ts +4 -3
- package/src/tree/serialize.ts +251 -197
- package/src/tree/shared.ts +31 -22
- package/src/tree/symbols.ts +13 -13
- package/src/tree/sync.ts +226 -198
- package/src/tree/types.ts +74 -93
- package/src/tree/web-api.ts +10 -7
- package/src/types.ts +7 -3
package/src/tree/shared.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Feature } from '../compat';
|
|
2
|
-
import { ParserContext } from '../context';
|
|
3
|
-
import {
|
|
4
|
-
AsyncServerValue,
|
|
2
|
+
import type { ParserContext } from '../context';
|
|
3
|
+
import type {
|
|
5
4
|
ErrorValue,
|
|
6
5
|
} from '../types';
|
|
7
6
|
|
|
8
|
-
export function getErrorConstructorName(error: ErrorValue) {
|
|
7
|
+
export function getErrorConstructorName(error: ErrorValue): string {
|
|
9
8
|
if (error instanceof EvalError) {
|
|
10
9
|
return 'EvalError';
|
|
11
10
|
}
|
|
@@ -27,7 +26,16 @@ export function getErrorConstructorName(error: ErrorValue) {
|
|
|
27
26
|
return 'Error';
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
type ErrorConstructors =
|
|
30
|
+
| ErrorConstructor
|
|
31
|
+
| EvalErrorConstructor
|
|
32
|
+
| RangeErrorConstructor
|
|
33
|
+
| ReferenceErrorConstructor
|
|
34
|
+
| SyntaxErrorConstructor
|
|
35
|
+
| TypeErrorConstructor
|
|
36
|
+
| URIErrorConstructor;
|
|
37
|
+
|
|
38
|
+
export function getErrorConstructor(errorName: string): ErrorConstructors {
|
|
31
39
|
switch (errorName) {
|
|
32
40
|
case 'Error': return Error;
|
|
33
41
|
case 'EvalError': return EvalError;
|
|
@@ -44,8 +52,8 @@ export function getErrorConstructor(errorName: string) {
|
|
|
44
52
|
export function getErrorOptions(
|
|
45
53
|
ctx: ParserContext,
|
|
46
54
|
error: Error,
|
|
47
|
-
) {
|
|
48
|
-
let options: Record<string,
|
|
55
|
+
): Record<string, unknown> | undefined {
|
|
56
|
+
let options: Record<string, unknown> | undefined;
|
|
49
57
|
const constructor = getErrorConstructorName(error);
|
|
50
58
|
// Name has been modified
|
|
51
59
|
if (error.name !== constructor) {
|
|
@@ -72,21 +80,9 @@ export function getErrorOptions(
|
|
|
72
80
|
return options;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
export function getIterableOptions(obj: Iterable<any>) {
|
|
76
|
-
const names = Object.getOwnPropertyNames(obj);
|
|
77
|
-
if (names.length) {
|
|
78
|
-
const options: Record<string, unknown> = {};
|
|
79
|
-
for (const name of names) {
|
|
80
|
-
options[name] = obj[name as unknown as keyof typeof obj];
|
|
81
|
-
}
|
|
82
|
-
return options;
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
83
|
export function isIterable(
|
|
88
84
|
value: unknown,
|
|
89
|
-
): value is Iterable<
|
|
85
|
+
): value is Iterable<unknown> {
|
|
90
86
|
if (!value || typeof value !== 'object') {
|
|
91
87
|
return false;
|
|
92
88
|
}
|
|
@@ -114,7 +110,20 @@ export function isIterable(
|
|
|
114
110
|
return Symbol.iterator in value;
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
type TypedArrayConstructor =
|
|
114
|
+
| Int8ArrayConstructor
|
|
115
|
+
| Int16ArrayConstructor
|
|
116
|
+
| Int32ArrayConstructor
|
|
117
|
+
| Uint8ArrayConstructor
|
|
118
|
+
| Uint16ArrayConstructor
|
|
119
|
+
| Uint32ArrayConstructor
|
|
120
|
+
| Uint8ClampedArrayConstructor
|
|
121
|
+
| Float32ArrayConstructor
|
|
122
|
+
| Float64ArrayConstructor
|
|
123
|
+
| BigInt64ArrayConstructor
|
|
124
|
+
| BigUint64ArrayConstructor;
|
|
125
|
+
|
|
126
|
+
export function getTypedArrayConstructor(name: string): TypedArrayConstructor {
|
|
118
127
|
switch (name) {
|
|
119
128
|
case 'Int8Array': return Int8Array;
|
|
120
129
|
case 'Int16Array': return Int16Array;
|
|
@@ -134,7 +143,7 @@ export function getTypedArrayConstructor(name: string) {
|
|
|
134
143
|
|
|
135
144
|
const IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
|
|
136
145
|
|
|
137
|
-
export function isValidIdentifier(name: string) {
|
|
146
|
+
export function isValidIdentifier(name: string): boolean {
|
|
138
147
|
const char = name[0];
|
|
139
148
|
return (
|
|
140
149
|
char === '$'
|
package/src/tree/symbols.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export const enum Symbols {
|
|
2
|
-
AsyncIterator,
|
|
3
|
-
HasInstance,
|
|
4
|
-
IsConcatSpreadable,
|
|
5
|
-
Iterator,
|
|
6
|
-
Match,
|
|
7
|
-
MatchAll,
|
|
8
|
-
Replace,
|
|
9
|
-
Search,
|
|
10
|
-
Species,
|
|
11
|
-
Split,
|
|
12
|
-
ToPrimitive,
|
|
13
|
-
ToStringTag,
|
|
14
|
-
Unscopables
|
|
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
15
|
}
|
|
16
16
|
|
|
17
17
|
export const SYMBOL_STRING: Record<Symbols, string> = {
|