1"use strict";
2
3var _index = require("../index");
4
5var t = _interopRequireWildcard(_index);
6
7var _constants = require("../constants");
8
9var _index2 = require("./index");
10
11var _index3 = _interopRequireDefault(_index2);
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
16
17(0, _index3.default)("ArrayExpression", {
18  fields: {
19    elements: {
20      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeOrValueType)("null", "Expression", "SpreadElement"))),
21      default: []
22    }
23  },
24  visitor: ["elements"],
25  aliases: ["Expression"]
26});
27
28(0, _index3.default)("AssignmentExpression", {
29  fields: {
30    operator: {
31      validate: (0, _index2.assertValueType)("string")
32    },
33    left: {
34      validate: (0, _index2.assertNodeType)("LVal")
35    },
36    right: {
37      validate: (0, _index2.assertNodeType)("Expression")
38    }
39  },
40  builder: ["operator", "left", "right"],
41  visitor: ["left", "right"],
42  aliases: ["Expression"]
43});
44
45(0, _index3.default)("BinaryExpression", {
46  builder: ["operator", "left", "right"],
47  fields: {
48    operator: {
49      validate: _index2.assertOneOf.apply(undefined, _constants.BINARY_OPERATORS)
50    },
51    left: {
52      validate: (0, _index2.assertNodeType)("Expression")
53    },
54    right: {
55      validate: (0, _index2.assertNodeType)("Expression")
56    }
57  },
58  visitor: ["left", "right"],
59  aliases: ["Binary", "Expression"]
60});
61
62(0, _index3.default)("Directive", {
63  visitor: ["value"],
64  fields: {
65    value: {
66      validate: (0, _index2.assertNodeType)("DirectiveLiteral")
67    }
68  }
69});
70
71(0, _index3.default)("DirectiveLiteral", {
72  builder: ["value"],
73  fields: {
74    value: {
75      validate: (0, _index2.assertValueType)("string")
76    }
77  }
78});
79
80(0, _index3.default)("BlockStatement", {
81  builder: ["body", "directives"],
82  visitor: ["directives", "body"],
83  fields: {
84    directives: {
85      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Directive"))),
86      default: []
87    },
88    body: {
89      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Statement")))
90    }
91  },
92  aliases: ["Scopable", "BlockParent", "Block", "Statement"]
93});
94
95(0, _index3.default)("BreakStatement", {
96  visitor: ["label"],
97  fields: {
98    label: {
99      validate: (0, _index2.assertNodeType)("Identifier"),
100      optional: true
101    }
102  },
103  aliases: ["Statement", "Terminatorless", "CompletionStatement"]
104});
105
106(0, _index3.default)("CallExpression", {
107  visitor: ["callee", "arguments"],
108  fields: {
109    callee: {
110      validate: (0, _index2.assertNodeType)("Expression")
111    },
112    arguments: {
113      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Expression", "SpreadElement")))
114    }
115  },
116  aliases: ["Expression"]
117});
118
119(0, _index3.default)("CatchClause", {
120  visitor: ["param", "body"],
121  fields: {
122    param: {
123      validate: (0, _index2.assertNodeType)("Identifier")
124    },
125    body: {
126      validate: (0, _index2.assertNodeType)("BlockStatement")
127    }
128  },
129  aliases: ["Scopable"]
130});
131
132(0, _index3.default)("ConditionalExpression", {
133  visitor: ["test", "consequent", "alternate"],
134  fields: {
135    test: {
136      validate: (0, _index2.assertNodeType)("Expression")
137    },
138    consequent: {
139      validate: (0, _index2.assertNodeType)("Expression")
140    },
141    alternate: {
142      validate: (0, _index2.assertNodeType)("Expression")
143    }
144  },
145  aliases: ["Expression", "Conditional"]
146});
147
148(0, _index3.default)("ContinueStatement", {
149  visitor: ["label"],
150  fields: {
151    label: {
152      validate: (0, _index2.assertNodeType)("Identifier"),
153      optional: true
154    }
155  },
156  aliases: ["Statement", "Terminatorless", "CompletionStatement"]
157});
158
159(0, _index3.default)("DebuggerStatement", {
160  aliases: ["Statement"]
161});
162
163(0, _index3.default)("DoWhileStatement", {
164  visitor: ["test", "body"],
165  fields: {
166    test: {
167      validate: (0, _index2.assertNodeType)("Expression")
168    },
169    body: {
170      validate: (0, _index2.assertNodeType)("Statement")
171    }
172  },
173  aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"]
174});
175
176(0, _index3.default)("EmptyStatement", {
177  aliases: ["Statement"]
178});
179
180(0, _index3.default)("ExpressionStatement", {
181  visitor: ["expression"],
182  fields: {
183    expression: {
184      validate: (0, _index2.assertNodeType)("Expression")
185    }
186  },
187  aliases: ["Statement", "ExpressionWrapper"]
188});
189
190(0, _index3.default)("File", {
191  builder: ["program", "comments", "tokens"],
192  visitor: ["program"],
193  fields: {
194    program: {
195      validate: (0, _index2.assertNodeType)("Program")
196    }
197  }
198});
199
200(0, _index3.default)("ForInStatement", {
201  visitor: ["left", "right", "body"],
202  aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
203  fields: {
204    left: {
205      validate: (0, _index2.assertNodeType)("VariableDeclaration", "LVal")
206    },
207    right: {
208      validate: (0, _index2.assertNodeType)("Expression")
209    },
210    body: {
211      validate: (0, _index2.assertNodeType)("Statement")
212    }
213  }
214});
215
216(0, _index3.default)("ForStatement", {
217  visitor: ["init", "test", "update", "body"],
218  aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"],
219  fields: {
220    init: {
221      validate: (0, _index2.assertNodeType)("VariableDeclaration", "Expression"),
222      optional: true
223    },
224    test: {
225      validate: (0, _index2.assertNodeType)("Expression"),
226      optional: true
227    },
228    update: {
229      validate: (0, _index2.assertNodeType)("Expression"),
230      optional: true
231    },
232    body: {
233      validate: (0, _index2.assertNodeType)("Statement")
234    }
235  }
236});
237
238(0, _index3.default)("FunctionDeclaration", {
239  builder: ["id", "params", "body", "generator", "async"],
240  visitor: ["id", "params", "body", "returnType", "typeParameters"],
241  fields: {
242    id: {
243      validate: (0, _index2.assertNodeType)("Identifier")
244    },
245    params: {
246      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("LVal")))
247    },
248    body: {
249      validate: (0, _index2.assertNodeType)("BlockStatement")
250    },
251    generator: {
252      default: false,
253      validate: (0, _index2.assertValueType)("boolean")
254    },
255    async: {
256      default: false,
257      validate: (0, _index2.assertValueType)("boolean")
258    }
259  },
260  aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pureish", "Declaration"]
261});
262
263(0, _index3.default)("FunctionExpression", {
264  inherits: "FunctionDeclaration",
265  aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"],
266  fields: {
267    id: {
268      validate: (0, _index2.assertNodeType)("Identifier"),
269      optional: true
270    },
271    params: {
272      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("LVal")))
273    },
274    body: {
275      validate: (0, _index2.assertNodeType)("BlockStatement")
276    },
277    generator: {
278      default: false,
279      validate: (0, _index2.assertValueType)("boolean")
280    },
281    async: {
282      default: false,
283      validate: (0, _index2.assertValueType)("boolean")
284    }
285  }
286});
287
288(0, _index3.default)("Identifier", {
289  builder: ["name"],
290  visitor: ["typeAnnotation"],
291  aliases: ["Expression", "LVal"],
292  fields: {
293    name: {
294      validate: function validate(node, key, val) {
295        if (!t.isValidIdentifier(val)) {}
296      }
297    },
298    decorators: {
299      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Decorator")))
300    }
301  }
302});
303
304(0, _index3.default)("IfStatement", {
305  visitor: ["test", "consequent", "alternate"],
306  aliases: ["Statement", "Conditional"],
307  fields: {
308    test: {
309      validate: (0, _index2.assertNodeType)("Expression")
310    },
311    consequent: {
312      validate: (0, _index2.assertNodeType)("Statement")
313    },
314    alternate: {
315      optional: true,
316      validate: (0, _index2.assertNodeType)("Statement")
317    }
318  }
319});
320
321(0, _index3.default)("LabeledStatement", {
322  visitor: ["label", "body"],
323  aliases: ["Statement"],
324  fields: {
325    label: {
326      validate: (0, _index2.assertNodeType)("Identifier")
327    },
328    body: {
329      validate: (0, _index2.assertNodeType)("Statement")
330    }
331  }
332});
333
334(0, _index3.default)("StringLiteral", {
335  builder: ["value"],
336  fields: {
337    value: {
338      validate: (0, _index2.assertValueType)("string")
339    }
340  },
341  aliases: ["Expression", "Pureish", "Literal", "Immutable"]
342});
343
344(0, _index3.default)("NumericLiteral", {
345  builder: ["value"],
346  deprecatedAlias: "NumberLiteral",
347  fields: {
348    value: {
349      validate: (0, _index2.assertValueType)("number")
350    }
351  },
352  aliases: ["Expression", "Pureish", "Literal", "Immutable"]
353});
354
355(0, _index3.default)("NullLiteral", {
356  aliases: ["Expression", "Pureish", "Literal", "Immutable"]
357});
358
359(0, _index3.default)("BooleanLiteral", {
360  builder: ["value"],
361  fields: {
362    value: {
363      validate: (0, _index2.assertValueType)("boolean")
364    }
365  },
366  aliases: ["Expression", "Pureish", "Literal", "Immutable"]
367});
368
369(0, _index3.default)("RegExpLiteral", {
370  builder: ["pattern", "flags"],
371  deprecatedAlias: "RegexLiteral",
372  aliases: ["Expression", "Literal"],
373  fields: {
374    pattern: {
375      validate: (0, _index2.assertValueType)("string")
376    },
377    flags: {
378      validate: (0, _index2.assertValueType)("string"),
379      default: ""
380    }
381  }
382});
383
384(0, _index3.default)("LogicalExpression", {
385  builder: ["operator", "left", "right"],
386  visitor: ["left", "right"],
387  aliases: ["Binary", "Expression"],
388  fields: {
389    operator: {
390      validate: _index2.assertOneOf.apply(undefined, _constants.LOGICAL_OPERATORS)
391    },
392    left: {
393      validate: (0, _index2.assertNodeType)("Expression")
394    },
395    right: {
396      validate: (0, _index2.assertNodeType)("Expression")
397    }
398  }
399});
400
401(0, _index3.default)("MemberExpression", {
402  builder: ["object", "property", "computed"],
403  visitor: ["object", "property"],
404  aliases: ["Expression", "LVal"],
405  fields: {
406    object: {
407      validate: (0, _index2.assertNodeType)("Expression")
408    },
409    property: {
410      validate: function validate(node, key, val) {
411        var expectedType = node.computed ? "Expression" : "Identifier";
412        (0, _index2.assertNodeType)(expectedType)(node, key, val);
413      }
414    },
415    computed: {
416      default: false
417    }
418  }
419});
420
421(0, _index3.default)("NewExpression", {
422  visitor: ["callee", "arguments"],
423  aliases: ["Expression"],
424  fields: {
425    callee: {
426      validate: (0, _index2.assertNodeType)("Expression")
427    },
428    arguments: {
429      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Expression", "SpreadElement")))
430    }
431  }
432});
433
434(0, _index3.default)("Program", {
435  visitor: ["directives", "body"],
436  builder: ["body", "directives"],
437  fields: {
438    directives: {
439      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Directive"))),
440      default: []
441    },
442    body: {
443      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Statement")))
444    }
445  },
446  aliases: ["Scopable", "BlockParent", "Block", "FunctionParent"]
447});
448
449(0, _index3.default)("ObjectExpression", {
450  visitor: ["properties"],
451  aliases: ["Expression"],
452  fields: {
453    properties: {
454      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("ObjectMethod", "ObjectProperty", "SpreadProperty")))
455    }
456  }
457});
458
459(0, _index3.default)("ObjectMethod", {
460  builder: ["kind", "key", "params", "body", "computed"],
461  fields: {
462    kind: {
463      validate: (0, _index2.chain)((0, _index2.assertValueType)("string"), (0, _index2.assertOneOf)("method", "get", "set")),
464      default: "method"
465    },
466    computed: {
467      validate: (0, _index2.assertValueType)("boolean"),
468      default: false
469    },
470    key: {
471      validate: function validate(node, key, val) {
472        var expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"];
473        _index2.assertNodeType.apply(undefined, expectedTypes)(node, key, val);
474      }
475    },
476    decorators: {
477      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Decorator")))
478    },
479    body: {
480      validate: (0, _index2.assertNodeType)("BlockStatement")
481    },
482    generator: {
483      default: false,
484      validate: (0, _index2.assertValueType)("boolean")
485    },
486    async: {
487      default: false,
488      validate: (0, _index2.assertValueType)("boolean")
489    }
490  },
491  visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
492  aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"]
493});
494
495(0, _index3.default)("ObjectProperty", {
496  builder: ["key", "value", "computed", "shorthand", "decorators"],
497  fields: {
498    computed: {
499      validate: (0, _index2.assertValueType)("boolean"),
500      default: false
501    },
502    key: {
503      validate: function validate(node, key, val) {
504        var expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"];
505        _index2.assertNodeType.apply(undefined, expectedTypes)(node, key, val);
506      }
507    },
508    value: {
509      validate: (0, _index2.assertNodeType)("Expression", "Pattern", "RestElement")
510    },
511    shorthand: {
512      validate: (0, _index2.assertValueType)("boolean"),
513      default: false
514    },
515    decorators: {
516      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Decorator"))),
517      optional: true
518    }
519  },
520  visitor: ["key", "value", "decorators"],
521  aliases: ["UserWhitespacable", "Property", "ObjectMember"]
522});
523
524(0, _index3.default)("RestElement", {
525  visitor: ["argument", "typeAnnotation"],
526  aliases: ["LVal"],
527  fields: {
528    argument: {
529      validate: (0, _index2.assertNodeType)("LVal")
530    },
531    decorators: {
532      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Decorator")))
533    }
534  }
535});
536
537(0, _index3.default)("ReturnStatement", {
538  visitor: ["argument"],
539  aliases: ["Statement", "Terminatorless", "CompletionStatement"],
540  fields: {
541    argument: {
542      validate: (0, _index2.assertNodeType)("Expression"),
543      optional: true
544    }
545  }
546});
547
548(0, _index3.default)("SequenceExpression", {
549  visitor: ["expressions"],
550  fields: {
551    expressions: {
552      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Expression")))
553    }
554  },
555  aliases: ["Expression"]
556});
557
558(0, _index3.default)("SwitchCase", {
559  visitor: ["test", "consequent"],
560  fields: {
561    test: {
562      validate: (0, _index2.assertNodeType)("Expression"),
563      optional: true
564    },
565    consequent: {
566      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("Statement")))
567    }
568  }
569});
570
571(0, _index3.default)("SwitchStatement", {
572  visitor: ["discriminant", "cases"],
573  aliases: ["Statement", "BlockParent", "Scopable"],
574  fields: {
575    discriminant: {
576      validate: (0, _index2.assertNodeType)("Expression")
577    },
578    cases: {
579      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("SwitchCase")))
580    }
581  }
582});
583
584(0, _index3.default)("ThisExpression", {
585  aliases: ["Expression"]
586});
587
588(0, _index3.default)("ThrowStatement", {
589  visitor: ["argument"],
590  aliases: ["Statement", "Terminatorless", "CompletionStatement"],
591  fields: {
592    argument: {
593      validate: (0, _index2.assertNodeType)("Expression")
594    }
595  }
596});
597
598(0, _index3.default)("TryStatement", {
599  visitor: ["block", "handler", "finalizer"],
600  aliases: ["Statement"],
601  fields: {
602    body: {
603      validate: (0, _index2.assertNodeType)("BlockStatement")
604    },
605    handler: {
606      optional: true,
607      handler: (0, _index2.assertNodeType)("BlockStatement")
608    },
609    finalizer: {
610      optional: true,
611      validate: (0, _index2.assertNodeType)("BlockStatement")
612    }
613  }
614});
615
616(0, _index3.default)("UnaryExpression", {
617  builder: ["operator", "argument", "prefix"],
618  fields: {
619    prefix: {
620      default: true
621    },
622    argument: {
623      validate: (0, _index2.assertNodeType)("Expression")
624    },
625    operator: {
626      validate: _index2.assertOneOf.apply(undefined, _constants.UNARY_OPERATORS)
627    }
628  },
629  visitor: ["argument"],
630  aliases: ["UnaryLike", "Expression"]
631});
632
633(0, _index3.default)("UpdateExpression", {
634  builder: ["operator", "argument", "prefix"],
635  fields: {
636    prefix: {
637      default: false
638    },
639    argument: {
640      validate: (0, _index2.assertNodeType)("Expression")
641    },
642    operator: {
643      validate: _index2.assertOneOf.apply(undefined, _constants.UPDATE_OPERATORS)
644    }
645  },
646  visitor: ["argument"],
647  aliases: ["Expression"]
648});
649
650(0, _index3.default)("VariableDeclaration", {
651  builder: ["kind", "declarations"],
652  visitor: ["declarations"],
653  aliases: ["Statement", "Declaration"],
654  fields: {
655    kind: {
656      validate: (0, _index2.chain)((0, _index2.assertValueType)("string"), (0, _index2.assertOneOf)("var", "let", "const"))
657    },
658    declarations: {
659      validate: (0, _index2.chain)((0, _index2.assertValueType)("array"), (0, _index2.assertEach)((0, _index2.assertNodeType)("VariableDeclarator")))
660    }
661  }
662});
663
664(0, _index3.default)("VariableDeclarator", {
665  visitor: ["id", "init"],
666  fields: {
667    id: {
668      validate: (0, _index2.assertNodeType)("LVal")
669    },
670    init: {
671      optional: true,
672      validate: (0, _index2.assertNodeType)("Expression")
673    }
674  }
675});
676
677(0, _index3.default)("WhileStatement", {
678  visitor: ["test", "body"],
679  aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"],
680  fields: {
681    test: {
682      validate: (0, _index2.assertNodeType)("Expression")
683    },
684    body: {
685      validate: (0, _index2.assertNodeType)("BlockStatement", "Statement")
686    }
687  }
688});
689
690(0, _index3.default)("WithStatement", {
691  visitor: ["object", "body"],
692  aliases: ["Statement"],
693  fields: {
694    object: {
695      object: (0, _index2.assertNodeType)("Expression")
696    },
697    body: {
698      validate: (0, _index2.assertNodeType)("BlockStatement", "Statement")
699    }
700  }
701});