forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmozilla-spidermonkey-parser-api.d.ts
614 lines (548 loc) · 19.8 KB
/
mozilla-spidermonkey-parser-api.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
// Type definitions for Mozilla SpiderMonkey Parser API 1.8.5
// Project: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API
// Definitions by: vvakame <https://github.com/vvakame/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module spiderMonkeyParserAPI {
// NOTE if property can hold null, that property to be optional.
module Syntax {
/**
* By default, Reflect.parse() produces Node objects, which are plain JavaScript objects (i.e., their prototype derives from the standard Object prototype).
* All node types implement the following interface:
*/
interface Node {
/**
* The type field is a string representing the AST variant type.
* Each subtype of Node is documented below with the specific string of its type field.
* You can use this field to determine which interface a node implements.
*/
type: string;
/**
* The loc field represents the source location information of the node.
* If the parser produced no information about the node's source location, the field is null; otherwise it is an object consisting of a start position (the position of the first character of the parsed source region) and an end position (the position of the first character after the parsed source region):
*/
loc?: SourceLocation;
}
interface SourceLocation {
source?: string;
start: Position;
end: Position;
}
/**
* Each Position object consists of a line number (1-indexed) and a column number (0-indexed):
*/
interface Position {
line: number; // uint32 >= 1;
column: number; // uint32 >= 0;
}
/**
* A complete program source tree.
*/
interface Program extends Node {
type: string; // "Program"
body: Statement[];
}
/**
* A function declaration or expression.
* The body of the function may be a block statement, or in the case of an expression closure, an expression.
* If the generator flag is true, the function is a generator function, i.e., contains a yield expression in its body (other than in a nested function).
* If the expression flag is true, the function is an expression closure and the body field is an expression.
*/
interface Function extends Node {
id?: Identifier;
params: Pattern[];
defaults: Expression[];
rest?: Identifier;
body?: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
/**
* Any statement.
*/
interface Statement extends Node {
}
/**
* An empty statement, i.e., a solitary semicolon.
*/
interface EmptyStatement extends Statement {
type: string; // "EmptyStatement";
}
/**
* A block statement, i.e., a sequence of statements surrounded by braces.
*/
interface BlockStatement extends Statement {
type: string; // "BlockStatement";
body: Statement[];
}
/**
* An if statement.
*/
interface IfStatement extends Statement {
type: string; // "IfStatement";
test: Expression;
consequent: Statement;
alternate?: Statement;
}
/**
* A labeled statement, i.e., a statement prefixed by a break/continue label.
*/
interface LabeledStatement extends Statement {
type: string; // "LabeledStatement";
label: Identifier;
body: Statement;
}
/**
* A break statement.
*/
interface BreakStatement extends Statement {
type: string; // "BreakStatement";
label?: Identifier;
}
/**
* A continue statement.
*/
interface ContinueStatement extends Statement {
type: string; // "ContinueStatement";
label?: Identifier;
}
/**
* A with statement.
*/
interface WithStatement extends Statement {
type: string; // "WithStatement";
object: Expression;
body: Statement;
}
/**
* A switch statement.
* The lexical flag is metadata indicating whether the switch statement contains any unnested let declarations (and therefore introduces a new lexical scope).
*/
interface SwitchStatement extends Statement {
type: string; // "SwitchStatement";
discriminant: Expression;
cases: SwitchCase[];
lexical: boolean;
}
/**
* A return statement.
*/
interface ReturnStatement extends Statement {
type: string; // "ReturnStatement";
argument?: Expression;
}
/**
* A throw statement.
*/
interface ThrowStatement extends Statement {
type: string; // "ThrowStatement";
argument: Expression;
}
/**
* A try statement.
*/
interface TryStatement extends Statement {
type: string; //"TryStatement";
block: BlockStatement;
handler?: CatchClause;
guardedHandlers: CatchClause[];
finalizer?: BlockStatement;
}
/**
* A while statement.
*/
interface WhileStatement extends Statement {
type: string; // "WhileStatement";
test: Expression;
body: Statement;
}
/**
* A do/while statement.
*/
interface DoWhileStatement extends Statement {
type: string; // "DoWhileStatement";
body: Statement;
test: Expression;
}
/**
* A for statement.
*/
interface ForStatement extends Statement {
type: string; // "ForStatement";
init?: VariableDeclaration | Expression;
test?: Expression;
update?: Expression;
body: Statement;
}
/**
* A for/in statement, or, if each is true, a for each/in statement.
*/
interface ForInStatement extends Statement {
type: string; // "ForInStatement";
left: VariableDeclaration | Expression;
right: Expression;
body: Statement;
each: boolean;
}
/**
* A for/of statement.
*/
interface ForOfStatement extends Statement {
type: string; // "ForOfStatement";
left: VariableDeclaration | Expression;
right: Expression;
body: Statement;
}
/**
* A let statement.
*/
interface LetStatement extends Statement {
type: string; // "LetStatement";
head: VariableDeclarator[];
body: Statement;
}
/**
* A debugger statement.
*/
interface DebuggerStatement extends Statement {
type: string; // "DebuggerStatement";
}
/**
* Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context in the language recognized by the SpiderMonkey parser.
*/
interface Declaration extends Statement {
}
/**
* A function declaration.
*/
interface FunctionDeclaration extends Function, Declaration {
type: string; // "FunctionDeclaration";
id: Identifier; // Note: The id field cannot be null.
params: Pattern[];
defaults: Expression[];
rest?: Identifier;
body: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
/**
* A variable declaration, via one of var, let, or const.
*/
interface VariableDeclaration extends Declaration {
type: string; // "VariableDeclaration";
declarations: VariableDeclarator[];
kind: string; // "var" | "let" | "const";
}
/**
* A variable declarator.
*/
interface VariableDeclarator extends Node {
type: string; // "VariableDeclarator";
id: Pattern; // Note: The id field cannot be null.
init?: Expression;
}
/**
* Any expression node.
* Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.
*/
interface Expression extends Node, Pattern {
}
/**
* A this expression.
*/
interface ThisExpression extends Expression {
type: string; // "ThisExpression";
}
/**
* An array expression.
*/
interface ArrayExpression extends Expression {
type: string; // "ArrayExpression";
elements: Expression[]; // [ Expression | null ];
}
/**
* An object expression.
*/
interface ObjectExpression extends Expression {
type: string; // "ObjectExpression";
properties: Property[];
}
/**
* A literal property in an object expression can have either a string or number as its value.
* Ordinary property initializers have a kind value "init"; getters and setters have the kind values "get" and "set", respectively.
*/
interface Property extends Node {
type: string; // "Property";
key: Literal | Identifier;
value: Expression;
kind: string; // "init" | "get" | "set";
}
/**
* A function expression.
*/
interface FunctionExpression extends Function, Expression {
type: string; // "FunctionExpression";
id?: Identifier;
params: Pattern[];
defaults: Expression[];
rest?: Identifier;
body: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
/**
* A fat arrow function expression, i.e., `let foo = (bar) => { ... body ... }`.
*/
interface ArrowExpression extends Function, Expression {
type: string; // "ArrowExpression";
params: Pattern[];
defaults: Expression[];
rest?: Identifier;
body: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
/**
* A sequence expression, i.e., a comma-separated sequence of expressions.
*/
interface SequenceExpression extends Expression {
type: string; // "SequenceExpression";
expressions: Expression[];
}
/**
* A unary operator expression.
*/
interface UnaryExpression extends Expression {
type: string; // "UnaryExpression";
operator: UnaryOperator;
prefix: boolean;
argument: Expression;
}
/**
* A binary operator expression.
*/
interface BinaryExpression extends Expression {
type: string; // "BinaryExpression";
operator: BinaryOperator;
left: Expression;
right: Expression;
}
/**
* An assignment operator expression.
*/
interface AssignmentExpression extends Expression {
type: string; // "AssignmentExpression";
operator: AssignmentOperator;
left: Expression;
right: Expression;
}
/**
* An update (increment or decrement) operator expression.
*/
interface UpdateExpression extends Expression {
type: string; // "UpdateExpression";
operator: UpdateOperator;
argument: Expression;
prefix: boolean;
}
/**
* A logical operator expression.
*/
interface LogicalExpression extends Expression {
type: string; // "LogicalExpression";
operator: LogicalOperator;
left: Expression;
right: Expression;
}
/**
* A conditional expression, i.e., a ternary ?/: expression.
*/
interface ConditionalExpression extends Expression {
type: string; // "ConditionalExpression";
test: Expression;
alternate: Expression;
consequent: Expression;
}
/**
* A new expression.
*/
interface NewExpression extends Expression {
type: string; // "NewExpression";
callee: Expression;
arguments: Expression[];
}
/**
* A function or method call expression.
*/
interface CallExpression extends Expression {
type: string; // "CallExpression";
callee: Expression;
arguments: Expression[];
}
/**
* A member expression.
* If computed === true, the node corresponds to a computed e1[e2] expression and property is an Expression.
* If computed === false, the node corresponds to a static e1.x expression and property is an Identifier.
*/
interface MemberExpression extends Expression {
type: string; // "MemberExpression";
object: Expression;
property: Identifier | Expression;
computed: boolean;
}
/**
* A yield expression.
*/
interface YieldExpression extends Expression {
type: string; // "YieldExpression";
argument?: Expression;
}
/**
* An array comprehension.
* The blocks array corresponds to the sequence of for and for each blocks.
* The optional filter expression corresponds to the final if clause, if present.
*/
interface ComprehensionExpression extends Expression {
type: string; // "ComprehensionExpression";
body: Expression;
blocks: ComprehensionBlock[];
filter?: Expression;
}
/**
* A generator expression.
* As with array comprehensions, the blocks array corresponds to the sequence of for and for each blocks, and the optional filter expression corresponds to the final if clause, if present.
*/
interface GeneratorExpression extends Expression {
type: string; // "GeneratorExpression";
body: Expression;
blocks: ComprehensionBlock[];
filter?: Expression;
}
/**
* A graph expression, aka "sharp literal," such as #1={ self: #1# }.
*/
interface GraphExpression extends Expression {
type: string; // "GraphExpression";
index: number; // uint32;
expression: Literal;
}
/**
* A graph index expression, aka "sharp variable," such as #1#.
*/
interface GraphIndexExpression extends Expression {
type: string; // "GraphIndexExpression";
index: number; // uint32;
}
/**
* A let expression.
*/
interface LetExpression extends Expression {
type: string; // "LetExpression";
head: VariableDeclarator[];
body: Expression;
}
/**
* JavaScript 1.7 introduced destructuring assignment and binding forms.
* All binding forms (such as function parameters, variable declarations, and catch block headers) accept array and object destructuring patterns in addition to plain identifiers.
* The left-hand sides of assignment expressions can be arbitrary expressions, but in the case where the expression is an object or array literal, it is interpreted by SpiderMonkey as a destructuring pattern.
*
* Since the left-hand side of an assignment can in general be any expression, in an assignment context, a pattern can be any expression.
* In binding positions (such as function parameters, variable declarations, and catch headers), patterns can only be identifiers in the base case, not arbitrary expressions.
*/
interface Pattern extends Node {
}
/**
* An object-destructuring pattern. A literal property in an object pattern can have either a string or number as its value.
*/
interface ObjectPattern extends Pattern {
type: string; // "ObjectPattern";
properties: {key: Literal | Identifier; value: Pattern;}[]; // [ { key: Literal | Identifier, value: Pattern } ];
}
/**
* An array-destructuring pattern.
*/
interface ArrayPattern extends Pattern {
type: string; // "ArrayPattern";
elements: Pattern[]; // [ Pattern | null ];
}
/**
* A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement.
*/
interface SwitchCase extends Node {
type: string; // "SwitchCase";
test?: Expression;
consequent: Statement[];
}
/**
* A catch clause following a try block.
* The optional guard property corresponds to the optional expression guard on the bound variable.
*/
interface CatchClause extends Node {
type: string; // "CatchClause";
param: Pattern;
guard?: Expression;
body: BlockStatement;
}
/**
* A for or for each block in an array comprehension or generator expression.
*/
interface ComprehensionBlock extends Node {
type: string; // "ComprehensionBlock";
left: Pattern;
right: Expression;
each: boolean;
}
/**
* An identifier.
* Note that an identifier may be an expression or a destructuring pattern.
*/
interface Identifier extends Node, Expression, Pattern {
type: string; // "Identifier";
name: string;
}
/**
* A literal token. Note that a literal can be an expression.
*/
interface Literal extends Node, Expression {
type: string; // "Literal";
value?: string | boolean | number | RegExp;
}
/**
* A unary operator token.
*/
interface UnaryOperator extends String {
// "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
}
/**
* A binary operator token.
*/
interface BinaryOperator extends String {
// "==" | "!=" | "===" | "!=="
// | "<" | "<=" | ">" | ">="
// | "<<" | ">>" | ">>>"
// | "+" | "-" | "*" | "/" | "%"
// | "|" | "^" | "&" | "in"
// | "instanceof" | ".."
// Note: The .. operator is E4X-specific.
}
/**
* A logical operator token.
*/
interface LogicalOperator extends String {
// "||" | "&&"
}
/**
* An assignment operator token.
*/
interface AssignmentOperator extends String {
// "=" | "+=" | "-=" | "*=" | "/=" | "%="
// | "<<=" | ">>=" | ">>>="
// | "|=" | "^=" | "&="
}
/**
* An update (increment or decrement) operator token.
*/
interface UpdateOperator extends String {
// "++" | "--"
}
}
}