Source File
node.go
Belonging Package
github.com/dop251/goja/ast
/*Package ast declares types representing a JavaScript AST.# WarningThe parser and AST interfaces are still works-in-progress (particularly wherenode types are concerned) and may change in the future.*/package astimport ()type PropertyKind stringconst (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 nodeIdx1() 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 BindingTargetInitializer Expression}Pattern interface {BindingTarget_pattern()}YieldExpression struct {Yield file.IdxArgument ExpressionDelegate bool}AwaitExpression struct {Await file.IdxArgument Expression}ArrayLiteral struct {LeftBracket file.IdxRightBracket file.IdxValue []Expression}ArrayPattern struct {LeftBracket file.IdxRightBracket file.IdxElements []ExpressionRest Expression}AssignExpression struct {Operator token.TokenLeft ExpressionRight Expression}BadExpression struct {From file.IdxTo file.Idx}BinaryExpression struct {Operator token.TokenLeft ExpressionRight ExpressionComparison bool}BooleanLiteral struct {Idx file.IdxLiteral stringValue bool}BracketExpression struct {Left ExpressionMember ExpressionLeftBracket file.IdxRightBracket file.Idx}CallExpression struct {Callee ExpressionLeftParenthesis file.IdxArgumentList []ExpressionRightParenthesis file.Idx}ConditionalExpression struct {Test ExpressionConsequent ExpressionAlternate Expression}DotExpression struct {Left ExpressionIdentifier Identifier}PrivateDotExpression struct {Left ExpressionIdentifier PrivateIdentifier}OptionalChain struct {Expression}Optional struct {Expression}FunctionLiteral struct {Function file.IdxName *IdentifierParameterList *ParameterListBody *BlockStatementSource stringDeclarationList []*VariableDeclarationAsync, Generator bool}ClassLiteral struct {Class file.IdxRightBrace file.IdxName *IdentifierSuperClass ExpressionBody []ClassElementSource string}ConciseBody interface {Node_conciseBody()}ExpressionBody struct {Expression Expression}ArrowFunctionLiteral struct {Start file.IdxParameterList *ParameterListBody ConciseBodySource stringDeclarationList []*VariableDeclarationAsync bool}Identifier struct {Name unistring.StringIdx file.Idx}PrivateIdentifier struct {Identifier}NewExpression struct {New file.IdxCallee ExpressionLeftParenthesis file.IdxArgumentList []ExpressionRightParenthesis file.Idx}NullLiteral struct {Idx file.IdxLiteral string}NumberLiteral struct {Idx file.IdxLiteral stringValue interface{}}ObjectLiteral struct {LeftBrace file.IdxRightBrace file.IdxValue []Property}ObjectPattern struct {LeftBrace file.IdxRightBrace file.IdxProperties []PropertyRest Expression}ParameterList struct {Opening file.IdxList []*BindingRest ExpressionClosing file.Idx}Property interface {Expression_property()}PropertyShort struct {Name IdentifierInitializer Expression}PropertyKeyed struct {Key ExpressionKind PropertyKindValue ExpressionComputed bool}SpreadElement struct {Expression}RegExpLiteral struct {Idx file.IdxLiteral stringPattern stringFlags string}SequenceExpression struct {Sequence []Expression}StringLiteral struct {Idx file.IdxLiteral stringValue unistring.String}TemplateElement struct {Idx file.IdxLiteral stringParsed unistring.StringValid bool}TemplateLiteral struct {OpenQuote file.IdxCloseQuote file.IdxTag ExpressionElements []*TemplateElementExpressions []Expression}ThisExpression struct {Idx file.Idx}SuperExpression struct {Idx file.Idx}UnaryExpression struct {Operator token.TokenIdx file.Idx // If a prefix operationOperand ExpressionPostfix bool}MetaProperty struct {Meta, Property *IdentifierIdx file.Idx})// _expressionNodefunc (*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.IdxTo file.Idx}BlockStatement struct {LeftBrace file.IdxList []StatementRightBrace file.Idx}BranchStatement struct {Idx file.IdxToken token.TokenLabel *Identifier}CaseStatement struct {Case file.IdxTest ExpressionConsequent []Statement}CatchStatement struct {Catch file.IdxParameter BindingTargetBody *BlockStatement}DebuggerStatement struct {Debugger file.Idx}DoWhileStatement struct {Do file.IdxTest ExpressionBody StatementRightParenthesis file.Idx}EmptyStatement struct {Semicolon file.Idx}ExpressionStatement struct {Expression Expression}ForInStatement struct {For file.IdxInto ForIntoSource ExpressionBody Statement}ForOfStatement struct {For file.IdxInto ForIntoSource ExpressionBody Statement}ForStatement struct {For file.IdxInitializer ForLoopInitializerUpdate ExpressionTest ExpressionBody Statement}IfStatement struct {If file.IdxTest ExpressionConsequent StatementAlternate Statement}LabelledStatement struct {Label *IdentifierColon file.IdxStatement Statement}ReturnStatement struct {Return file.IdxArgument Expression}SwitchStatement struct {Switch file.IdxDiscriminant ExpressionDefault intBody []*CaseStatementRightBrace file.Idx}ThrowStatement struct {Throw file.IdxArgument Expression}TryStatement struct {Try file.IdxBody *BlockStatementCatch *CatchStatementFinally *BlockStatement}VariableStatement struct {Var file.IdxList []*Binding}LexicalDeclaration struct {Idx file.IdxToken token.TokenList []*Binding}WhileStatement struct {While file.IdxTest ExpressionBody Statement}WithStatement struct {With file.IdxObject ExpressionBody Statement}FunctionDeclaration struct {Function *FunctionLiteral}ClassDeclaration struct {Class *ClassLiteral})// _statementNodefunc (*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.IdxList []*Binding}ClassElement interface {Node_classElement()}FieldDefinition struct {Idx file.IdxKey ExpressionInitializer ExpressionComputed boolStatic bool}MethodDefinition struct {Idx file.IdxKey ExpressionKind PropertyKind // "method", "get" or "set"Body *FunctionLiteralComputed boolStatic bool}ClassStaticBlock struct {Static file.IdxBlock *BlockStatementSource stringDeclarationList []*VariableDeclaration})type (ForLoopInitializer interface {Node_forLoopInitializer()}ForLoopInitializerExpression struct {Expression Expression}ForLoopInitializerVarDeclList struct {Var file.IdxList []*Binding}ForLoopInitializerLexicalDecl struct {LexicalDeclaration LexicalDeclaration}ForInto interface {Node_forInto()}ForIntoVar struct {Binding *Binding}ForDeclaration struct {Idx file.IdxIsConst boolTarget 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 []StatementDeclarationList []*VariableDeclarationFile *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() }
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |