Debian Codegraph @

ast/node.go

raw symbols SCIP
1 // Package ast declares types representing a JavaScript AST.
2 //
3 // # Warning
4 // The parser and AST interfaces are still works-in-progress (particularly where
5 // node types are concerned) and may change in the future.
6 package ast
7
8 import (
9 "github.com/robertkrimen/otto/file"
10 "github.com/robertkrimen/otto/token"
11 )
12
13 // Node is implemented by types that represent a node.
14 type Node interface {
15 Idx0() file.Idx // The index of the first character belonging to the node
16 Idx1() file.Idx // The index of the first character immediately after the node
17 }
18
19 // Expression is implemented by types that represent an Expression.
20 type Expression interface {
21 Node
22 expression()
23 }
24
25 // ArrayLiteral represents an array literal.
26 type ArrayLiteral struct {
27 Value []Expression
28 LeftBracket file.Idx
29 RightBracket file.Idx
30 }
31
32 // Idx0 implements Node.
33 func (al *ArrayLiteral) Idx0() file.Idx {
34 return al.LeftBracket
35 }
36
37 // Idx1 implements Node.
38 func (al *ArrayLiteral) Idx1() file.Idx {
39 return al.RightBracket + 1
40 }
41
42 // expression implements Expression.
43 func (*ArrayLiteral) expression() {}
44
45 // AssignExpression represents an assignment expression.
46 type AssignExpression struct {
47 Left Expression
48 Right Expression
49 Operator token.Token
50 }
51
52 // Idx0 implements Node.
53 func (ae *AssignExpression) Idx0() file.Idx {
54 return ae.Left.Idx0()
55 }
56
57 // Idx1 implements Node.
58 func (ae *AssignExpression) Idx1() file.Idx {
59 return ae.Right.Idx1()
60 }
61
62 // expression implements Expression.
63 func (*AssignExpression) expression() {}
64
65 // BadExpression represents a bad expression.
66 type BadExpression struct {
67 From file.Idx
68 To file.Idx
69 }
70
71 // Idx0 implements Node.
72 func (be *BadExpression) Idx0() file.Idx {
73 return be.From
74 }
75
76 // Idx1 implements Node.
77 func (be *BadExpression) Idx1() file.Idx {
78 return be.To
79 }
80
81 // expression implements Expression.
82 func (*BadExpression) expression() {}
83
84 // BinaryExpression represents a binary expression.
85 type BinaryExpression struct {
86 Left Expression
87 Right Expression
88 Operator token.Token
89 Comparison bool
90 }
91
92 // Idx0 implements Node.
93 func (be *BinaryExpression) Idx0() file.Idx {
94 return be.Left.Idx0()
95 }
96
97 // Idx1 implements Node.
98 func (be *BinaryExpression) Idx1() file.Idx {
99 return be.Right.Idx1()
100 }
101
102 // expression implements Expression.
103 func (*BinaryExpression) expression() {}
104
105 // BooleanLiteral represents a boolean expression.
106 type BooleanLiteral struct {
107 Literal string
108 Idx file.Idx
109 Value bool
110 }
111
112 // Idx0 implements Node.
113 func (bl *BooleanLiteral) Idx0() file.Idx {
114 return bl.Idx
115 }
116
117 // Idx1 implements Node.
118 func (bl *BooleanLiteral) Idx1() file.Idx {
119 return file.Idx(int(bl.Idx) + len(bl.Literal))
120 }
121
122 // expression implements Expression.
123 func (*BooleanLiteral) expression() {}
124
125 // BracketExpression represents a bracketed expression.
126 type BracketExpression struct {
127 Left Expression
128 Member Expression
129 LeftBracket file.Idx
130 RightBracket file.Idx
131 }
132
133 // Idx0 implements Node.
134 func (be *BracketExpression) Idx0() file.Idx {
135 return be.Left.Idx0()
136 }
137
138 // Idx1 implements Node.
139 func (be *BracketExpression) Idx1() file.Idx {
140 return be.RightBracket + 1
141 }
142
143 // expression implements Expression.
144 func (*BracketExpression) expression() {}
145
146 // CallExpression represents a call expression.
147 type CallExpression struct {
148 Callee Expression
149 ArgumentList []Expression
150 LeftParenthesis file.Idx
151 RightParenthesis file.Idx
152 }
153
154 // Idx0 implements Node.
155 func (ce *CallExpression) Idx0() file.Idx {
156 return ce.Callee.Idx0()
157 }
158
159 // Idx1 implements Node.
160 func (ce *CallExpression) Idx1() file.Idx {
161 return ce.RightParenthesis + 1
162 }
163
164 // expression implements Expression.
165 func (*CallExpression) expression() {}
166
167 // ConditionalExpression represents a conditional expression.
168 type ConditionalExpression struct {
169 Test Expression
170 Consequent Expression
171 Alternate Expression
172 }
173
174 // Idx0 implements Node.
175 func (ce *ConditionalExpression) Idx0() file.Idx {
176 return ce.Test.Idx0()
177 }
178
179 // Idx1 implements Node.
180 func (ce *ConditionalExpression) Idx1() file.Idx {
181 return ce.Alternate.Idx1()
182 }
183
184 // expression implements Expression.
185 func (*ConditionalExpression) expression() {}
186
187 // DotExpression represents a dot expression.
188 type DotExpression struct {
189 Left Expression
190 Identifier *Identifier
191 }
192
193 // Idx0 implements Node.
194 func (de *DotExpression) Idx0() file.Idx {
195 return de.Left.Idx0()
196 }
197
198 // Idx1 implements Node.
199 func (de *DotExpression) Idx1() file.Idx {
200 return de.Identifier.Idx1()
201 }
202
203 // expression implements Expression.
204 func (*DotExpression) expression() {}
205
206 // EmptyExpression represents an empty expression.
207 type EmptyExpression struct {
208 Begin file.Idx
209 End file.Idx
210 }
211
212 // Idx0 implements Node.
213 func (ee *EmptyExpression) Idx0() file.Idx {
214 return ee.Begin
215 }
216
217 // Idx1 implements Node.
218 func (ee *EmptyExpression) Idx1() file.Idx {
219 return ee.End
220 }
221
222 // expression implements Expression.
223 func (*EmptyExpression) expression() {}
224
225 // FunctionLiteral represents a function literal.
226 type FunctionLiteral struct {
227 Body Statement
228 Name *Identifier
229 ParameterList *ParameterList
230 Source string
231 DeclarationList []Declaration
232 Function file.Idx
233 }
234
235 // Idx0 implements Node.
236 func (fl *FunctionLiteral) Idx0() file.Idx {
237 return fl.Function
238 }
239
240 // Idx1 implements Node.
241 func (fl *FunctionLiteral) Idx1() file.Idx {
242 return fl.Body.Idx1()
243 }
244
245 // expression implements Expression.
246 func (*FunctionLiteral) expression() {}
247
248 // Identifier represents an identifier.
249 type Identifier struct {
250 Name string
251 Idx file.Idx
252 }
253
254 // Idx0 implements Node.
255 func (i *Identifier) Idx0() file.Idx {
256 return i.Idx
257 }
258
259 // Idx1 implements Node.
260 func (i *Identifier) Idx1() file.Idx {
261 return file.Idx(int(i.Idx) + len(i.Name))
262 }
263
264 // expression implements Expression.
265 func (*Identifier) expression() {}
266
267 // NewExpression represents a new expression.
268 type NewExpression struct {
269 Callee Expression
270 ArgumentList []Expression
271 New file.Idx
272 LeftParenthesis file.Idx
273 RightParenthesis file.Idx
274 }
275
276 // Idx0 implements Node.
277 func (ne *NewExpression) Idx0() file.Idx {
278 return ne.New
279 }
280
281 // Idx1 implements Node.
282 func (ne *NewExpression) Idx1() file.Idx {
283 if ne.RightParenthesis > 0 {
284 return ne.RightParenthesis + 1
285 }
286 return ne.Callee.Idx1()
287 }
288
289 // expression implements Expression.
290 func (*NewExpression) expression() {}
291
292 // NullLiteral represents a null literal.
293 type NullLiteral struct {
294 Literal string
295 Idx file.Idx
296 }
297
298 // Idx0 implements Node.
299 func (nl *NullLiteral) Idx0() file.Idx {
300 return nl.Idx
301 }
302
303 // Idx1 implements Node.
304 func (nl *NullLiteral) Idx1() file.Idx {
305 return file.Idx(int(nl.Idx) + 4)
306 }
307
308 // expression implements Expression.
309 func (*NullLiteral) expression() {}
310
311 // NumberLiteral represents a number literal.
312 type NumberLiteral struct {
313 Value interface{}
314 Literal string
315 Idx file.Idx
316 }
317
318 // Idx0 implements Node.
319 func (nl *NumberLiteral) Idx0() file.Idx {
320 return nl.Idx
321 }
322
323 // Idx1 implements Node.
324 func (nl *NumberLiteral) Idx1() file.Idx {
325 return file.Idx(int(nl.Idx) + len(nl.Literal))
326 }
327
328 // expression implements Expression.
329 func (*NumberLiteral) expression() {}
330
331 // ObjectLiteral represents an object literal.
332 type ObjectLiteral struct {
333 Value []Property
334 LeftBrace file.Idx
335 RightBrace file.Idx
336 }
337
338 // Idx0 implements Node.
339 func (ol *ObjectLiteral) Idx0() file.Idx {
340 return ol.LeftBrace
341 }
342
343 // Idx1 implements Node.
344 func (ol *ObjectLiteral) Idx1() file.Idx {
345 return ol.RightBrace + 1
346 }
347
348 // expression implements Expression.
349 func (*ObjectLiteral) expression() {}
350
351 // ParameterList represents a parameter list.
352 type ParameterList struct {
353 List []*Identifier
354 Opening file.Idx
355 Closing file.Idx
356 }
357
358 // Property represents a property.
359 type Property struct {
360 Value Expression
361 Key string
362 Kind string
363 }
364
365 // RegExpLiteral represents a regular expression literal.
366 type RegExpLiteral struct {
367 Literal string
368 Pattern string
369 Flags string
370 Value string
371 Idx file.Idx
372 }
373
374 // Idx0 implements Node.
375 func (rl *RegExpLiteral) Idx0() file.Idx {
376 return rl.Idx
377 }
378
379 // Idx1 implements Node.
380 func (rl *RegExpLiteral) Idx1() file.Idx {
381 return file.Idx(int(rl.Idx) + len(rl.Literal))
382 }
383
384 // expression implements Expression.
385 func (*RegExpLiteral) expression() {}
386
387 // SequenceExpression represents a sequence literal.
388 type SequenceExpression struct {
389 Sequence []Expression
390 }
391
392 // Idx0 implements Node.
393 func (se *SequenceExpression) Idx0() file.Idx {
394 return se.Sequence[0].Idx0()
395 }
396
397 // Idx1 implements Node.
398 func (se *SequenceExpression) Idx1() file.Idx {
399 return se.Sequence[len(se.Sequence)-1].Idx1()
400 }
401
402 // expression implements Expression.
403 func (*SequenceExpression) expression() {}
404
405 // StringLiteral represents a string literal.
406 type StringLiteral struct {
407 Literal string
408 Value string
409 Idx file.Idx
410 }
411
412 // Idx0 implements Node.
413 func (sl *StringLiteral) Idx0() file.Idx {
414 return sl.Idx
415 }
416
417 // Idx1 implements Node.
418 func (sl *StringLiteral) Idx1() file.Idx {
419 return file.Idx(int(sl.Idx) + len(sl.Literal))
420 }
421
422 // expression implements Expression.
423 func (*StringLiteral) expression() {}
424
425 // ThisExpression represents a this expression.
426 type ThisExpression struct {
427 Idx file.Idx
428 }
429
430 // Idx0 implements Node.
431 func (te *ThisExpression) Idx0() file.Idx {
432 return te.Idx
433 }
434
435 // Idx1 implements Node.
436 func (te *ThisExpression) Idx1() file.Idx {
437 return te.Idx + 4
438 }
439
440 // expression implements Expression.
441 func (*ThisExpression) expression() {}
442
443 // UnaryExpression represents a unary expression.
444 type UnaryExpression struct {
445 Operand Expression
446 Operator token.Token
447 Idx file.Idx
448 Postfix bool
449 }
450
451 // Idx0 implements Node.
452 func (ue *UnaryExpression) Idx0() file.Idx {
453 if ue.Postfix {
454 return ue.Operand.Idx0()
455 }
456 return ue.Idx
457 }
458
459 // Idx1 implements Node.
460 func (ue *UnaryExpression) Idx1() file.Idx {
461 if ue.Postfix {
462 return ue.Operand.Idx1() + 2 // ++ --
463 }
464 return ue.Operand.Idx1()
465 }
466
467 // expression implements Expression.
468 func (*UnaryExpression) expression() {}
469
470 // VariableExpression represents a variable expression.
471 type VariableExpression struct {
472 Initializer Expression
473 Name string
474 Idx file.Idx
475 }
476
477 // Idx0 implements Node.
478 func (ve *VariableExpression) Idx0() file.Idx {
479 return ve.Idx
480 }
481
482 // Idx1 implements Node.
483 func (ve *VariableExpression) Idx1() file.Idx {
484 if ve.Initializer == nil {
485 return file.Idx(int(ve.Idx) + len(ve.Name))
486 }
487 return ve.Initializer.Idx1()
488 }
489
490 // expression implements Expression.
491 func (*VariableExpression) expression() {}
492
493 // Statement is implemented by types which represent a statement.
494 type Statement interface {
495 Node
496 statement()
497 }
498
499 // BadStatement represents a bad statement.
500 type BadStatement struct {
501 From file.Idx
502 To file.Idx
503 }
504
505 // Idx0 implements Node.
506 func (bs *BadStatement) Idx0() file.Idx {
507 return bs.From
508 }
509
510 // Idx1 implements Node.
511 func (bs *BadStatement) Idx1() file.Idx {
512 return bs.To
513 }
514
515 // expression implements Statement.
516 func (*BadStatement) statement() {}
517
518 // BlockStatement represents a block statement.
519 type BlockStatement struct {
520 List []Statement
521 LeftBrace file.Idx
522 RightBrace file.Idx
523 }
524
525 // Idx0 implements Node.
526 func (bs *BlockStatement) Idx0() file.Idx {
527 return bs.LeftBrace
528 }
529
530 // Idx1 implements Node.
531 func (bs *BlockStatement) Idx1() file.Idx {
532 return bs.RightBrace + 1
533 }
534
535 // expression implements Statement.
536 func (*BlockStatement) statement() {}
537
538 // BranchStatement represents a branch statement.
539 type BranchStatement struct {
540 Label *Identifier
541 Idx file.Idx
542 Token token.Token
543 }
544
545 // Idx0 implements Node.
546 func (bs *BranchStatement) Idx0() file.Idx {
547 return bs.Idx
548 }
549
550 // Idx1 implements Node.
551 func (bs *BranchStatement) Idx1() file.Idx {
552 if bs.Label == nil {
553 return file.Idx(int(bs.Idx) + len(bs.Token.String()))
554 }
555 return bs.Label.Idx1()
556 }
557
558 // expression implements Statement.
559 func (*BranchStatement) statement() {}
560
561 // CaseStatement represents a case statement.
562 type CaseStatement struct {
563 Test Expression
564 Consequent []Statement
565 Case file.Idx
566 }
567
568 // Idx0 implements Node.
569 func (cs *CaseStatement) Idx0() file.Idx {
570 return cs.Case
571 }
572
573 // Idx1 implements Node.
574 func (cs *CaseStatement) Idx1() file.Idx {
575 return cs.Consequent[len(cs.Consequent)-1].Idx1()
576 }
577
578 // expression implements Statement.
579 func (*CaseStatement) statement() {}
580
581 // CatchStatement represents a catch statement.
582 type CatchStatement struct {
583 Body Statement
584 Parameter *Identifier
585 Catch file.Idx
586 }
587
588 // Idx0 implements Node.
589 func (cs *CatchStatement) Idx0() file.Idx {
590 return cs.Catch
591 }
592
593 // Idx1 implements Node.
594 func (cs *CatchStatement) Idx1() file.Idx {
595 return cs.Body.Idx1()
596 }
597
598 // expression implements Statement.
599 func (*CatchStatement) statement() {}
600
601 // DebuggerStatement represents a debugger statement.
602 type DebuggerStatement struct {
603 Debugger file.Idx
604 }
605
606 // Idx0 implements Node.
607 func (ds *DebuggerStatement) Idx0() file.Idx {
608 return ds.Debugger
609 }
610
611 // Idx1 implements Node.
612 func (ds *DebuggerStatement) Idx1() file.Idx {
613 return ds.Debugger + 8
614 }
615
616 // expression implements Statement.
617 func (*DebuggerStatement) statement() {}
618
619 // DoWhileStatement represents a do while statement.
620 type DoWhileStatement struct {
621 Test Expression
622 Body Statement
623 Do file.Idx
624 RightParenthesis file.Idx
625 }
626
627 // Idx0 implements Node.
628 func (dws *DoWhileStatement) Idx0() file.Idx {
629 return dws.Do
630 }
631
632 // Idx1 implements Node.
633 func (dws *DoWhileStatement) Idx1() file.Idx {
634 return dws.RightParenthesis + 1
635 }
636
637 // expression implements Statement.
638 func (*DoWhileStatement) statement() {}
639
640 // EmptyStatement represents a empty statement.
641 type EmptyStatement struct {
642 Semicolon file.Idx
643 }
644
645 // Idx0 implements Node.
646 func (es *EmptyStatement) Idx0() file.Idx {
647 return es.Semicolon
648 }
649
650 // Idx1 implements Node.
651 func (es *EmptyStatement) Idx1() file.Idx {
652 return es.Semicolon + 1
653 }
654
655 // expression implements Statement.
656 func (*EmptyStatement) statement() {}
657
658 // ExpressionStatement represents a expression statement.
659 type ExpressionStatement struct {
660 Expression Expression
661 }
662
663 // Idx0 implements Node.
664 func (es *ExpressionStatement) Idx0() file.Idx {
665 return es.Expression.Idx0()
666 }
667
668 // Idx1 implements Node.
669 func (es *ExpressionStatement) Idx1() file.Idx {
670 return es.Expression.Idx1()
671 }
672
673 // expression implements Statement.
674 func (*ExpressionStatement) statement() {}
675
676 // ForInStatement represents a for in statement.
677 type ForInStatement struct {
678 Into Expression
679 Source Expression
680 Body Statement
681 For file.Idx
682 }
683
684 // Idx0 implements Node.
685 func (fis *ForInStatement) Idx0() file.Idx {
686 return fis.For
687 }
688
689 // Idx1 implements Node.
690 func (fis *ForInStatement) Idx1() file.Idx {
691 return fis.Body.Idx1()
692 }
693
694 // expression implements Statement.
695 func (*ForInStatement) statement() {}
696
697 // ForStatement represents a for statement.
698 type ForStatement struct {
699 Initializer Expression
700 Update Expression
701 Test Expression
702 Body Statement
703 For file.Idx
704 }
705
706 // Idx0 implements Node.
707 func (fs *ForStatement) Idx0() file.Idx {
708 return fs.For
709 }
710
711 // Idx1 implements Node.
712 func (fs *ForStatement) Idx1() file.Idx {
713 return fs.Body.Idx1()
714 }
715
716 // expression implements Statement.
717 func (*ForStatement) statement() {}
718
719 // FunctionStatement represents a function statement.
720 type FunctionStatement struct {
721 Function *FunctionLiteral
722 }
723
724 // Idx0 implements Node.
725 func (fs *FunctionStatement) Idx0() file.Idx {
726 return fs.Function.Idx0()
727 }
728
729 // Idx1 implements Node.
730 func (fs *FunctionStatement) Idx1() file.Idx {
731 return fs.Function.Idx1()
732 }
733
734 // expression implements Statement.
735 func (*FunctionStatement) statement() {}
736
737 // IfStatement represents a if statement.
738 type IfStatement struct {
739 Test Expression
740 Consequent Statement
741 Alternate Statement
742 If file.Idx
743 }
744
745 // Idx0 implements Node.
746 func (is *IfStatement) Idx0() file.Idx {
747 return is.If
748 }
749
750 // Idx1 implements Node.
751 func (is *IfStatement) Idx1() file.Idx {
752 if is.Alternate != nil {
753 return is.Alternate.Idx1()
754 }
755 return is.Consequent.Idx1()
756 }
757
758 // expression implements Statement.
759 func (*IfStatement) statement() {}
760
761 // LabelledStatement represents a labelled statement.
762 type LabelledStatement struct {
763 Statement Statement
764 Label *Identifier
765 Colon file.Idx
766 }
767
768 // Idx0 implements Node.
769 func (ls *LabelledStatement) Idx0() file.Idx {
770 return ls.Label.Idx0()
771 }
772
773 // Idx1 implements Node.
774 func (ls *LabelledStatement) Idx1() file.Idx {
775 return ls.Statement.Idx1()
776 }
777
778 // expression implements Statement.
779 func (*LabelledStatement) statement() {}
780
781 // ReturnStatement represents a return statement.
782 type ReturnStatement struct {
783 Argument Expression
784 Return file.Idx
785 }
786
787 // Idx0 implements Node.
788 func (rs *ReturnStatement) Idx0() file.Idx {
789 return rs.Return
790 }
791
792 // Idx1 implements Node.
793 func (rs *ReturnStatement) Idx1() file.Idx {
794 if rs.Argument != nil {
795 return rs.Argument.Idx1()
796 }
797 return rs.Return + 6
798 }
799
800 // expression implements Statement.
801 func (*ReturnStatement) statement() {}
802
803 // SwitchStatement represents a switch statement.
804 type SwitchStatement struct {
805 Discriminant Expression
806 Body []*CaseStatement
807 Switch file.Idx
808 Default int
809 RightBrace file.Idx
810 }
811
812 // Idx0 implements Node.
813 func (ss *SwitchStatement) Idx0() file.Idx {
814 return ss.Switch
815 }
816
817 // Idx1 implements Node.
818 func (ss *SwitchStatement) Idx1() file.Idx {
819 return ss.RightBrace + 1
820 }
821
822 // expression implements Statement.
823 func (*SwitchStatement) statement() {}
824
825 // ThrowStatement represents a throw statement.
826 type ThrowStatement struct {
827 Argument Expression
828 Throw file.Idx
829 }
830
831 // Idx0 implements Node.
832 func (ts *ThrowStatement) Idx0() file.Idx {
833 return ts.Throw
834 }
835
836 // Idx1 implements Node.
837 func (ts *ThrowStatement) Idx1() file.Idx {
838 return ts.Argument.Idx1()
839 }
840
841 // expression implements Statement.
842 func (*ThrowStatement) statement() {}
843
844 // TryStatement represents a try statement.
845 type TryStatement struct {
846 Body Statement
847 Finally Statement
848 Catch *CatchStatement
849 Try file.Idx
850 }
851
852 // Idx0 implements Node.
853 func (ts *TryStatement) Idx0() file.Idx {
854 return ts.Try
855 }
856
857 // Idx1 implements Node.
858 func (ts *TryStatement) Idx1() file.Idx {
859 if ts.Finally != nil {
860 return ts.Finally.Idx1()
861 }
862 return ts.Catch.Idx1()
863 }
864
865 // expression implements Statement.
866 func (*TryStatement) statement() {}
867
868 // VariableStatement represents a variable statement.
869 type VariableStatement struct {
870 List []Expression
871 Var file.Idx
872 }
873
874 // Idx0 implements Node.
875 func (vs *VariableStatement) Idx0() file.Idx {
876 return vs.Var
877 }
878
879 // Idx1 implements Node.
880 func (vs *VariableStatement) Idx1() file.Idx {
881 return vs.List[len(vs.List)-1].Idx1()
882 }
883
884 // expression implements Statement.
885 func (*VariableStatement) statement() {}
886
887 // WhileStatement represents a while statement.
888 type WhileStatement struct {
889 Test Expression
890 Body Statement
891 While file.Idx
892 }
893
894 // Idx0 implements Node.
895 func (ws *WhileStatement) Idx0() file.Idx {
896 return ws.While
897 }
898
899 // Idx1 implements Node.
900 func (ws *WhileStatement) Idx1() file.Idx {
901 return ws.Body.Idx1()
902 }
903
904 // expression implements Statement.
905 func (*WhileStatement) statement() {}
906
907 // WithStatement represents a with statement.
908 type WithStatement struct {
909 Object Expression
910 Body Statement
911 With file.Idx
912 }
913
914 // Idx0 implements Node.
915 func (ws *WithStatement) Idx0() file.Idx {
916 return ws.With
917 }
918
919 // Idx1 implements Node.
920 func (ws *WithStatement) Idx1() file.Idx {
921 return ws.Body.Idx1()
922 }
923
924 // expression implements Statement.
925 func (*WithStatement) statement() {}
926
927 // Declaration is implemented by type which represent declarations.
928 type Declaration interface {
929 declaration()
930 }
931
932 // FunctionDeclaration represents a function declaration.
933 type FunctionDeclaration struct {
934 Function *FunctionLiteral
935 }
936
937 func (*FunctionDeclaration) declaration() {}
938
939 // VariableDeclaration represents a variable declaration.
940 type VariableDeclaration struct {
941 List []*VariableExpression
942 Var file.Idx
943 }
944
945 // declaration implements Declaration.
946 func (*VariableDeclaration) declaration() {}
947
948 // Program represents a full program.
949 type Program struct {
950 File *file.File
951 Comments CommentMap
952 Body []Statement
953 DeclarationList []Declaration
954 }
955
956 // Idx0 implements Node.
957 func (p *Program) Idx0() file.Idx {
958 return p.Body[0].Idx0()
959 }
960
961 // Idx1 implements Node.
962 func (p *Program) Idx1() file.Idx {
963 return p.Body[len(p.Body)-1].Idx1()
964 }