/* 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 ( ) type PropertyKind string const ( PropertyKindValue PropertyKind = "value" PropertyKindGet PropertyKind = "get" PropertyKindSet PropertyKind = "set" PropertyKindMethod PropertyKind = "method" ) // 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() } BindingTarget interface { Expression _bindingTarget() } Binding struct { Target BindingTarget Initializer Expression } Pattern interface { BindingTarget _pattern() } YieldExpression struct { Yield file.Idx Argument Expression Delegate bool } AwaitExpression struct { Await file.Idx Argument Expression } ArrayLiteral struct { LeftBracket file.Idx RightBracket file.Idx Value []Expression } ArrayPattern struct { LeftBracket file.Idx RightBracket file.Idx Elements []Expression Rest 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 } PrivateDotExpression struct { Left Expression Identifier PrivateIdentifier } OptionalChain struct { Expression } Optional struct { Expression } FunctionLiteral struct { Function file.Idx Name *Identifier ParameterList *ParameterList Body *BlockStatement Source string DeclarationList []*VariableDeclaration Async, Generator bool } ClassLiteral struct { Class file.Idx RightBrace file.Idx Name *Identifier SuperClass Expression Body []ClassElement Source string } ConciseBody interface { Node _conciseBody() } ExpressionBody struct { Expression Expression } ArrowFunctionLiteral struct { Start file.Idx ParameterList *ParameterList Body ConciseBody Source string DeclarationList []*VariableDeclaration Async bool } Identifier struct { Name unistring.String Idx file.Idx } PrivateIdentifier struct { Identifier } 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 } ObjectPattern struct { LeftBrace file.Idx RightBrace file.Idx Properties []Property Rest Expression } ParameterList struct { Opening file.Idx List []*Binding Rest Expression Closing file.Idx } Property interface { Expression _property() } PropertyShort struct { Name Identifier Initializer Expression } PropertyKeyed struct { Key Expression Kind PropertyKind Value Expression Computed bool } SpreadElement struct { Expression } RegExpLiteral struct { Idx file.Idx Literal string Pattern string Flags string } SequenceExpression struct { Sequence []Expression } StringLiteral struct { Idx file.Idx Literal string Value unistring.String } TemplateElement struct { Idx file.Idx Literal string Parsed unistring.String Valid bool } TemplateLiteral struct { OpenQuote file.Idx CloseQuote file.Idx Tag Expression Elements []*TemplateElement Expressions []Expression } ThisExpression struct { Idx file.Idx } SuperExpression struct { Idx file.Idx } UnaryExpression struct { Operator token.Token Idx file.Idx // If a prefix operation Operand Expression Postfix bool } MetaProperty struct { Meta, Property *Identifier Idx file.Idx } ) // _expressionNode func (*ArrayLiteral) () {} func (*AssignExpression) () {} func (*YieldExpression) () {} func (*AwaitExpression) () {} func (*BadExpression) () {} func (*BinaryExpression) () {} func (*BooleanLiteral) () {} func (*BracketExpression) () {} func (*CallExpression) () {} func (*ConditionalExpression) () {} func (*DotExpression) () {} func (*PrivateDotExpression) () {} func (*FunctionLiteral) () {} func (*ClassLiteral) () {} func (*ArrowFunctionLiteral) () {} func (*Identifier) () {} func (*NewExpression) () {} func (*NullLiteral) () {} func (*NumberLiteral) () {} func (*ObjectLiteral) () {} func (*RegExpLiteral) () {} func (*SequenceExpression) () {} func (*StringLiteral) () {} func (*TemplateLiteral) () {} func (*ThisExpression) () {} func (*SuperExpression) () {} func (*UnaryExpression) () {} func (*MetaProperty) () {} func (*ObjectPattern) () {} func (*ArrayPattern) () {} func (*Binding) () {} func (*PropertyShort) () {} func (*PropertyKeyed) () {} // ========= // // 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 BindingTarget Body *BlockStatement } DebuggerStatement struct { Debugger file.Idx } DoWhileStatement struct { Do file.Idx Test Expression Body Statement RightParenthesis file.Idx } EmptyStatement struct { Semicolon file.Idx } ExpressionStatement struct { Expression Expression } ForInStatement struct { For file.Idx Into ForInto Source Expression Body Statement } ForOfStatement struct { For file.Idx Into ForInto Source Expression Body Statement } ForStatement struct { For file.Idx Initializer ForLoopInitializer Update Expression Test Expression Body Statement } 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 RightBrace file.Idx } ThrowStatement struct { Throw file.Idx Argument Expression } TryStatement struct { Try file.Idx Body *BlockStatement Catch *CatchStatement Finally *BlockStatement } VariableStatement struct { Var file.Idx List []*Binding } LexicalDeclaration struct { Idx file.Idx Token token.Token List []*Binding } WhileStatement struct { While file.Idx Test Expression Body Statement } WithStatement struct { With file.Idx Object Expression Body Statement } FunctionDeclaration struct { Function *FunctionLiteral } ClassDeclaration struct { Class *ClassLiteral } ) // _statementNode func (*BadStatement) () {} func (*BlockStatement) () {} func (*BranchStatement) () {} func (*CaseStatement) () {} func (*CatchStatement) () {} func (*DebuggerStatement) () {} func (*DoWhileStatement) () {} func (*EmptyStatement) () {} func (*ExpressionStatement) () {} func (*ForInStatement) () {} func (*ForOfStatement) () {} func (*ForStatement) () {} func (*IfStatement) () {} func (*LabelledStatement) () {} func (*ReturnStatement) () {} func (*SwitchStatement) () {} func (*ThrowStatement) () {} func (*TryStatement) () {} func (*VariableStatement) () {} func (*WhileStatement) () {} func (*WithStatement) () {} func (*LexicalDeclaration) () {} func (*FunctionDeclaration) () {} func (*ClassDeclaration) () {} // =========== // // Declaration // // =========== // type ( VariableDeclaration struct { Var file.Idx List []*Binding } ClassElement interface { Node _classElement() } FieldDefinition struct { Idx file.Idx Key Expression Initializer Expression Computed bool Static bool } MethodDefinition struct { Idx file.Idx Key Expression Kind PropertyKind // "method", "get" or "set" Body *FunctionLiteral Computed bool Static bool } ClassStaticBlock struct { Static file.Idx Block *BlockStatement Source string DeclarationList []*VariableDeclaration } ) type ( ForLoopInitializer interface { Node _forLoopInitializer() } ForLoopInitializerExpression struct { Expression Expression } ForLoopInitializerVarDeclList struct { Var file.Idx List []*Binding } ForLoopInitializerLexicalDecl struct { LexicalDeclaration LexicalDeclaration } ForInto interface { Node _forInto() } ForIntoVar struct { Binding *Binding } ForDeclaration struct { Idx file.Idx IsConst bool Target BindingTarget } ForIntoExpression struct { Expression Expression } ) func (*ForLoopInitializerExpression) () {} func (*ForLoopInitializerVarDeclList) () {} func (*ForLoopInitializerLexicalDecl) () {} func (*ForIntoVar) () {} func (*ForDeclaration) () {} func (*ForIntoExpression) () {} func (*ArrayPattern) () {} func (*ArrayPattern) () {} func (*ObjectPattern) () {} func (*ObjectPattern) () {} func (*BadExpression) () {} func (*PropertyShort) () {} func (*PropertyKeyed) () {} func (*SpreadElement) () {} func (*Identifier) () {} func (*BlockStatement) () {} func (*ExpressionBody) () {} func (*FieldDefinition) () {} func (*MethodDefinition) () {} func (*ClassStaticBlock) () {} // ==== // // Node // // ==== // type Program struct { Body []Statement DeclarationList []*VariableDeclaration File *file.File } // ==== // // Idx0 // // ==== // func ( *ArrayLiteral) () file.Idx { return .LeftBracket } func ( *ArrayPattern) () file.Idx { return .LeftBracket } func ( *YieldExpression) () file.Idx { return .Yield } func ( *AwaitExpression) () file.Idx { return .Await } func ( *ObjectPattern) () file.Idx { return .LeftBrace } func ( *ParameterList) () file.Idx { return .Opening } func ( *AssignExpression) () file.Idx { return .Left.Idx0() } func ( *BadExpression) () file.Idx { return .From } func ( *BinaryExpression) () file.Idx { return .Left.Idx0() } func ( *BooleanLiteral) () file.Idx { return .Idx } func ( *BracketExpression) () file.Idx { return .Left.Idx0() } func ( *CallExpression) () file.Idx { return .Callee.Idx0() } func ( *ConditionalExpression) () file.Idx { return .Test.Idx0() } func ( *DotExpression) () file.Idx { return .Left.Idx0() } func ( *PrivateDotExpression) () file.Idx { return .Left.Idx0() } func ( *FunctionLiteral) () file.Idx { return .Function } func ( *ClassLiteral) () file.Idx { return .Class } func ( *ArrowFunctionLiteral) () file.Idx { return .Start } func ( *Identifier) () file.Idx { return .Idx } func ( *NewExpression) () file.Idx { return .New } func ( *NullLiteral) () file.Idx { return .Idx } func ( *NumberLiteral) () file.Idx { return .Idx } func ( *ObjectLiteral) () file.Idx { return .LeftBrace } func ( *RegExpLiteral) () file.Idx { return .Idx } func ( *SequenceExpression) () file.Idx { return .Sequence[0].Idx0() } func ( *StringLiteral) () file.Idx { return .Idx } func ( *TemplateElement) () file.Idx { return .Idx } func ( *TemplateLiteral) () file.Idx { return .OpenQuote } func ( *ThisExpression) () file.Idx { return .Idx } func ( *SuperExpression) () file.Idx { return .Idx } func ( *UnaryExpression) () file.Idx { if .Postfix { return .Operand.Idx0() } return .Idx } func ( *MetaProperty) () file.Idx { return .Idx } func ( *BadStatement) () file.Idx { return .From } func ( *BlockStatement) () file.Idx { return .LeftBrace } func ( *BranchStatement) () file.Idx { return .Idx } func ( *CaseStatement) () file.Idx { return .Case } func ( *CatchStatement) () file.Idx { return .Catch } func ( *DebuggerStatement) () file.Idx { return .Debugger } func ( *DoWhileStatement) () file.Idx { return .Do } func ( *EmptyStatement) () file.Idx { return .Semicolon } func ( *ExpressionStatement) () file.Idx { return .Expression.Idx0() } func ( *ForInStatement) () file.Idx { return .For } func ( *ForOfStatement) () file.Idx { return .For } func ( *ForStatement) () file.Idx { return .For } func ( *IfStatement) () file.Idx { return .If } func ( *LabelledStatement) () file.Idx { return .Label.Idx0() } func ( *Program) () file.Idx { return .Body[0].Idx0() } func ( *ReturnStatement) () file.Idx { return .Return } func ( *SwitchStatement) () file.Idx { return .Switch } func ( *ThrowStatement) () file.Idx { return .Throw } func ( *TryStatement) () file.Idx { return .Try } func ( *VariableStatement) () file.Idx { return .Var } func ( *WhileStatement) () file.Idx { return .While } func ( *WithStatement) () file.Idx { return .With } func ( *LexicalDeclaration) () file.Idx { return .Idx } func ( *FunctionDeclaration) () file.Idx { return .Function.Idx0() } func ( *ClassDeclaration) () file.Idx { return .Class.Idx0() } func ( *Binding) () file.Idx { return .Target.Idx0() } func ( *ForLoopInitializerExpression) () file.Idx { return .Expression.Idx0() } func ( *ForLoopInitializerVarDeclList) () file.Idx { return .List[0].Idx0() } func ( *ForLoopInitializerLexicalDecl) () file.Idx { return .LexicalDeclaration.Idx0() } func ( *PropertyShort) () file.Idx { return .Name.Idx } func ( *PropertyKeyed) () file.Idx { return .Key.Idx0() } func ( *ExpressionBody) () file.Idx { return .Expression.Idx0() } func ( *VariableDeclaration) () file.Idx { return .Var } func ( *FieldDefinition) () file.Idx { return .Idx } func ( *MethodDefinition) () file.Idx { return .Idx } func ( *ClassStaticBlock) () file.Idx { return .Static } func ( *ForDeclaration) () file.Idx { return .Idx } func ( *ForIntoVar) () file.Idx { return .Binding.Idx0() } func ( *ForIntoExpression) () file.Idx { return .Expression.Idx0() } // ==== // // Idx1 // // ==== // func ( *ArrayLiteral) () file.Idx { return .RightBracket + 1 } func ( *ArrayPattern) () file.Idx { return .RightBracket + 1 } func ( *AssignExpression) () file.Idx { return .Right.Idx1() } func ( *AwaitExpression) () file.Idx { return .Argument.Idx1() } func ( *BadExpression) () file.Idx { return .To } func ( *BinaryExpression) () file.Idx { return .Right.Idx1() } func ( *BooleanLiteral) () file.Idx { return file.Idx(int(.Idx) + len(.Literal)) } func ( *BracketExpression) () file.Idx { return .RightBracket + 1 } func ( *CallExpression) () file.Idx { return .RightParenthesis + 1 } func ( *ConditionalExpression) () file.Idx { return .Alternate.Idx1() } func ( *DotExpression) () file.Idx { return .Identifier.Idx1() } func ( *PrivateDotExpression) () file.Idx { return .Identifier.Idx1() } func ( *FunctionLiteral) () file.Idx { return .Body.Idx1() } func ( *ClassLiteral) () file.Idx { return .RightBrace + 1 } func ( *ArrowFunctionLiteral) () file.Idx { return .Body.Idx1() } func ( *Identifier) () file.Idx { return file.Idx(int(.Idx) + len(.Name)) } func ( *NewExpression) () file.Idx { if .ArgumentList != nil { return .RightParenthesis + 1 } else { return .Callee.Idx1() } } func ( *NullLiteral) () file.Idx { return file.Idx(int(.Idx) + 4) } // "null" func ( *NumberLiteral) () file.Idx { return file.Idx(int(.Idx) + len(.Literal)) } func ( *ObjectLiteral) () file.Idx { return .RightBrace + 1 } func ( *ObjectPattern) () file.Idx { return .RightBrace + 1 } func ( *ParameterList) () file.Idx { return .Closing + 1 } func ( *RegExpLiteral) () file.Idx { return file.Idx(int(.Idx) + len(.Literal)) } func ( *SequenceExpression) () file.Idx { return .Sequence[len(.Sequence)-1].Idx1() } func ( *StringLiteral) () file.Idx { return file.Idx(int(.Idx) + len(.Literal)) } func ( *TemplateElement) () file.Idx { return file.Idx(int(.Idx) + len(.Literal)) } func ( *TemplateLiteral) () file.Idx { return .CloseQuote + 1 } func ( *ThisExpression) () file.Idx { return .Idx + 4 } func ( *SuperExpression) () file.Idx { return .Idx + 5 } func ( *UnaryExpression) () file.Idx { if .Postfix { return .Operand.Idx1() + 2 // ++ -- } return .Operand.Idx1() } func ( *MetaProperty) () file.Idx { return .Property.Idx1() } func ( *BadStatement) () file.Idx { return .To } func ( *BlockStatement) () file.Idx { return .RightBrace + 1 } func ( *BranchStatement) () file.Idx { if .Label == nil { return file.Idx(int(.Idx) + len(.Token.String())) } return .Label.Idx1() } func ( *CaseStatement) () file.Idx { return .Consequent[len(.Consequent)-1].Idx1() } func ( *CatchStatement) () file.Idx { return .Body.Idx1() } func ( *DebuggerStatement) () file.Idx { return .Debugger + 8 } func ( *DoWhileStatement) () file.Idx { return .RightParenthesis + 1 } func ( *EmptyStatement) () file.Idx { return .Semicolon + 1 } func ( *ExpressionStatement) () file.Idx { return .Expression.Idx1() } func ( *ForInStatement) () file.Idx { return .Body.Idx1() } func ( *ForOfStatement) () file.Idx { return .Body.Idx1() } func ( *ForStatement) () file.Idx { return .Body.Idx1() } func ( *IfStatement) () file.Idx { if .Alternate != nil { return .Alternate.Idx1() } return .Consequent.Idx1() } func ( *LabelledStatement) () file.Idx { return .Statement.Idx1() } func ( *Program) () file.Idx { return .Body[len(.Body)-1].Idx1() } func ( *ReturnStatement) () file.Idx { if .Argument != nil { return .Argument.Idx1() } return .Return + 6 } func ( *SwitchStatement) () file.Idx { return .RightBrace + 1 } func ( *ThrowStatement) () file.Idx { return .Argument.Idx1() } func ( *TryStatement) () file.Idx { if .Finally != nil { return .Finally.Idx1() } if .Catch != nil { return .Catch.Idx1() } return .Body.Idx1() } func ( *VariableStatement) () file.Idx { return .List[len(.List)-1].Idx1() } func ( *WhileStatement) () file.Idx { return .Body.Idx1() } func ( *WithStatement) () file.Idx { return .Body.Idx1() } func ( *LexicalDeclaration) () file.Idx { return .List[len(.List)-1].Idx1() } func ( *FunctionDeclaration) () file.Idx { return .Function.Idx1() } func ( *ClassDeclaration) () file.Idx { return .Class.Idx1() } func ( *Binding) () file.Idx { if .Initializer != nil { return .Initializer.Idx1() } return .Target.Idx1() } func ( *ForLoopInitializerExpression) () file.Idx { return .Expression.Idx1() } func ( *ForLoopInitializerVarDeclList) () file.Idx { return .List[len(.List)-1].Idx1() } func ( *ForLoopInitializerLexicalDecl) () file.Idx { return .LexicalDeclaration.Idx1() } func ( *PropertyShort) () file.Idx { if .Initializer != nil { return .Initializer.Idx1() } return .Name.Idx1() } func ( *PropertyKeyed) () file.Idx { return .Value.Idx1() } func ( *ExpressionBody) () file.Idx { return .Expression.Idx1() } func ( *VariableDeclaration) () file.Idx { if len(.List) > 0 { return .List[len(.List)-1].Idx1() } return .Var + 3 } func ( *FieldDefinition) () file.Idx { if .Initializer != nil { return .Initializer.Idx1() } return .Key.Idx1() } func ( *MethodDefinition) () file.Idx { return .Body.Idx1() } func ( *ClassStaticBlock) () file.Idx { return .Block.Idx1() } func ( *YieldExpression) () file.Idx { if .Argument != nil { return .Argument.Idx1() } return .Yield + 5 } func ( *ForDeclaration) () file.Idx { return .Target.Idx1() } func ( *ForIntoVar) () file.Idx { return .Binding.Idx1() } func ( *ForIntoExpression) () file.Idx { return .Expression.Idx1() }