aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/robertkrimen/otto/ast
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/robertkrimen/otto/ast')
-rw-r--r--vendor/github.com/robertkrimen/otto/ast/README.markdown1068
-rw-r--r--vendor/github.com/robertkrimen/otto/ast/comments.go278
-rw-r--r--vendor/github.com/robertkrimen/otto/ast/node.go515
3 files changed, 1861 insertions, 0 deletions
diff --git a/vendor/github.com/robertkrimen/otto/ast/README.markdown b/vendor/github.com/robertkrimen/otto/ast/README.markdown
new file mode 100644
index 000000000..a785da911
--- /dev/null
+++ b/vendor/github.com/robertkrimen/otto/ast/README.markdown
@@ -0,0 +1,1068 @@
+# ast
+--
+ import "github.com/robertkrimen/otto/ast"
+
+Package ast declares types representing a JavaScript AST.
+
+
+### Warning
+
+The parser and AST interfaces are still works-in-progress (particularly where
+node types are concerned) and may change in the future.
+
+## Usage
+
+#### type ArrayLiteral
+
+```go
+type ArrayLiteral struct {
+ LeftBracket file.Idx
+ RightBracket file.Idx
+ Value []Expression
+}
+```
+
+
+#### func (*ArrayLiteral) Idx0
+
+```go
+func (self *ArrayLiteral) Idx0() file.Idx
+```
+
+#### func (*ArrayLiteral) Idx1
+
+```go
+func (self *ArrayLiteral) Idx1() file.Idx
+```
+
+#### type AssignExpression
+
+```go
+type AssignExpression struct {
+ Operator token.Token
+ Left Expression
+ Right Expression
+}
+```
+
+
+#### func (*AssignExpression) Idx0
+
+```go
+func (self *AssignExpression) Idx0() file.Idx
+```
+
+#### func (*AssignExpression) Idx1
+
+```go
+func (self *AssignExpression) Idx1() file.Idx
+```
+
+#### type BadExpression
+
+```go
+type BadExpression struct {
+ From file.Idx
+ To file.Idx
+}
+```
+
+
+#### func (*BadExpression) Idx0
+
+```go
+func (self *BadExpression) Idx0() file.Idx
+```
+
+#### func (*BadExpression) Idx1
+
+```go
+func (self *BadExpression) Idx1() file.Idx
+```
+
+#### type BadStatement
+
+```go
+type BadStatement struct {
+ From file.Idx
+ To file.Idx
+}
+```
+
+
+#### func (*BadStatement) Idx0
+
+```go
+func (self *BadStatement) Idx0() file.Idx
+```
+
+#### func (*BadStatement) Idx1
+
+```go
+func (self *BadStatement) Idx1() file.Idx
+```
+
+#### type BinaryExpression
+
+```go
+type BinaryExpression struct {
+ Operator token.Token
+ Left Expression
+ Right Expression
+ Comparison bool
+}
+```
+
+
+#### func (*BinaryExpression) Idx0
+
+```go
+func (self *BinaryExpression) Idx0() file.Idx
+```
+
+#### func (*BinaryExpression) Idx1
+
+```go
+func (self *BinaryExpression) Idx1() file.Idx
+```
+
+#### type BlockStatement
+
+```go
+type BlockStatement struct {
+ LeftBrace file.Idx
+ List []Statement
+ RightBrace file.Idx
+}
+```
+
+
+#### func (*BlockStatement) Idx0
+
+```go
+func (self *BlockStatement) Idx0() file.Idx
+```
+
+#### func (*BlockStatement) Idx1
+
+```go
+func (self *BlockStatement) Idx1() file.Idx
+```
+
+#### type BooleanLiteral
+
+```go
+type BooleanLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value bool
+}
+```
+
+
+#### func (*BooleanLiteral) Idx0
+
+```go
+func (self *BooleanLiteral) Idx0() file.Idx
+```
+
+#### func (*BooleanLiteral) Idx1
+
+```go
+func (self *BooleanLiteral) Idx1() file.Idx
+```
+
+#### type BracketExpression
+
+```go
+type BracketExpression struct {
+ Left Expression
+ Member Expression
+ LeftBracket file.Idx
+ RightBracket file.Idx
+}
+```
+
+
+#### func (*BracketExpression) Idx0
+
+```go
+func (self *BracketExpression) Idx0() file.Idx
+```
+
+#### func (*BracketExpression) Idx1
+
+```go
+func (self *BracketExpression) Idx1() file.Idx
+```
+
+#### type BranchStatement
+
+```go
+type BranchStatement struct {
+ Idx file.Idx
+ Token token.Token
+ Label *Identifier
+}
+```
+
+
+#### func (*BranchStatement) Idx0
+
+```go
+func (self *BranchStatement) Idx0() file.Idx
+```
+
+#### func (*BranchStatement) Idx1
+
+```go
+func (self *BranchStatement) Idx1() file.Idx
+```
+
+#### type CallExpression
+
+```go
+type CallExpression struct {
+ Callee Expression
+ LeftParenthesis file.Idx
+ ArgumentList []Expression
+ RightParenthesis file.Idx
+}
+```
+
+
+#### func (*CallExpression) Idx0
+
+```go
+func (self *CallExpression) Idx0() file.Idx
+```
+
+#### func (*CallExpression) Idx1
+
+```go
+func (self *CallExpression) Idx1() file.Idx
+```
+
+#### type CaseStatement
+
+```go
+type CaseStatement struct {
+ Case file.Idx
+ Test Expression
+ Consequent []Statement
+}
+```
+
+
+#### func (*CaseStatement) Idx0
+
+```go
+func (self *CaseStatement) Idx0() file.Idx
+```
+
+#### func (*CaseStatement) Idx1
+
+```go
+func (self *CaseStatement) Idx1() file.Idx
+```
+
+#### type CatchStatement
+
+```go
+type CatchStatement struct {
+ Catch file.Idx
+ Parameter *Identifier
+ Body Statement
+}
+```
+
+
+#### func (*CatchStatement) Idx0
+
+```go
+func (self *CatchStatement) Idx0() file.Idx
+```
+
+#### func (*CatchStatement) Idx1
+
+```go
+func (self *CatchStatement) Idx1() file.Idx
+```
+
+#### type ConditionalExpression
+
+```go
+type ConditionalExpression struct {
+ Test Expression
+ Consequent Expression
+ Alternate Expression
+}
+```
+
+
+#### func (*ConditionalExpression) Idx0
+
+```go
+func (self *ConditionalExpression) Idx0() file.Idx
+```
+
+#### func (*ConditionalExpression) Idx1
+
+```go
+func (self *ConditionalExpression) Idx1() file.Idx
+```
+
+#### type DebuggerStatement
+
+```go
+type DebuggerStatement struct {
+ Debugger file.Idx
+}
+```
+
+
+#### func (*DebuggerStatement) Idx0
+
+```go
+func (self *DebuggerStatement) Idx0() file.Idx
+```
+
+#### func (*DebuggerStatement) Idx1
+
+```go
+func (self *DebuggerStatement) Idx1() file.Idx
+```
+
+#### type Declaration
+
+```go
+type Declaration interface {
+ // contains filtered or unexported methods
+}
+```
+
+All declaration nodes implement the Declaration interface.
+
+#### type DoWhileStatement
+
+```go
+type DoWhileStatement struct {
+ Do file.Idx
+ Test Expression
+ Body Statement
+}
+```
+
+
+#### func (*DoWhileStatement) Idx0
+
+```go
+func (self *DoWhileStatement) Idx0() file.Idx
+```
+
+#### func (*DoWhileStatement) Idx1
+
+```go
+func (self *DoWhileStatement) Idx1() file.Idx
+```
+
+#### type DotExpression
+
+```go
+type DotExpression struct {
+ Left Expression
+ Identifier Identifier
+}
+```
+
+
+#### func (*DotExpression) Idx0
+
+```go
+func (self *DotExpression) Idx0() file.Idx
+```
+
+#### func (*DotExpression) Idx1
+
+```go
+func (self *DotExpression) Idx1() file.Idx
+```
+
+#### type EmptyStatement
+
+```go
+type EmptyStatement struct {
+ Semicolon file.Idx
+}
+```
+
+
+#### func (*EmptyStatement) Idx0
+
+```go
+func (self *EmptyStatement) Idx0() file.Idx
+```
+
+#### func (*EmptyStatement) Idx1
+
+```go
+func (self *EmptyStatement) Idx1() file.Idx
+```
+
+#### type Expression
+
+```go
+type Expression interface {
+ Node
+ // contains filtered or unexported methods
+}
+```
+
+All expression nodes implement the Expression interface.
+
+#### type ExpressionStatement
+
+```go
+type ExpressionStatement struct {
+ Expression Expression
+}
+```
+
+
+#### func (*ExpressionStatement) Idx0
+
+```go
+func (self *ExpressionStatement) Idx0() file.Idx
+```
+
+#### func (*ExpressionStatement) Idx1
+
+```go
+func (self *ExpressionStatement) Idx1() file.Idx
+```
+
+#### type ForInStatement
+
+```go
+type ForInStatement struct {
+ For file.Idx
+ Into Expression
+ Source Expression
+ Body Statement
+}
+```
+
+
+#### func (*ForInStatement) Idx0
+
+```go
+func (self *ForInStatement) Idx0() file.Idx
+```
+
+#### func (*ForInStatement) Idx1
+
+```go
+func (self *ForInStatement) Idx1() file.Idx
+```
+
+#### type ForStatement
+
+```go
+type ForStatement struct {
+ For file.Idx
+ Initializer Expression
+ Update Expression
+ Test Expression
+ Body Statement
+}
+```
+
+
+#### func (*ForStatement) Idx0
+
+```go
+func (self *ForStatement) Idx0() file.Idx
+```
+
+#### func (*ForStatement) Idx1
+
+```go
+func (self *ForStatement) Idx1() file.Idx
+```
+
+#### type FunctionDeclaration
+
+```go
+type FunctionDeclaration struct {
+ Function *FunctionLiteral
+}
+```
+
+
+#### type FunctionLiteral
+
+```go
+type FunctionLiteral struct {
+ Function file.Idx
+ Name *Identifier
+ ParameterList *ParameterList
+ Body Statement
+ Source string
+
+ DeclarationList []Declaration
+}
+```
+
+
+#### func (*FunctionLiteral) Idx0
+
+```go
+func (self *FunctionLiteral) Idx0() file.Idx
+```
+
+#### func (*FunctionLiteral) Idx1
+
+```go
+func (self *FunctionLiteral) Idx1() file.Idx
+```
+
+#### type Identifier
+
+```go
+type Identifier struct {
+ Name string
+ Idx file.Idx
+}
+```
+
+
+#### func (*Identifier) Idx0
+
+```go
+func (self *Identifier) Idx0() file.Idx
+```
+
+#### func (*Identifier) Idx1
+
+```go
+func (self *Identifier) Idx1() file.Idx
+```
+
+#### type IfStatement
+
+```go
+type IfStatement struct {
+ If file.Idx
+ Test Expression
+ Consequent Statement
+ Alternate Statement
+}
+```
+
+
+#### func (*IfStatement) Idx0
+
+```go
+func (self *IfStatement) Idx0() file.Idx
+```
+
+#### func (*IfStatement) Idx1
+
+```go
+func (self *IfStatement) Idx1() file.Idx
+```
+
+#### type LabelledStatement
+
+```go
+type LabelledStatement struct {
+ Label *Identifier
+ Colon file.Idx
+ Statement Statement
+}
+```
+
+
+#### func (*LabelledStatement) Idx0
+
+```go
+func (self *LabelledStatement) Idx0() file.Idx
+```
+
+#### func (*LabelledStatement) Idx1
+
+```go
+func (self *LabelledStatement) Idx1() file.Idx
+```
+
+#### type NewExpression
+
+```go
+type NewExpression struct {
+ New file.Idx
+ Callee Expression
+ LeftParenthesis file.Idx
+ ArgumentList []Expression
+ RightParenthesis file.Idx
+}
+```
+
+
+#### func (*NewExpression) Idx0
+
+```go
+func (self *NewExpression) Idx0() file.Idx
+```
+
+#### func (*NewExpression) Idx1
+
+```go
+func (self *NewExpression) Idx1() file.Idx
+```
+
+#### type Node
+
+```go
+type Node interface {
+ Idx0() file.Idx // The index of the first character belonging to the node
+ Idx1() file.Idx // The index of the first character immediately after the node
+}
+```
+
+All nodes implement the Node interface.
+
+#### type NullLiteral
+
+```go
+type NullLiteral struct {
+ Idx file.Idx
+ Literal string
+}
+```
+
+
+#### func (*NullLiteral) Idx0
+
+```go
+func (self *NullLiteral) Idx0() file.Idx
+```
+
+#### func (*NullLiteral) Idx1
+
+```go
+func (self *NullLiteral) Idx1() file.Idx
+```
+
+#### type NumberLiteral
+
+```go
+type NumberLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value interface{}
+}
+```
+
+
+#### func (*NumberLiteral) Idx0
+
+```go
+func (self *NumberLiteral) Idx0() file.Idx
+```
+
+#### func (*NumberLiteral) Idx1
+
+```go
+func (self *NumberLiteral) Idx1() file.Idx
+```
+
+#### type ObjectLiteral
+
+```go
+type ObjectLiteral struct {
+ LeftBrace file.Idx
+ RightBrace file.Idx
+ Value []Property
+}
+```
+
+
+#### func (*ObjectLiteral) Idx0
+
+```go
+func (self *ObjectLiteral) Idx0() file.Idx
+```
+
+#### func (*ObjectLiteral) Idx1
+
+```go
+func (self *ObjectLiteral) Idx1() file.Idx
+```
+
+#### type ParameterList
+
+```go
+type ParameterList struct {
+ Opening file.Idx
+ List []*Identifier
+ Closing file.Idx
+}
+```
+
+
+#### type Program
+
+```go
+type Program struct {
+ Body []Statement
+
+ DeclarationList []Declaration
+
+ File *file.File
+}
+```
+
+
+#### func (*Program) Idx0
+
+```go
+func (self *Program) Idx0() file.Idx
+```
+
+#### func (*Program) Idx1
+
+```go
+func (self *Program) Idx1() file.Idx
+```
+
+#### type Property
+
+```go
+type Property struct {
+ Key string
+ Kind string
+ Value Expression
+}
+```
+
+
+#### type RegExpLiteral
+
+```go
+type RegExpLiteral struct {
+ Idx file.Idx
+ Literal string
+ Pattern string
+ Flags string
+ Value string
+}
+```
+
+
+#### func (*RegExpLiteral) Idx0
+
+```go
+func (self *RegExpLiteral) Idx0() file.Idx
+```
+
+#### func (*RegExpLiteral) Idx1
+
+```go
+func (self *RegExpLiteral) Idx1() file.Idx
+```
+
+#### type ReturnStatement
+
+```go
+type ReturnStatement struct {
+ Return file.Idx
+ Argument Expression
+}
+```
+
+
+#### func (*ReturnStatement) Idx0
+
+```go
+func (self *ReturnStatement) Idx0() file.Idx
+```
+
+#### func (*ReturnStatement) Idx1
+
+```go
+func (self *ReturnStatement) Idx1() file.Idx
+```
+
+#### type SequenceExpression
+
+```go
+type SequenceExpression struct {
+ Sequence []Expression
+}
+```
+
+
+#### func (*SequenceExpression) Idx0
+
+```go
+func (self *SequenceExpression) Idx0() file.Idx
+```
+
+#### func (*SequenceExpression) Idx1
+
+```go
+func (self *SequenceExpression) Idx1() file.Idx
+```
+
+#### type Statement
+
+```go
+type Statement interface {
+ Node
+ // contains filtered or unexported methods
+}
+```
+
+All statement nodes implement the Statement interface.
+
+#### type StringLiteral
+
+```go
+type StringLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value string
+}
+```
+
+
+#### func (*StringLiteral) Idx0
+
+```go
+func (self *StringLiteral) Idx0() file.Idx
+```
+
+#### func (*StringLiteral) Idx1
+
+```go
+func (self *StringLiteral) Idx1() file.Idx
+```
+
+#### type SwitchStatement
+
+```go
+type SwitchStatement struct {
+ Switch file.Idx
+ Discriminant Expression
+ Default int
+ Body []*CaseStatement
+}
+```
+
+
+#### func (*SwitchStatement) Idx0
+
+```go
+func (self *SwitchStatement) Idx0() file.Idx
+```
+
+#### func (*SwitchStatement) Idx1
+
+```go
+func (self *SwitchStatement) Idx1() file.Idx
+```
+
+#### type ThisExpression
+
+```go
+type ThisExpression struct {
+ Idx file.Idx
+}
+```
+
+
+#### func (*ThisExpression) Idx0
+
+```go
+func (self *ThisExpression) Idx0() file.Idx
+```
+
+#### func (*ThisExpression) Idx1
+
+```go
+func (self *ThisExpression) Idx1() file.Idx
+```
+
+#### type ThrowStatement
+
+```go
+type ThrowStatement struct {
+ Throw file.Idx
+ Argument Expression
+}
+```
+
+
+#### func (*ThrowStatement) Idx0
+
+```go
+func (self *ThrowStatement) Idx0() file.Idx
+```
+
+#### func (*ThrowStatement) Idx1
+
+```go
+func (self *ThrowStatement) Idx1() file.Idx
+```
+
+#### type TryStatement
+
+```go
+type TryStatement struct {
+ Try file.Idx
+ Body Statement
+ Catch *CatchStatement
+ Finally Statement
+}
+```
+
+
+#### func (*TryStatement) Idx0
+
+```go
+func (self *TryStatement) Idx0() file.Idx
+```
+
+#### func (*TryStatement) Idx1
+
+```go
+func (self *TryStatement) Idx1() file.Idx
+```
+
+#### type UnaryExpression
+
+```go
+type UnaryExpression struct {
+ Operator token.Token
+ Idx file.Idx // If a prefix operation
+ Operand Expression
+ Postfix bool
+}
+```
+
+
+#### func (*UnaryExpression) Idx0
+
+```go
+func (self *UnaryExpression) Idx0() file.Idx
+```
+
+#### func (*UnaryExpression) Idx1
+
+```go
+func (self *UnaryExpression) Idx1() file.Idx
+```
+
+#### type VariableDeclaration
+
+```go
+type VariableDeclaration struct {
+ Var file.Idx
+ List []*VariableExpression
+}
+```
+
+
+#### type VariableExpression
+
+```go
+type VariableExpression struct {
+ Name string
+ Idx file.Idx
+ Initializer Expression
+}
+```
+
+
+#### func (*VariableExpression) Idx0
+
+```go
+func (self *VariableExpression) Idx0() file.Idx
+```
+
+#### func (*VariableExpression) Idx1
+
+```go
+func (self *VariableExpression) Idx1() file.Idx
+```
+
+#### type VariableStatement
+
+```go
+type VariableStatement struct {
+ Var file.Idx
+ List []Expression
+}
+```
+
+
+#### func (*VariableStatement) Idx0
+
+```go
+func (self *VariableStatement) Idx0() file.Idx
+```
+
+#### func (*VariableStatement) Idx1
+
+```go
+func (self *VariableStatement) Idx1() file.Idx
+```
+
+#### type WhileStatement
+
+```go
+type WhileStatement struct {
+ While file.Idx
+ Test Expression
+ Body Statement
+}
+```
+
+
+#### func (*WhileStatement) Idx0
+
+```go
+func (self *WhileStatement) Idx0() file.Idx
+```
+
+#### func (*WhileStatement) Idx1
+
+```go
+func (self *WhileStatement) Idx1() file.Idx
+```
+
+#### type WithStatement
+
+```go
+type WithStatement struct {
+ With file.Idx
+ Object Expression
+ Body Statement
+}
+```
+
+
+#### func (*WithStatement) Idx0
+
+```go
+func (self *WithStatement) Idx0() file.Idx
+```
+
+#### func (*WithStatement) Idx1
+
+```go
+func (self *WithStatement) Idx1() file.Idx
+```
+
+--
+**godocdown** http://github.com/robertkrimen/godocdown
diff --git a/vendor/github.com/robertkrimen/otto/ast/comments.go b/vendor/github.com/robertkrimen/otto/ast/comments.go
new file mode 100644
index 000000000..ef2cc3d89
--- /dev/null
+++ b/vendor/github.com/robertkrimen/otto/ast/comments.go
@@ -0,0 +1,278 @@
+package ast
+
+import (
+ "fmt"
+ "github.com/robertkrimen/otto/file"
+)
+
+// CommentPosition determines where the comment is in a given context
+type CommentPosition int
+
+const (
+ _ CommentPosition = iota
+ LEADING // Before the pertinent expression
+ TRAILING // After the pertinent expression
+ KEY // Before a key in an object
+ COLON // After a colon in a field declaration
+ FINAL // Final comments in a block, not belonging to a specific expression or the comment after a trailing , in an array or object literal
+ IF // After an if keyword
+ WHILE // After a while keyword
+ DO // After do keyword
+ FOR // After a for keyword
+ WITH // After a with keyword
+ TBD
+)
+
+// Comment contains the data of the comment
+type Comment struct {
+ Begin file.Idx
+ Text string
+ Position CommentPosition
+}
+
+// NewComment creates a new comment
+func NewComment(text string, idx file.Idx) *Comment {
+ comment := &Comment{
+ Begin: idx,
+ Text: text,
+ Position: TBD,
+ }
+
+ return comment
+}
+
+// String returns a stringified version of the position
+func (cp CommentPosition) String() string {
+ switch cp {
+ case LEADING:
+ return "Leading"
+ case TRAILING:
+ return "Trailing"
+ case KEY:
+ return "Key"
+ case COLON:
+ return "Colon"
+ case FINAL:
+ return "Final"
+ case IF:
+ return "If"
+ case WHILE:
+ return "While"
+ case DO:
+ return "Do"
+ case FOR:
+ return "For"
+ case WITH:
+ return "With"
+ default:
+ return "???"
+ }
+}
+
+// String returns a stringified version of the comment
+func (c Comment) String() string {
+ return fmt.Sprintf("Comment: %v", c.Text)
+}
+
+// Comments defines the current view of comments from the parser
+type Comments struct {
+ // CommentMap is a reference to the parser comment map
+ CommentMap CommentMap
+ // Comments lists the comments scanned, not linked to a node yet
+ Comments []*Comment
+ // future lists the comments after a line break during a sequence of comments
+ future []*Comment
+ // Current is node for which comments are linked to
+ Current Expression
+
+ // wasLineBreak determines if a line break occured while scanning for comments
+ wasLineBreak bool
+ // primary determines whether or not processing a primary expression
+ primary bool
+ // afterBlock determines whether or not being after a block statement
+ afterBlock bool
+}
+
+func NewComments() *Comments {
+ comments := &Comments{
+ CommentMap: CommentMap{},
+ }
+
+ return comments
+}
+
+func (c *Comments) String() string {
+ return fmt.Sprintf("NODE: %v, Comments: %v, Future: %v(LINEBREAK:%v)", c.Current, len(c.Comments), len(c.future), c.wasLineBreak)
+}
+
+// FetchAll returns all the currently scanned comments,
+// including those from the next line
+func (c *Comments) FetchAll() []*Comment {
+ defer func() {
+ c.Comments = nil
+ c.future = nil
+ }()
+
+ return append(c.Comments, c.future...)
+}
+
+// Fetch returns all the currently scanned comments
+func (c *Comments) Fetch() []*Comment {
+ defer func() {
+ c.Comments = nil
+ }()
+
+ return c.Comments
+}
+
+// ResetLineBreak marks the beginning of a new statement
+func (c *Comments) ResetLineBreak() {
+ c.wasLineBreak = false
+}
+
+// MarkPrimary will mark the context as processing a primary expression
+func (c *Comments) MarkPrimary() {
+ c.primary = true
+ c.wasLineBreak = false
+}
+
+// AfterBlock will mark the context as being after a block.
+func (c *Comments) AfterBlock() {
+ c.afterBlock = true
+}
+
+// AddComment adds a comment to the view.
+// Depending on the context, comments are added normally or as post line break.
+func (c *Comments) AddComment(comment *Comment) {
+ if c.primary {
+ if !c.wasLineBreak {
+ c.Comments = append(c.Comments, comment)
+ } else {
+ c.future = append(c.future, comment)
+ }
+ } else {
+ if !c.wasLineBreak || (c.Current == nil && !c.afterBlock) {
+ c.Comments = append(c.Comments, comment)
+ } else {
+ c.future = append(c.future, comment)
+ }
+ }
+}
+
+// MarkComments will mark the found comments as the given position.
+func (c *Comments) MarkComments(position CommentPosition) {
+ for _, comment := range c.Comments {
+ if comment.Position == TBD {
+ comment.Position = position
+ }
+ }
+ for _, c := range c.future {
+ if c.Position == TBD {
+ c.Position = position
+ }
+ }
+}
+
+// Unset the current node and apply the comments to the current expression.
+// Resets context variables.
+func (c *Comments) Unset() {
+ if c.Current != nil {
+ c.applyComments(c.Current, c.Current, TRAILING)
+ c.Current = nil
+ }
+ c.wasLineBreak = false
+ c.primary = false
+ c.afterBlock = false
+}
+
+// SetExpression sets the current expression.
+// It is applied the found comments, unless the previous expression has not been unset.
+// It is skipped if the node is already set or if it is a part of the previous node.
+func (c *Comments) SetExpression(node Expression) {
+ // Skipping same node
+ if c.Current == node {
+ return
+ }
+ if c.Current != nil && c.Current.Idx1() == node.Idx1() {
+ c.Current = node
+ return
+ }
+ previous := c.Current
+ c.Current = node
+
+ // Apply the found comments and futures to the node and the previous.
+ c.applyComments(node, previous, TRAILING)
+}
+
+// PostProcessNode applies all found comments to the given node
+func (c *Comments) PostProcessNode(node Node) {
+ c.applyComments(node, nil, TRAILING)
+}
+
+// applyComments applies both the comments and the future comments to the given node and the previous one,
+// based on the context.
+func (c *Comments) applyComments(node, previous Node, position CommentPosition) {
+ if previous != nil {
+ c.CommentMap.AddComments(previous, c.Comments, position)
+ c.Comments = nil
+ } else {
+ c.CommentMap.AddComments(node, c.Comments, position)
+ c.Comments = nil
+ }
+ // Only apply the future comments to the node if the previous is set.
+ // This is for detecting end of line comments and which node comments on the following lines belongs to
+ if previous != nil {
+ c.CommentMap.AddComments(node, c.future, position)
+ c.future = nil
+ }
+}
+
+// AtLineBreak will mark a line break
+func (c *Comments) AtLineBreak() {
+ c.wasLineBreak = true
+}
+
+// CommentMap is the data structure where all found comments are stored
+type CommentMap map[Node][]*Comment
+
+// AddComment adds a single comment to the map
+func (cm CommentMap) AddComment(node Node, comment *Comment) {
+ list := cm[node]
+ list = append(list, comment)
+
+ cm[node] = list
+}
+
+// AddComments adds a slice of comments, given a node and an updated position
+func (cm CommentMap) AddComments(node Node, comments []*Comment, position CommentPosition) {
+ for _, comment := range comments {
+ if comment.Position == TBD {
+ comment.Position = position
+ }
+ cm.AddComment(node, comment)
+ }
+}
+
+// Size returns the size of the map
+func (cm CommentMap) Size() int {
+ size := 0
+ for _, comments := range cm {
+ size += len(comments)
+ }
+
+ return size
+}
+
+// MoveComments moves comments with a given position from a node to another
+func (cm CommentMap) MoveComments(from, to Node, position CommentPosition) {
+ for i, c := range cm[from] {
+ if c.Position == position {
+ cm.AddComment(to, c)
+
+ // Remove the comment from the "from" slice
+ cm[from][i] = cm[from][len(cm[from])-1]
+ cm[from][len(cm[from])-1] = nil
+ cm[from] = cm[from][:len(cm[from])-1]
+ }
+ }
+}
diff --git a/vendor/github.com/robertkrimen/otto/ast/node.go b/vendor/github.com/robertkrimen/otto/ast/node.go
new file mode 100644
index 000000000..49ae375d1
--- /dev/null
+++ b/vendor/github.com/robertkrimen/otto/ast/node.go
@@ -0,0 +1,515 @@
+/*
+Package ast declares types representing a JavaScript AST.
+
+Warning
+
+The parser and AST interfaces are still works-in-progress (particularly where
+node types are concerned) and may change in the future.
+
+*/
+package ast
+
+import (
+ "github.com/robertkrimen/otto/file"
+ "github.com/robertkrimen/otto/token"
+)
+
+// All nodes implement the Node interface.
+type Node interface {
+ Idx0() file.Idx // The index of the first character belonging to the node
+ Idx1() file.Idx // The index of the first character immediately after the node
+}
+
+// ========== //
+// Expression //
+// ========== //
+
+type (
+ // All expression nodes implement the Expression interface.
+ Expression interface {
+ Node
+ _expressionNode()
+ }
+
+ ArrayLiteral struct {
+ LeftBracket file.Idx
+ RightBracket file.Idx
+ Value []Expression
+ }
+
+ AssignExpression struct {
+ Operator token.Token
+ Left Expression
+ Right Expression
+ }
+
+ BadExpression struct {
+ From file.Idx
+ To file.Idx
+ }
+
+ BinaryExpression struct {
+ Operator token.Token
+ Left Expression
+ Right Expression
+ Comparison bool
+ }
+
+ BooleanLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value bool
+ }
+
+ BracketExpression struct {
+ Left Expression
+ Member Expression
+ LeftBracket file.Idx
+ RightBracket file.Idx
+ }
+
+ CallExpression struct {
+ Callee Expression
+ LeftParenthesis file.Idx
+ ArgumentList []Expression
+ RightParenthesis file.Idx
+ }
+
+ ConditionalExpression struct {
+ Test Expression
+ Consequent Expression
+ Alternate Expression
+ }
+
+ DotExpression struct {
+ Left Expression
+ Identifier *Identifier
+ }
+
+ EmptyExpression struct {
+ Begin file.Idx
+ End file.Idx
+ }
+
+ FunctionLiteral struct {
+ Function file.Idx
+ Name *Identifier
+ ParameterList *ParameterList
+ Body Statement
+ Source string
+
+ DeclarationList []Declaration
+ }
+
+ Identifier struct {
+ Name string
+ Idx file.Idx
+ }
+
+ NewExpression struct {
+ New file.Idx
+ Callee Expression
+ LeftParenthesis file.Idx
+ ArgumentList []Expression
+ RightParenthesis file.Idx
+ }
+
+ NullLiteral struct {
+ Idx file.Idx
+ Literal string
+ }
+
+ NumberLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value interface{}
+ }
+
+ ObjectLiteral struct {
+ LeftBrace file.Idx
+ RightBrace file.Idx
+ Value []Property
+ }
+
+ ParameterList struct {
+ Opening file.Idx
+ List []*Identifier
+ Closing file.Idx
+ }
+
+ Property struct {
+ Key string
+ Kind string
+ Value Expression
+ }
+
+ RegExpLiteral struct {
+ Idx file.Idx
+ Literal string
+ Pattern string
+ Flags string
+ Value string
+ }
+
+ SequenceExpression struct {
+ Sequence []Expression
+ }
+
+ StringLiteral struct {
+ Idx file.Idx
+ Literal string
+ Value string
+ }
+
+ ThisExpression struct {
+ Idx file.Idx
+ }
+
+ UnaryExpression struct {
+ Operator token.Token
+ Idx file.Idx // If a prefix operation
+ Operand Expression
+ Postfix bool
+ }
+
+ VariableExpression struct {
+ Name string
+ Idx file.Idx
+ Initializer Expression
+ }
+)
+
+// _expressionNode
+
+func (*ArrayLiteral) _expressionNode() {}
+func (*AssignExpression) _expressionNode() {}
+func (*BadExpression) _expressionNode() {}
+func (*BinaryExpression) _expressionNode() {}
+func (*BooleanLiteral) _expressionNode() {}
+func (*BracketExpression) _expressionNode() {}
+func (*CallExpression) _expressionNode() {}
+func (*ConditionalExpression) _expressionNode() {}
+func (*DotExpression) _expressionNode() {}
+func (*EmptyExpression) _expressionNode() {}
+func (*FunctionLiteral) _expressionNode() {}
+func (*Identifier) _expressionNode() {}
+func (*NewExpression) _expressionNode() {}
+func (*NullLiteral) _expressionNode() {}
+func (*NumberLiteral) _expressionNode() {}
+func (*ObjectLiteral) _expressionNode() {}
+func (*RegExpLiteral) _expressionNode() {}
+func (*SequenceExpression) _expressionNode() {}
+func (*StringLiteral) _expressionNode() {}
+func (*ThisExpression) _expressionNode() {}
+func (*UnaryExpression) _expressionNode() {}
+func (*VariableExpression) _expressionNode() {}
+
+// ========= //
+// Statement //
+// ========= //
+
+type (
+ // All statement nodes implement the Statement interface.
+ Statement interface {
+ Node
+ _statementNode()
+ }
+
+ BadStatement struct {
+ From file.Idx
+ To file.Idx
+ }
+
+ BlockStatement struct {
+ LeftBrace file.Idx
+ List []Statement
+ RightBrace file.Idx
+ }
+
+ BranchStatement struct {
+ Idx file.Idx
+ Token token.Token
+ Label *Identifier
+ }
+
+ CaseStatement struct {
+ Case file.Idx
+ Test Expression
+ Consequent []Statement
+ }
+
+ CatchStatement struct {
+ Catch file.Idx
+ Parameter *Identifier
+ Body Statement
+ }
+
+ DebuggerStatement struct {
+ Debugger file.Idx
+ }
+
+ DoWhileStatement struct {
+ Do file.Idx
+ Test Expression
+ Body Statement
+ }
+
+ EmptyStatement struct {
+ Semicolon file.Idx
+ }
+
+ ExpressionStatement struct {
+ Expression Expression
+ }
+
+ ForInStatement struct {
+ For file.Idx
+ Into Expression
+ Source Expression
+ Body Statement
+ }
+
+ ForStatement struct {
+ For file.Idx
+ Initializer Expression
+ Update Expression
+ Test Expression
+ Body Statement
+ }
+
+ FunctionStatement struct {
+ Function *FunctionLiteral
+ }
+
+ IfStatement struct {
+ If file.Idx
+ Test Expression
+ Consequent Statement
+ Alternate Statement
+ }
+
+ LabelledStatement struct {
+ Label *Identifier
+ Colon file.Idx
+ Statement Statement
+ }
+
+ ReturnStatement struct {
+ Return file.Idx
+ Argument Expression
+ }
+
+ SwitchStatement struct {
+ Switch file.Idx
+ Discriminant Expression
+ Default int
+ Body []*CaseStatement
+ }
+
+ ThrowStatement struct {
+ Throw file.Idx
+ Argument Expression
+ }
+
+ TryStatement struct {
+ Try file.Idx
+ Body Statement
+ Catch *CatchStatement
+ Finally Statement
+ }
+
+ VariableStatement struct {
+ Var file.Idx
+ List []Expression
+ }
+
+ WhileStatement struct {
+ While file.Idx
+ Test Expression
+ Body Statement
+ }
+
+ WithStatement struct {
+ With file.Idx
+ Object Expression
+ Body Statement
+ }
+)
+
+// _statementNode
+
+func (*BadStatement) _statementNode() {}
+func (*BlockStatement) _statementNode() {}
+func (*BranchStatement) _statementNode() {}
+func (*CaseStatement) _statementNode() {}
+func (*CatchStatement) _statementNode() {}
+func (*DebuggerStatement) _statementNode() {}
+func (*DoWhileStatement) _statementNode() {}
+func (*EmptyStatement) _statementNode() {}
+func (*ExpressionStatement) _statementNode() {}
+func (*ForInStatement) _statementNode() {}
+func (*ForStatement) _statementNode() {}
+func (*FunctionStatement) _statementNode() {}
+func (*IfStatement) _statementNode() {}
+func (*LabelledStatement) _statementNode() {}
+func (*ReturnStatement) _statementNode() {}
+func (*SwitchStatement) _statementNode() {}
+func (*ThrowStatement) _statementNode() {}
+func (*TryStatement) _statementNode() {}
+func (*VariableStatement) _statementNode() {}
+func (*WhileStatement) _statementNode() {}
+func (*WithStatement) _statementNode() {}
+
+// =========== //
+// Declaration //
+// =========== //
+
+type (
+ // All declaration nodes implement the Declaration interface.
+ Declaration interface {
+ _declarationNode()
+ }
+
+ FunctionDeclaration struct {
+ Function *FunctionLiteral
+ }
+
+ VariableDeclaration struct {
+ Var file.Idx
+ List []*VariableExpression
+ }
+)
+
+// _declarationNode
+
+func (*FunctionDeclaration) _declarationNode() {}
+func (*VariableDeclaration) _declarationNode() {}
+
+// ==== //
+// Node //
+// ==== //
+
+type Program struct {
+ Body []Statement
+
+ DeclarationList []Declaration
+
+ File *file.File
+
+ Comments CommentMap
+}
+
+// ==== //
+// Idx0 //
+// ==== //
+
+func (self *ArrayLiteral) Idx0() file.Idx { return self.LeftBracket }
+func (self *AssignExpression) Idx0() file.Idx { return self.Left.Idx0() }
+func (self *BadExpression) Idx0() file.Idx { return self.From }
+func (self *BinaryExpression) Idx0() file.Idx { return self.Left.Idx0() }
+func (self *BooleanLiteral) Idx0() file.Idx { return self.Idx }
+func (self *BracketExpression) Idx0() file.Idx { return self.Left.Idx0() }
+func (self *CallExpression) Idx0() file.Idx { return self.Callee.Idx0() }
+func (self *ConditionalExpression) Idx0() file.Idx { return self.Test.Idx0() }
+func (self *DotExpression) Idx0() file.Idx { return self.Left.Idx0() }
+func (self *EmptyExpression) Idx0() file.Idx { return self.Begin }
+func (self *FunctionLiteral) Idx0() file.Idx { return self.Function }
+func (self *Identifier) Idx0() file.Idx { return self.Idx }
+func (self *NewExpression) Idx0() file.Idx { return self.New }
+func (self *NullLiteral) Idx0() file.Idx { return self.Idx }
+func (self *NumberLiteral) Idx0() file.Idx { return self.Idx }
+func (self *ObjectLiteral) Idx0() file.Idx { return self.LeftBrace }
+func (self *RegExpLiteral) Idx0() file.Idx { return self.Idx }
+func (self *SequenceExpression) Idx0() file.Idx { return self.Sequence[0].Idx0() }
+func (self *StringLiteral) Idx0() file.Idx { return self.Idx }
+func (self *ThisExpression) Idx0() file.Idx { return self.Idx }
+func (self *UnaryExpression) Idx0() file.Idx { return self.Idx }
+func (self *VariableExpression) Idx0() file.Idx { return self.Idx }
+
+func (self *BadStatement) Idx0() file.Idx { return self.From }
+func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
+func (self *BranchStatement) Idx0() file.Idx { return self.Idx }
+func (self *CaseStatement) Idx0() file.Idx { return self.Case }
+func (self *CatchStatement) Idx0() file.Idx { return self.Catch }
+func (self *DebuggerStatement) Idx0() file.Idx { return self.Debugger }
+func (self *DoWhileStatement) Idx0() file.Idx { return self.Do }
+func (self *EmptyStatement) Idx0() file.Idx { return self.Semicolon }
+func (self *ExpressionStatement) Idx0() file.Idx { return self.Expression.Idx0() }
+func (self *ForInStatement) Idx0() file.Idx { return self.For }
+func (self *ForStatement) Idx0() file.Idx { return self.For }
+func (self *FunctionStatement) Idx0() file.Idx { return self.Function.Idx0() }
+func (self *IfStatement) Idx0() file.Idx { return self.If }
+func (self *LabelledStatement) Idx0() file.Idx { return self.Label.Idx0() }
+func (self *Program) Idx0() file.Idx { return self.Body[0].Idx0() }
+func (self *ReturnStatement) Idx0() file.Idx { return self.Return }
+func (self *SwitchStatement) Idx0() file.Idx { return self.Switch }
+func (self *ThrowStatement) Idx0() file.Idx { return self.Throw }
+func (self *TryStatement) Idx0() file.Idx { return self.Try }
+func (self *VariableStatement) Idx0() file.Idx { return self.Var }
+func (self *WhileStatement) Idx0() file.Idx { return self.While }
+func (self *WithStatement) Idx0() file.Idx { return self.With }
+
+// ==== //
+// Idx1 //
+// ==== //
+
+func (self *ArrayLiteral) Idx1() file.Idx { return self.RightBracket }
+func (self *AssignExpression) Idx1() file.Idx { return self.Right.Idx1() }
+func (self *BadExpression) Idx1() file.Idx { return self.To }
+func (self *BinaryExpression) Idx1() file.Idx { return self.Right.Idx1() }
+func (self *BooleanLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
+func (self *BracketExpression) Idx1() file.Idx { return self.RightBracket + 1 }
+func (self *CallExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
+func (self *ConditionalExpression) Idx1() file.Idx { return self.Test.Idx1() }
+func (self *DotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
+func (self *EmptyExpression) Idx1() file.Idx { return self.End }
+func (self *FunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
+func (self *Identifier) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Name)) }
+func (self *NewExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
+func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
+func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
+func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace }
+func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
+func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[0].Idx1() }
+func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
+func (self *ThisExpression) Idx1() file.Idx { return self.Idx }
+func (self *UnaryExpression) Idx1() file.Idx {
+ if self.Postfix {
+ return self.Operand.Idx1() + 2 // ++ --
+ }
+ return self.Operand.Idx1()
+}
+func (self *VariableExpression) Idx1() file.Idx {
+ if self.Initializer == nil {
+ return file.Idx(int(self.Idx) + len(self.Name) + 1)
+ }
+ return self.Initializer.Idx1()
+}
+
+func (self *BadStatement) Idx1() file.Idx { return self.To }
+func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
+func (self *BranchStatement) Idx1() file.Idx { return self.Idx }
+func (self *CaseStatement) Idx1() file.Idx { return self.Consequent[len(self.Consequent)-1].Idx1() }
+func (self *CatchStatement) Idx1() file.Idx { return self.Body.Idx1() }
+func (self *DebuggerStatement) Idx1() file.Idx { return self.Debugger + 8 }
+func (self *DoWhileStatement) Idx1() file.Idx { return self.Test.Idx1() }
+func (self *EmptyStatement) Idx1() file.Idx { return self.Semicolon + 1 }
+func (self *ExpressionStatement) Idx1() file.Idx { return self.Expression.Idx1() }
+func (self *ForInStatement) Idx1() file.Idx { return self.Body.Idx1() }
+func (self *ForStatement) Idx1() file.Idx { return self.Body.Idx1() }
+func (self *FunctionStatement) Idx1() file.Idx { return self.Function.Idx1() }
+func (self *IfStatement) Idx1() file.Idx {
+ if self.Alternate != nil {
+ return self.Alternate.Idx1()
+ }
+ return self.Consequent.Idx1()
+}
+func (self *LabelledStatement) Idx1() file.Idx { return self.Colon + 1 }
+func (self *Program) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
+func (self *ReturnStatement) Idx1() file.Idx { return self.Return }
+func (self *SwitchStatement) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
+func (self *ThrowStatement) Idx1() file.Idx { return self.Throw }
+func (self *TryStatement) Idx1() file.Idx { return self.Try }
+func (self *VariableStatement) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
+func (self *WhileStatement) Idx1() file.Idx { return self.Body.Idx1() }
+func (self *WithStatement) Idx1() file.Idx { return self.Body.Idx1() }