@nyariv/sandboxjs 0.8.22 → 0.8.23

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/build/parser.d.ts CHANGED
@@ -1,14 +1,192 @@
1
- export declare type LispArray = Array<LispItem> & {
2
- lisp: {};
3
- };
4
- export declare type LispItem = Lisp | If | KeyVal | SpreadArray | SpreadObject | (LispArray) | {
5
- new (): any;
6
- } | (new (...args: any[]) => any) | CodeString | String | Number | Boolean | null | undefined;
7
- export interface ILiteral extends Lisp {
8
- op: 'literal';
9
- a: string;
10
- b: LispArray;
1
+ export declare const enum LispType {
2
+ None = 0,
3
+ Prop = 1,
4
+ StringIndex = 2,
5
+ Let = 3,
6
+ Const = 4,
7
+ Call = 5,
8
+ KeyVal = 6,
9
+ Number = 7,
10
+ Return = 8,
11
+ Assign = 9,
12
+ InlineFunction = 10,
13
+ ArrowFunction = 11,
14
+ CreateArray = 12,
15
+ If = 13,
16
+ IfCase = 14,
17
+ InlineIf = 15,
18
+ InlineIfCase = 16,
19
+ SpreadObject = 17,
20
+ SpreadArray = 18,
21
+ ArrayProp = 19,
22
+ PropOptional = 20,
23
+ CallOptional = 21,
24
+ CreateObject = 22,
25
+ Group = 23,
26
+ Not = 24,
27
+ IncrementBefore = 25,
28
+ IncrementAfter = 26,
29
+ DecrementBefore = 27,
30
+ DecrementAfter = 28,
31
+ And = 29,
32
+ Or = 30,
33
+ StrictNotEqual = 31,
34
+ StrictEqual = 32,
35
+ Plus = 33,
36
+ Var = 34,
37
+ GlobalSymbol = 35,
38
+ Literal = 36,
39
+ Function = 37,
40
+ Loop = 38,
41
+ Try = 39,
42
+ Switch = 40,
43
+ SwitchCase = 41,
44
+ Block = 42,
45
+ Expression = 43,
46
+ Await = 44,
47
+ New = 45,
48
+ Throw = 46,
49
+ Minus = 47,
50
+ Divide = 48,
51
+ Power = 49,
52
+ Multiply = 50,
53
+ Modulus = 51,
54
+ Equal = 52,
55
+ NotEqual = 53,
56
+ SmallerEqualThan = 54,
57
+ LargerEqualThan = 55,
58
+ SmallerThan = 56,
59
+ LargerThan = 57,
60
+ Negative = 58,
61
+ Positive = 59,
62
+ Typeof = 60,
63
+ Delete = 61,
64
+ Instanceof = 62,
65
+ In = 63,
66
+ Inverse = 64,
67
+ SubractEquals = 65,
68
+ AddEquals = 66,
69
+ DivideEquals = 67,
70
+ PowerEquals = 68,
71
+ MultiplyEquals = 69,
72
+ ModulusEquals = 70,
73
+ BitNegateEquals = 71,
74
+ BitAndEquals = 72,
75
+ BitOrEquals = 73,
76
+ UnsignedShiftRightEquals = 74,
77
+ ShiftRightEquals = 75,
78
+ ShiftLeftEquals = 76,
79
+ BitAnd = 77,
80
+ BitOr = 78,
81
+ BitNegate = 79,
82
+ BitShiftLeft = 80,
83
+ BitShiftRight = 81,
84
+ BitUnsignedShiftRight = 82,
85
+ BigInt = 83,
86
+ LiteralIndex = 84,
87
+ RegexIndex = 85,
88
+ LoopAction = 86,
89
+ Void = 87,
90
+ True = 88
11
91
  }
92
+ export type DefineLisp<op extends LispType, a extends LispItem | LispItem, b extends LispItem | LispItem> = [op, a, b];
93
+ export type ExtractLispOp<L> = L extends DefineLisp<infer i, any, any> ? i : never;
94
+ export type ExtractLispA<L> = L extends DefineLisp<any, infer i, any> ? i : never;
95
+ export type ExtractLispB<L> = L extends DefineLisp<any, any, infer i> ? i : never;
96
+ export type LispItemSingle = LispType.None | LispType.True | string | Lisp;
97
+ export type LispItem = LispItemSingle | LispItemSingle[];
98
+ export type Lisp = [LispType, LispItem, LispItem];
99
+ export type Literal = DefineLisp<LispType.Literal, string, Lisp[]> & {
100
+ tempJsStrings?: string[];
101
+ };
102
+ export type If = DefineLisp<LispType.If, Lisp, IfCase>;
103
+ export type InlineIf = DefineLisp<LispType.InlineIf, Lisp, InlineIfCase>;
104
+ export type IfCase = DefineLisp<LispType.IfCase, Lisp[], Lisp[]>;
105
+ export type InlineIfCase = DefineLisp<LispType.InlineIfCase, Lisp, Lisp>;
106
+ export type KeyVal = DefineLisp<LispType.KeyVal, string | Lisp, Lisp[]>;
107
+ export type SpreadObject = DefineLisp<LispType.SpreadObject, LispType.None, Lisp>;
108
+ export type SpreadArray = DefineLisp<LispType.SpreadArray, LispType.None, Lisp>;
109
+ export type ArrayProp = DefineLisp<LispType.ArrayProp, Lisp, Lisp>;
110
+ export type Prop = DefineLisp<LispType.Prop, Lisp, string | Lisp>;
111
+ export type PropOptional = DefineLisp<LispType.PropOptional, Lisp, Lisp[]>;
112
+ export type Call = DefineLisp<LispType.Call, Lisp, Lisp[]>;
113
+ export type CallOptional = DefineLisp<LispType.CallOptional, Lisp, Lisp[]>;
114
+ export type CreateArray = DefineLisp<LispType.CreateArray, Lisp, Lisp[]>;
115
+ export type CreateObject = DefineLisp<LispType.CreateObject, Lisp, Lisp[]>;
116
+ export type Group = DefineLisp<LispType.Group, Lisp, Lisp[]>;
117
+ export type Inverse = DefineLisp<LispType.Inverse, Lisp, Lisp>;
118
+ export type Not = DefineLisp<LispType.Not, Lisp, Lisp>;
119
+ export type Negative = DefineLisp<LispType.Negative, Lisp, Lisp>;
120
+ export type Positive = DefineLisp<LispType.Positive, Lisp, Lisp>;
121
+ export type Typeof = DefineLisp<LispType.Typeof, Lisp, Lisp>;
122
+ export type Delete = DefineLisp<LispType.Delete, Lisp, Lisp>;
123
+ export type IncrementBefore = DefineLisp<LispType.IncrementBefore, Lisp, LispType.None>;
124
+ export type IncrementAfter = DefineLisp<LispType.IncrementAfter, Lisp, LispType.None>;
125
+ export type DecrementBefore = DefineLisp<LispType.DecrementBefore, Lisp, LispType.None>;
126
+ export type DecrementAfter = DefineLisp<LispType.DecrementAfter, Lisp, LispType.None>;
127
+ export type And = DefineLisp<LispType.And, Lisp, Lisp>;
128
+ export type Or = DefineLisp<LispType.Or, Lisp, Lisp>;
129
+ export type Instanceof = DefineLisp<LispType.Instanceof, Lisp, Lisp>;
130
+ export type In = DefineLisp<LispType.In, Lisp, Lisp>;
131
+ export type Assigns = DefineLisp<LispType.Assign, Lisp, Lisp>;
132
+ export type SubractEquals = DefineLisp<LispType.SubractEquals, Lisp, Lisp>;
133
+ export type AddEquals = DefineLisp<LispType.AddEquals, Lisp, Lisp>;
134
+ export type DivideEquals = DefineLisp<LispType.DivideEquals, Lisp, Lisp>;
135
+ export type PowerEquals = DefineLisp<LispType.PowerEquals, Lisp, Lisp>;
136
+ export type MultiplyEquals = DefineLisp<LispType.MultiplyEquals, Lisp, Lisp>;
137
+ export type ModulusEquals = DefineLisp<LispType.ModulusEquals, Lisp, Lisp>;
138
+ export type BitNegateEquals = DefineLisp<LispType.BitNegateEquals, Lisp, Lisp>;
139
+ export type BitAndEquals = DefineLisp<LispType.BitAndEquals, Lisp, Lisp>;
140
+ export type BitOrEquals = DefineLisp<LispType.BitOrEquals, Lisp, Lisp>;
141
+ export type UnsignedShiftRightEquals = DefineLisp<LispType.UnsignedShiftRightEquals, Lisp, Lisp>;
142
+ export type ShiftLeftEquals = DefineLisp<LispType.ShiftLeftEquals, Lisp, Lisp>;
143
+ export type ShiftRightEquals = DefineLisp<LispType.ShiftRightEquals, Lisp, Lisp>;
144
+ export type BitAnd = DefineLisp<LispType.BitAnd, Lisp, Lisp>;
145
+ export type BitOr = DefineLisp<LispType.BitOr, Lisp, Lisp>;
146
+ export type BitNegate = DefineLisp<LispType.BitNegate, Lisp, Lisp>;
147
+ export type BitShiftLeft = DefineLisp<LispType.BitShiftLeft, Lisp, Lisp>;
148
+ export type BitShiftRight = DefineLisp<LispType.BitShiftRight, Lisp, Lisp>;
149
+ export type BitUnsignedShiftRight = DefineLisp<LispType.BitUnsignedShiftRight, Lisp, Lisp>;
150
+ export type SmallerEqualThan = DefineLisp<LispType.SmallerEqualThan, Lisp, Lisp>;
151
+ export type LargerEqualThan = DefineLisp<LispType.LargerEqualThan, Lisp, Lisp>;
152
+ export type SmallerThan = DefineLisp<LispType.SmallerThan, Lisp, Lisp>;
153
+ export type LargerThan = DefineLisp<LispType.LargerThan, Lisp, Lisp>;
154
+ export type StrictNotEqual = DefineLisp<LispType.StrictNotEqual, Lisp, Lisp>;
155
+ export type NotEqual = DefineLisp<LispType.NotEqual, Lisp, Lisp>;
156
+ export type StrictEqual = DefineLisp<LispType.StrictEqual, Lisp, Lisp>;
157
+ export type Equal = DefineLisp<LispType.Equal, Lisp, Lisp>;
158
+ export type Plus = DefineLisp<LispType.Plus, Lisp, Lisp>;
159
+ export type Minus = DefineLisp<LispType.Minus, Lisp, Lisp>;
160
+ export type Divide = DefineLisp<LispType.Divide, Lisp, Lisp>;
161
+ export type Power = DefineLisp<LispType.Power, Lisp, Lisp>;
162
+ export type Multiply = DefineLisp<LispType.Multiply, Lisp, Lisp>;
163
+ export type Modulus = DefineLisp<LispType.Modulus, Lisp, Lisp>;
164
+ export type Block = DefineLisp<LispType.Block, Lisp[], LispType.None>;
165
+ export type Expression = DefineLisp<LispType.Expression, Lisp[], LispType.None>;
166
+ export type Return = DefineLisp<LispType.Return, LispType.None, Lisp>;
167
+ export type Throw = DefineLisp<LispType.Throw, LispType.None, Lisp>;
168
+ export type Switch = DefineLisp<LispType.Switch, Lisp, SwitchCase[]>;
169
+ export type SwitchCase = DefineLisp<LispType.SwitchCase, LispType.None | Lisp, Lisp[]>;
170
+ export type Var = DefineLisp<LispType.Var, string, Lisp | LispType.None>;
171
+ export type Let = DefineLisp<LispType.Let, string, Lisp | LispType.None>;
172
+ export type Const = DefineLisp<LispType.Const, string, Lisp | LispType.None>;
173
+ export type Number = DefineLisp<LispType.Number, LispType.None, string>;
174
+ export type BigInt = DefineLisp<LispType.BigInt, LispType.None, string>;
175
+ export type GlobalSymbol = DefineLisp<LispType.GlobalSymbol, LispType.None, string>;
176
+ export type LiteralIndex = DefineLisp<LispType.LiteralIndex, LispType.None, string>;
177
+ export type StringIndex = DefineLisp<LispType.StringIndex, LispType.None, string>;
178
+ export type RegexIndex = DefineLisp<LispType.RegexIndex, LispType.None, string>;
179
+ export type Function = DefineLisp<LispType.Function, (string | LispType.None | LispType.True)[], string | Lisp[]>;
180
+ export type InlineFunction = DefineLisp<LispType.InlineFunction, string[], string | Lisp[]>;
181
+ export type ArrowFunction = DefineLisp<LispType.ArrowFunction, string[], string | Lisp[]>;
182
+ export type Loop = DefineLisp<LispType.Loop, LispItem, Lisp[]>;
183
+ export type LoopAction = DefineLisp<LispType.LoopAction, string, LispType.None>;
184
+ export type Try = DefineLisp<LispType.Try, Lisp[], LispItem>;
185
+ export type Void = DefineLisp<LispType.Void, Lisp, LispType.None>;
186
+ export type Await = DefineLisp<LispType.Await, Lisp, LispType.None>;
187
+ export type New = DefineLisp<LispType.New, Lisp, Lisp[]>;
188
+ export type None = DefineLisp<LispType.None, LispType.None, LispType.None>;
189
+ export type LispFamily = Literal | If | InlineIf | IfCase | InlineIfCase | KeyVal | SpreadObject | SpreadArray | ArrayProp | Prop | PropOptional | Call | CallOptional | CreateArray | CreateObject | Group | Inverse | Not | Negative | Positive | Typeof | Delete | IncrementBefore | IncrementAfter | DecrementBefore | DecrementAfter | And | Or | Instanceof | In | Assigns | SubractEquals | AddEquals | DivideEquals | PowerEquals | MultiplyEquals | ModulusEquals | BitNegateEquals | BitAndEquals | BitOrEquals | UnsignedShiftRightEquals | ShiftLeftEquals | ShiftRightEquals | BitAnd | BitOr | BitNegate | BitShiftLeft | BitShiftRight | BitUnsignedShiftRight | SmallerEqualThan | LargerEqualThan | SmallerThan | LargerThan | StrictNotEqual | NotEqual | StrictEqual | Equal | Plus | Minus | Divide | Power | Multiply | Modulus | Block | Expression | Return | Throw | Switch | SwitchCase | Var | Let | Const | Number | BigInt | GlobalSymbol | LiteralIndex | StringIndex | RegexIndex | Function | InlineFunction | ArrowFunction | Loop | LoopAction | Try | Void | Await | New | None;
12
190
  export interface IRegEx {
13
191
  regex: string;
14
192
  flags: string;
@@ -16,57 +194,147 @@ export interface IRegEx {
16
194
  }
17
195
  export interface IConstants {
18
196
  strings: string[];
19
- literals: ILiteral[];
197
+ literals: Literal[];
20
198
  regexes: IRegEx[];
21
199
  eager: boolean;
22
200
  }
23
201
  export interface IExecutionTree {
24
- tree: LispArray;
202
+ tree: Lisp[];
25
203
  constants: IConstants;
26
204
  }
27
- declare type LispCallback = (strings: IConstants, type: string, part: CodeString, res: string[], expect: string, ctx: {
28
- lispTree: LispItem;
205
+ type LispCallback<T> = (strings: IConstants, type: T, part: CodeString, res: string[], expect: string, ctx: {
206
+ lispTree: Lisp;
29
207
  }) => any;
30
208
  export declare class ParseError extends Error {
31
209
  code: string;
32
210
  constructor(message: string, code: string);
33
211
  }
34
- export declare class Lisp {
35
- op: string;
36
- a?: LispItem;
37
- b?: LispItem;
38
- constructor(obj: Lisp);
39
- }
40
- export declare class If {
41
- t: any;
42
- f: any;
43
- constructor(t: any, f: any);
44
- }
45
- export declare class KeyVal {
46
- key: string;
47
- val: any;
48
- constructor(key: string, val: any);
49
- }
50
- export declare class SpreadObject {
51
- item: {
52
- [key: string]: any;
53
- };
54
- constructor(item: {
55
- [key: string]: any;
56
- });
57
- }
58
- export declare class SpreadArray {
59
- item: any[];
60
- constructor(item: any[]);
61
- }
62
- export declare const lispArrayKey: {};
63
- export declare function toLispArray(arr: LispItem[]): LispArray;
64
212
  export declare let expectTypes: {
65
- [type: string]: {
66
- types: {
67
- [type: string]: RegExp;
213
+ readonly splitter: {
214
+ readonly types: {
215
+ readonly opHigh: RegExp;
216
+ readonly op: RegExp;
217
+ readonly comparitor: RegExp;
218
+ readonly boolOp: RegExp;
219
+ readonly bitwise: RegExp;
220
+ };
221
+ readonly next: readonly ["modifier", "value", "prop", "incrementerBefore"];
222
+ };
223
+ readonly inlineIf: {
224
+ readonly types: {
225
+ readonly inlineIf: RegExp;
226
+ };
227
+ readonly next: readonly ["expEnd"];
228
+ };
229
+ readonly assignment: {
230
+ readonly types: {
231
+ readonly assignModify: RegExp;
232
+ readonly assign: RegExp;
233
+ };
234
+ readonly next: readonly ["modifier", "value", "prop", "incrementerBefore"];
235
+ };
236
+ readonly incrementerBefore: {
237
+ readonly types: {
238
+ readonly incrementerBefore: RegExp;
239
+ };
240
+ readonly next: readonly ["prop"];
241
+ };
242
+ readonly expEdge: {
243
+ readonly types: {
244
+ readonly call: RegExp;
245
+ readonly incrementerAfter: RegExp;
246
+ };
247
+ readonly next: readonly ["splitter", "expEdge", "dot", "inlineIf", "expEnd"];
248
+ };
249
+ readonly modifier: {
250
+ readonly types: {
251
+ readonly not: RegExp;
252
+ readonly inverse: RegExp;
253
+ readonly negative: RegExp;
254
+ readonly positive: RegExp;
255
+ readonly typeof: RegExp;
256
+ readonly delete: RegExp;
257
+ };
258
+ readonly next: readonly ["modifier", "value", "prop", "incrementerBefore"];
259
+ };
260
+ readonly dot: {
261
+ readonly types: {
262
+ readonly arrayProp: RegExp;
263
+ readonly dot: RegExp;
264
+ };
265
+ readonly next: readonly ["splitter", "assignment", "expEdge", "dot", "inlineIf", "expEnd"];
266
+ };
267
+ readonly prop: {
268
+ readonly types: {
269
+ readonly prop: RegExp;
270
+ };
271
+ readonly next: readonly ["splitter", "assignment", "expEdge", "dot", "inlineIf", "expEnd"];
272
+ };
273
+ readonly value: {
274
+ readonly types: {
275
+ readonly createObject: RegExp;
276
+ readonly createArray: RegExp;
277
+ readonly number: RegExp;
278
+ readonly string: RegExp;
279
+ readonly literal: RegExp;
280
+ readonly regex: RegExp;
281
+ readonly boolean: RegExp;
282
+ readonly null: RegExp;
283
+ readonly und: RegExp;
284
+ readonly arrowFunctionSingle: RegExp;
285
+ readonly arrowFunction: RegExp;
286
+ readonly inlineFunction: RegExp;
287
+ readonly group: RegExp;
288
+ readonly NaN: RegExp;
289
+ readonly Infinity: RegExp;
290
+ readonly void: RegExp;
291
+ readonly await: RegExp;
292
+ readonly new: RegExp;
293
+ };
294
+ readonly next: readonly ["splitter", "expEdge", "dot", "inlineIf", "expEnd"];
295
+ };
296
+ readonly initialize: {
297
+ readonly types: {
298
+ readonly initialize: RegExp;
299
+ readonly return: RegExp;
300
+ readonly throw: RegExp;
301
+ };
302
+ readonly next: readonly ["modifier", "value", "prop", "incrementerBefore", "expEnd"];
303
+ };
304
+ readonly spreadObject: {
305
+ readonly types: {
306
+ readonly spreadObject: RegExp;
307
+ };
308
+ readonly next: readonly ["value", "prop"];
309
+ };
310
+ readonly spreadArray: {
311
+ readonly types: {
312
+ readonly spreadArray: RegExp;
313
+ };
314
+ readonly next: readonly ["value", "prop"];
315
+ };
316
+ readonly expEnd: {
317
+ readonly types: {};
318
+ readonly next: readonly [];
319
+ };
320
+ readonly expFunction: {
321
+ readonly types: {
322
+ readonly function: RegExp;
323
+ };
324
+ readonly next: readonly ["expEdge", "expEnd"];
325
+ };
326
+ readonly expSingle: {
327
+ readonly types: {
328
+ readonly for: RegExp;
329
+ readonly do: RegExp;
330
+ readonly while: RegExp;
331
+ readonly loopAction: RegExp;
332
+ readonly if: RegExp;
333
+ readonly try: RegExp;
334
+ readonly block: RegExp;
335
+ readonly switch: RegExp;
68
336
  };
69
- next: string[];
337
+ readonly next: readonly ["expEnd"];
70
338
  };
71
339
  };
72
340
  export declare function testMultiple(str: string, tests: RegExp[]): RegExpExecArray;
@@ -97,10 +365,11 @@ export declare function restOfExp(constants: IConstants, part: CodeString, tests
97
365
  export declare namespace restOfExp {
98
366
  var next: string[];
99
367
  }
100
- export declare const setLispType: (types: string[], fn: LispCallback) => void;
101
- export declare function lispifyReturnExpr(constants: IConstants, str: CodeString): Lisp;
102
- export declare function lispifyBlock(str: CodeString, constants: IConstants, expression?: boolean): LispArray;
103
- export declare function lispifyFunction(str: CodeString, constants: IConstants, expression?: boolean): LispArray;
368
+ export declare const setLispType: <T extends readonly string[]>(types: T, fn: LispCallback<T[number]>) => void;
369
+ export declare function lispifyReturnExpr(constants: IConstants, str: CodeString): Return;
370
+ export declare function lispifyBlock(str: CodeString, constants: IConstants, expression?: boolean): Lisp[];
371
+ export declare function lispifyFunction(str: CodeString, constants: IConstants, expression?: boolean): Lisp[];
372
+ export declare function isLisp<Type extends Lisp = Lisp>(item: LispItem | LispItem): item is Type;
104
373
  export declare function insertSemicolons(constants: IConstants, str: CodeString): CodeString;
105
374
  export declare function checkRegex(str: string): IRegEx | null;
106
375
  export declare function extractConstants(constants: IConstants, str: string, currentEnclosure?: string): {