ast

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ast defines the abstract syntax tree (AST) node types produced by the parser and consumed by the interpreter.

The tree is organized into two interface hierarchies — Expr for expressions and Stmt for statements — both extending the common Node interface. Every node carries the source position of its first token via Pos, and the position just past its last token via End, enabling precise error reporting.

The shape follows the ESTree specification loosely, adapted to idiomatic Go: concrete struct types with exported fields, small marker methods to seal the interfaces, and no visitor indirection (the interpreter type-switches).

ECMA-262 Reference: §13–§16 (Expressions, Statements, Functions, Programs).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(n Node) string

Dump returns a human-readable, indented tree rendering of an AST node. It is intended for debugging and for the CLI's --ast mode; the format is not stable and should not be parsed.

The dumper is reflection-based so it automatically covers every node type without a per-type visitor: for each node it prints the concrete type name followed by its exported fields, recursing into nested Node values, slices, and pointers.

Types

type ArrayLit

type ArrayLit struct {
	Lbracket token.Pos
	Rbracket token.Pos
	Elements []Expr // element may be nil (hole) or *SpreadElement
	// TrailingComma is set when the literal ends with a comma (e.g. `[a,]`). It
	// is benign for an array expression but, when the literal is refined into an
	// ArrayAssignmentPattern, an elision/comma may not follow a rest element.
	TrailingComma bool
}

ArrayLit is an array literal such as [1, 2, ...rest]. A nil element denotes an elision (a hole), e.g. [1, , 3].

func (*ArrayLit) End

func (e *ArrayLit) End() token.Pos

func (*ArrayLit) Pos

func (e *ArrayLit) Pos() token.Pos

type ArrowFunc

type ArrowFunc struct {
	Start      token.Pos
	Params     []Expr // Ident, patterns, or *RestElement
	Body       Node   // *BlockStmt or Expr
	Async      bool
	Expression bool // true when Body is an expression (concise body)
	Strict     bool // strict-mode code (own directive or lexically nested in strict code)
	// Source is the exact source text of the arrow function, returned by
	// Function.prototype.toString ([[SourceText]], §20.2.3.5).
	Source string
}

ArrowFunc is an arrow function (params) => body. Body is either a *BlockStmt or an expression (when Expression is true).

func (*ArrowFunc) End

func (e *ArrowFunc) End() token.Pos

func (*ArrowFunc) Pos

func (e *ArrowFunc) Pos() token.Pos

type AssignExpr

type AssignExpr struct {
	Target Expr // assignment target (Ident, MemberExpr, or destructuring pattern)
	OpPos  token.Pos
	Op     token.Type
	Value  Expr
}

AssignExpr is an assignment such as x = y or x += y. Op is token.ASSIGN for a plain assignment, or a compound-assignment token otherwise.

func (*AssignExpr) End

func (e *AssignExpr) End() token.Pos

func (*AssignExpr) Pos

func (e *AssignExpr) Pos() token.Pos

type AssignPattern

type AssignPattern struct {
	Target  Expr
	Default Expr
}

AssignPattern is a binding with a default value, target = default, used in parameter lists and destructuring patterns.

func (*AssignPattern) End

func (e *AssignPattern) End() token.Pos

func (*AssignPattern) Pos

func (e *AssignPattern) Pos() token.Pos

type AwaitExpr

type AwaitExpr struct {
	Keyword  token.Pos
	Argument Expr
}

AwaitExpr is an await expression inside an async function.

func (*AwaitExpr) End

func (e *AwaitExpr) End() token.Pos

func (*AwaitExpr) Pos

func (e *AwaitExpr) Pos() token.Pos

type BigIntLit

type BigIntLit struct {
	ValuePos token.Pos
	Raw      string // full spelling including trailing 'n'
	Digits   string // normalized decimal digits
}

BigIntLit is a BigInt literal such as 123n. Digits holds the decimal digit string without the trailing 'n'.

func (*BigIntLit) End

func (e *BigIntLit) End() token.Pos

func (*BigIntLit) Pos

func (e *BigIntLit) Pos() token.Pos

type BinaryExpr

type BinaryExpr struct {
	Left  Expr
	OpPos token.Pos
	Op    token.Type
	Right Expr
}

BinaryExpr is a binary operation such as a + b, a < b, a instanceof b. It does NOT include the short-circuiting logical operators (see LogicalExpr).

func (*BinaryExpr) End

func (e *BinaryExpr) End() token.Pos

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() token.Pos

type BlockStmt

type BlockStmt struct {
	Lbrace token.Pos
	Rbrace token.Pos
	Body   []Stmt
}

BlockStmt is a brace-delimited statement list { ... }.

func (*BlockStmt) End

func (s *BlockStmt) End() token.Pos

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() token.Pos

type BoolLit

type BoolLit struct {
	ValuePos token.Pos
	Value    bool
}

BoolLit is a boolean literal (true or false).

func (*BoolLit) End

func (e *BoolLit) End() token.Pos

func (*BoolLit) Pos

func (e *BoolLit) Pos() token.Pos

type BreakStmt

type BreakStmt struct {
	Keyword token.Pos
	Label   *Ident // nil for an unlabeled break
	EndPos  token.Pos
}

BreakStmt is a break statement, optionally with a label.

func (*BreakStmt) End

func (s *BreakStmt) End() token.Pos

func (*BreakStmt) Pos

func (s *BreakStmt) Pos() token.Pos

type CallExpr

type CallExpr struct {
	Callee    Expr
	Arguments []Expr // may contain *SpreadElement
	Rparen    token.Pos
	Optional  bool
}

CallExpr is a function call callee(args). When Optional is true it is an optional call (fn?.()).

func (*CallExpr) End

func (e *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (e *CallExpr) Pos() token.Pos

type CatchClause

type CatchClause struct {
	Keyword token.Pos
	Param   Expr // Ident or destructuring pattern, may be nil
	Body    *BlockStmt
}

CatchClause is the catch (param) { ... } part of a try statement. Param is nil for an optional-catch-binding form (catch { ... }).

type ClassDecl

type ClassDecl struct {
	Keyword token.Pos
	Def     *ClassDef
}

ClassDecl is a class declaration statement.

func (*ClassDecl) End

func (s *ClassDecl) End() token.Pos

func (*ClassDecl) Pos

func (s *ClassDecl) Pos() token.Pos

type ClassDef

type ClassDef struct {
	Name       *Ident // nil for anonymous class expressions
	SuperClass Expr   // nil when the class has no `extends` clause
	Members    []*ClassMember
	Lbrace     token.Pos
	Rbrace     token.Pos
}

ClassDef holds the shared shape of a class declaration or expression.

type ClassExpr

type ClassExpr struct {
	Keyword token.Pos
	Def     *ClassDef
}

ClassExpr is a class expression (see ClassDef).

func (*ClassExpr) End

func (e *ClassExpr) End() token.Pos

func (*ClassExpr) Pos

func (e *ClassExpr) Pos() token.Pos

type ClassMember

type ClassMember struct {
	KeyPos   token.Pos
	Key      Expr         // Ident, StringLit, NumberLit, PrivateIdent, or computed
	Value    Expr         // *FuncExpr for methods, initializer Expr for fields
	Kind     PropertyKind // PropInit (field/method), PropGet, or PropSet
	Static   bool
	Computed bool
	// Field reports whether this member is a class field (as opposed to a
	// method or accessor).
	Field bool
	// StaticBlock holds the body of a `static { ... }` initialization block.
	// When non-nil the member is a static block (Static is true and Key is nil);
	// it is neither a field nor a method.
	StaticBlock *BlockStmt
}

ClassMember is a single element of a class body: a method, accessor, or field.

func (*ClassMember) End

func (m *ClassMember) End() token.Pos

func (*ClassMember) Pos

func (m *ClassMember) Pos() token.Pos

type ConditionalExpr

type ConditionalExpr struct {
	Test       Expr
	Consequent Expr
	Alternate  Expr
}

ConditionalExpr is the ternary operator test ? cons : alt.

func (*ConditionalExpr) End

func (e *ConditionalExpr) End() token.Pos

func (*ConditionalExpr) Pos

func (e *ConditionalExpr) Pos() token.Pos

type ContinueStmt

type ContinueStmt struct {
	Keyword token.Pos
	Label   *Ident // nil for an unlabeled continue
	EndPos  token.Pos
}

ContinueStmt is a continue statement, optionally with a label.

func (*ContinueStmt) End

func (s *ContinueStmt) End() token.Pos

func (*ContinueStmt) Pos

func (s *ContinueStmt) Pos() token.Pos

type DebuggerStmt

type DebuggerStmt struct {
	Keyword token.Pos
	EndPos  token.Pos
}

DebuggerStmt is a debugger statement.

func (*DebuggerStmt) End

func (s *DebuggerStmt) End() token.Pos

func (*DebuggerStmt) Pos

func (s *DebuggerStmt) Pos() token.Pos

type DoWhileStmt

type DoWhileStmt struct {
	Keyword token.Pos
	Body    Stmt
	Test    Expr
	EndPos  token.Pos
}

DoWhileStmt is a do/while loop.

func (*DoWhileStmt) End

func (s *DoWhileStmt) End() token.Pos

func (*DoWhileStmt) Pos

func (s *DoWhileStmt) Pos() token.Pos

type EmptyStmt

type EmptyStmt struct {
	Semicolon token.Pos
}

EmptyStmt is a lone semicolon.

func (*EmptyStmt) End

func (s *EmptyStmt) End() token.Pos

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() token.Pos

type ExportSpecifier

type ExportSpecifier struct {
	Local    string
	Exported string
}

ExportSpecifier is one entry of an `export { local as exported }` clause.

type ExportStmt

type ExportStmt struct {
	Keyword     token.Pos
	Decl        Stmt               // exported declaration (*VarDecl/*FuncDecl/*ClassDecl); nil otherwise
	DefaultExpr Expr               // `export default <expr>`; nil otherwise
	Specifiers  []*ExportSpecifier // `export { … }` entries
	Default     bool               // true for `export default …`
	// Source is the decoded `from` module specifier of a re-export
	// (`export { … } from 'src'`, `export * from 'src'`), or "" when absent.
	Source string
	// Star is true for `export * [as name] from 'src'`; StarName holds the
	// namespace alias of `export * as name from 'src'` ("" for a bare `export *`).
	Star     bool
	StarName string
	EndPos   token.Pos
}

ExportStmt is an ES-module export declaration. It appears only in module code. The variants it captures are:

  • export var/let/const/function/class … (Decl set, Default false)
  • export default function/class … (Decl set, Default true)
  • export default AssignmentExpression; (DefaultExpr set, Default true)
  • export { a, b as c }; (Specifiers set)

func (*ExportStmt) End

func (s *ExportStmt) End() token.Pos

func (*ExportStmt) Pos

func (s *ExportStmt) Pos() token.Pos

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr is the interface implemented by all expression nodes.

type ExprStmt

type ExprStmt struct {
	X Expr
	// Directive holds the string value when this statement is a directive
	// prologue entry such as "use strict"; otherwise it is empty.
	Directive string
}

ExprStmt is an expression used in statement position.

func (*ExprStmt) End

func (s *ExprStmt) End() token.Pos

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() token.Pos

type ForInStmt

type ForInStmt struct {
	Keyword token.Pos
	Left    Node // *VarDecl or Expr
	Right   Expr
	Body    Stmt
	Of      bool // true for for-of, false for for-in
	Await   bool // true for `for await (... of ...)`
}

ForInStmt is a for-in or for-of loop. Of distinguishes the two. Left is a *VarDecl or an assignment target Expr.

func (*ForInStmt) End

func (s *ForInStmt) End() token.Pos

func (*ForInStmt) Pos

func (s *ForInStmt) Pos() token.Pos

type ForStmt

type ForStmt struct {
	Keyword token.Pos
	Init    Node // *VarDecl, Expr, or nil
	Test    Expr
	Update  Expr
	Body    Stmt
}

ForStmt is a C-style for loop: for (init; test; update) body. Any of Init, Test, Update may be nil. Init is either a *VarDecl or an Expr.

func (*ForStmt) End

func (s *ForStmt) End() token.Pos

func (*ForStmt) Pos

func (s *ForStmt) Pos() token.Pos

type FuncDecl

type FuncDecl struct {
	Keyword token.Pos
	Def     *FuncDef
}

FuncDecl is a function declaration statement.

func (*FuncDecl) End

func (s *FuncDecl) End() token.Pos

func (*FuncDecl) Pos

func (s *FuncDecl) Pos() token.Pos

type FuncDef

type FuncDef struct {
	Name      *Ident // nil for anonymous function expressions
	Params    []Expr // Ident, patterns, AssignPattern, or *RestElement
	Body      *BlockStmt
	Async     bool
	Generator bool
	// Strict reports whether this function's body runs in strict mode, either
	// because it carries its own "use strict" directive prologue or because it
	// is lexically nested in strict code (a strict script, module, or function).
	Strict bool
	// Source is the exact source text of the whole function/method definition —
	// the [[SourceText]] returned by Function.prototype.toString (§20.2.3.5). It
	// is empty for functions with no available source (the Function constructor
	// builds its own), in which case toString uses the NativeFunction form.
	Source string
}

FuncDef holds the shared shape of a function: its (optional) name, parameter list, and body. It is embedded by FuncDecl, FuncExpr, and object/class methods so the interpreter can treat all callable definitions uniformly.

type FuncExpr

type FuncExpr struct {
	Keyword token.Pos
	Def     *FuncDef
}

FuncExpr is a function expression: function (params) { body } or a named function expression. It shares its shape with function declarations via the embedded FuncDef.

func (*FuncExpr) End

func (e *FuncExpr) End() token.Pos

func (*FuncExpr) Pos

func (e *FuncExpr) Pos() token.Pos

type Ident

type Ident struct {
	NamePos token.Pos
	Name    string
	// Parenthesized marks an identifier that appeared as the immediate content of
	// a ParenthesizedExpression, e.g. `(fn)`. Such an operand is a
	// CoverParenthesizedExpression, whose IsIdentifierRef is false (§13.2.5.2), so
	// it does not trigger NamedEvaluation: `(fn) = function(){}` leaves the
	// function anonymous even though a bare `fn = function(){}` would name it.
	Parenthesized bool
}

Ident is an identifier reference such as a variable name.

func (*Ident) End

func (e *Ident) End() token.Pos

func (*Ident) Pos

func (e *Ident) Pos() token.Pos

type IfStmt

type IfStmt struct {
	Keyword    token.Pos
	Test       Expr
	Consequent Stmt
	Alternate  Stmt
}

IfStmt is an if/else statement. Alternate is nil when there is no else.

func (*IfStmt) End

func (s *IfStmt) End() token.Pos

func (*IfStmt) Pos

func (s *IfStmt) Pos() token.Pos

type ImportCall

type ImportCall struct {
	Keyword   token.Pos
	Specifier Expr
	Options   Expr // the optional second argument; nil when absent
	Rparen    token.Pos
}

ImportCall is a dynamic import() expression (ECMA-262 ES2020): import(Specifier) or import(Specifier, Options). It evaluates to a Promise for the imported module's namespace object. It is distinct from an import declaration and from the import.meta meta-property.

func (*ImportCall) End

func (e *ImportCall) End() token.Pos

func (*ImportCall) Pos

func (e *ImportCall) Pos() token.Pos

type LabeledStmt

type LabeledStmt struct {
	Label *Ident
	Body  Stmt
}

LabeledStmt is a labeled statement label: stmt.

func (*LabeledStmt) End

func (s *LabeledStmt) End() token.Pos

func (*LabeledStmt) Pos

func (s *LabeledStmt) Pos() token.Pos

type LogicalExpr

type LogicalExpr struct {
	Left  Expr
	OpPos token.Pos
	Op    token.Type
	Right Expr
}

LogicalExpr is a short-circuiting logical operation: &&, ||, or ?? (nullish coalescing). It is distinct from BinaryExpr because evaluation order and short-circuit semantics differ.

func (*LogicalExpr) End

func (e *LogicalExpr) End() token.Pos

func (*LogicalExpr) Pos

func (e *LogicalExpr) Pos() token.Pos

type MemberExpr

type MemberExpr struct {
	Object   Expr
	Property Expr // Ident (dot) / PrivateIdent, or arbitrary Expr (computed)
	EndPos   token.Pos
	Computed bool
	Optional bool
}

MemberExpr is a property access a.b or a[b]. When Optional is true the access is part of an optional chain (a?.b).

func (*MemberExpr) End

func (e *MemberExpr) End() token.Pos

func (*MemberExpr) Pos

func (e *MemberExpr) Pos() token.Pos

type NewExpr

type NewExpr struct {
	Keyword   token.Pos
	Callee    Expr
	Arguments []Expr
	EndPos    token.Pos
}

NewExpr is a constructor invocation new Callee(args).

func (*NewExpr) End

func (e *NewExpr) End() token.Pos

func (*NewExpr) Pos

func (e *NewExpr) Pos() token.Pos

type Node

type Node interface {
	// Pos returns the position of the node's first token.
	Pos() token.Pos
	// End returns the position immediately after the node's last token.
	End() token.Pos
}

Node is the interface implemented by every AST node.

type NullLit

type NullLit struct {
	ValuePos token.Pos
}

NullLit is the null literal.

func (*NullLit) End

func (e *NullLit) End() token.Pos

func (*NullLit) Pos

func (e *NullLit) Pos() token.Pos

type NumberLit

type NumberLit struct {
	ValuePos token.Pos
	Value    float64
	Raw      string
}

NumberLit is a numeric literal. Value holds the parsed IEEE-754 value; Raw preserves the original spelling (e.g. "0xff", "1_000").

func (*NumberLit) End

func (e *NumberLit) End() token.Pos

func (*NumberLit) Pos

func (e *NumberLit) Pos() token.Pos

type ObjectLit

type ObjectLit struct {
	Lbrace     token.Pos
	Rbrace     token.Pos
	Properties []*Property
}

ObjectLit is an object literal such as { a: 1, b, ...rest, [k]: v }.

func (*ObjectLit) End

func (e *ObjectLit) End() token.Pos

func (*ObjectLit) Pos

func (e *ObjectLit) Pos() token.Pos

type PrivateIdent

type PrivateIdent struct {
	NamePos token.Pos
	Name    string // includes the leading '#'
}

PrivateIdent is a private class member name such as #count. It is only valid inside a class body (as a member key or in a `#x in obj` check).

func (*PrivateIdent) End

func (e *PrivateIdent) End() token.Pos

func (*PrivateIdent) Pos

func (e *PrivateIdent) Pos() token.Pos

type Program

type Program struct {
	Source string // source name (filename or "<eval>")
	Body   []Stmt // top-level statements
	// Strict reports whether the program body began with a "use strict"
	// directive prologue.
	Strict bool
	// EndPos is the position of the trailing EOF token.
	EndPos token.Pos
}

Program is the root node of a parsed source file (a Script goal symbol). It holds the top-level statement list plus source metadata.

func (*Program) End

func (p *Program) End() token.Pos

End returns the end of the program.

func (*Program) Pos

func (p *Program) Pos() token.Pos

Pos returns the start of the program (position of the first statement, or the EOF position for an empty program).

type Property

type Property struct {
	KeyPos token.Pos
	Key    Expr // Ident, StringLit, NumberLit, or computed Expr
	Value  Expr // value expression (nil for spread's separate handling)
	Kind   PropertyKind
	// Computed reports whether the key was written as [expr].
	Computed bool
	// Shorthand reports whether this was written as { x } rather than { x: x }.
	Shorthand bool
	// Method reports whether the value is a concise method definition.
	Method bool
}

Property is a single member of an object literal.

func (*Property) End

func (p *Property) End() token.Pos

func (*Property) Pos

func (p *Property) Pos() token.Pos

type PropertyKind

type PropertyKind int

PropertyKind classifies an object-literal or class member.

const (
	// PropInit is a normal data property (key: value or shorthand).
	PropInit PropertyKind = iota
	// PropGet is a getter accessor (get key() {...}).
	PropGet
	// PropSet is a setter accessor (set key(v) {...}).
	PropSet
	// PropSpread is a spread element (...expr).
	PropSpread
)

type RegexLit

type RegexLit struct {
	ValuePos token.Pos
	Pattern  string
	Flags    string
	Raw      string
}

RegexLit is a regular-expression literal /pattern/flags.

func (*RegexLit) End

func (e *RegexLit) End() token.Pos

func (*RegexLit) Pos

func (e *RegexLit) Pos() token.Pos

type RestElement

type RestElement struct {
	Ellipsis token.Pos
	Target   Expr
}

RestElement is a rest binding ...target used in parameter lists and destructuring patterns.

func (*RestElement) End

func (e *RestElement) End() token.Pos

func (*RestElement) Pos

func (e *RestElement) Pos() token.Pos

type ReturnStmt

type ReturnStmt struct {
	Keyword  token.Pos
	Argument Expr
	EndPos   token.Pos
}

ReturnStmt is a return statement. Argument is nil for a bare return.

func (*ReturnStmt) End

func (s *ReturnStmt) End() token.Pos

func (*ReturnStmt) Pos

func (s *ReturnStmt) Pos() token.Pos

type SequenceExpr

type SequenceExpr struct {
	Exprs []Expr
}

SequenceExpr is a comma expression (a, b, c) evaluating to its last operand.

func (*SequenceExpr) End

func (e *SequenceExpr) End() token.Pos

func (*SequenceExpr) Pos

func (e *SequenceExpr) Pos() token.Pos

type SpreadElement

type SpreadElement struct {
	Ellipsis token.Pos
	Argument Expr
}

SpreadElement is a spread/rest element ...expr used in array/call/object contexts.

func (*SpreadElement) End

func (e *SpreadElement) End() token.Pos

func (*SpreadElement) Pos

func (e *SpreadElement) Pos() token.Pos

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt is the interface implemented by all statement nodes.

type StringLit

type StringLit struct {
	ValuePos token.Pos
	Value    string
	Raw      string
}

StringLit is a string literal. Value holds the decoded contents; Raw includes the surrounding quotes.

func (*StringLit) End

func (e *StringLit) End() token.Pos

func (*StringLit) Pos

func (e *StringLit) Pos() token.Pos

type SuperExpr

type SuperExpr struct {
	Keyword token.Pos
}

SuperExpr is the `super` keyword (valid only as a member/call base inside class methods).

func (*SuperExpr) End

func (e *SuperExpr) End() token.Pos

func (*SuperExpr) Pos

func (e *SuperExpr) Pos() token.Pos

type SwitchCase

type SwitchCase struct {
	CasePos token.Pos
	Test    Expr // nil for `default:`
	Body    []Stmt
}

SwitchCase is one case/default clause. Test is nil for the default clause.

type SwitchStmt

type SwitchStmt struct {
	Keyword      token.Pos
	Discriminant Expr
	Cases        []*SwitchCase
	Rbrace       token.Pos
}

SwitchStmt is a switch statement.

func (*SwitchStmt) End

func (s *SwitchStmt) End() token.Pos

func (*SwitchStmt) Pos

func (s *SwitchStmt) Pos() token.Pos

type TaggedTemplateExpr

type TaggedTemplateExpr struct {
	Tag   Expr
	Quasi *TemplateLit
}

TaggedTemplateExpr is a tagged template such as tag`a${x}b`.

func (*TaggedTemplateExpr) End

func (e *TaggedTemplateExpr) End() token.Pos

func (*TaggedTemplateExpr) Pos

func (e *TaggedTemplateExpr) Pos() token.Pos

type TemplateElement

type TemplateElement struct {
	Pos    token.Pos
	Cooked string // interpreted value (with escapes processed)
	Raw    string // exact source text
	// CookedInvalid reports that this segment contained an escape with no cooked
	// value (a legacy octal, \8/\9, or malformed hex/unicode escape). It is an
	// early SyntaxError in an untagged template; a tagged template yields an
	// undefined cooked value for the segment (ECMA-262 §12.9.6).
	CookedInvalid bool
}

TemplateElement is one cooked/raw string segment of a template literal.

type TemplateLit

type TemplateLit struct {
	Start  token.Pos
	EndPos token.Pos
	Quasis []TemplateElement
	Exprs  []Expr
}

TemplateLit is a template literal `a${x}b`. Quasis holds the literal string segments; Exprs holds the interpolated expressions. len(Quasis) is always len(Exprs)+1.

func (*TemplateLit) End

func (e *TemplateLit) End() token.Pos

func (*TemplateLit) Pos

func (e *TemplateLit) Pos() token.Pos

type ThisExpr

type ThisExpr struct {
	Keyword token.Pos
}

ThisExpr is the `this` keyword.

func (*ThisExpr) End

func (e *ThisExpr) End() token.Pos

func (*ThisExpr) Pos

func (e *ThisExpr) Pos() token.Pos

type ThrowStmt

type ThrowStmt struct {
	Keyword  token.Pos
	Argument Expr
	EndPos   token.Pos
}

ThrowStmt is a throw statement.

func (*ThrowStmt) End

func (s *ThrowStmt) End() token.Pos

func (*ThrowStmt) Pos

func (s *ThrowStmt) Pos() token.Pos

type TryStmt

type TryStmt struct {
	Keyword   token.Pos
	Block     *BlockStmt
	Handler   *CatchClause // nil when there is no catch
	Finalizer *BlockStmt   // nil when there is no finally
}

TryStmt is a try/catch/finally statement. Handler and Finalizer may be nil, but at least one is always present.

func (*TryStmt) End

func (s *TryStmt) End() token.Pos

func (*TryStmt) Pos

func (s *TryStmt) Pos() token.Pos

type UnaryExpr

type UnaryExpr struct {
	OpPos   token.Pos
	Op      token.Type
	Operand Expr
}

UnaryExpr is a prefix unary operation such as -x, !x, typeof x, void x, delete x.

func (*UnaryExpr) End

func (e *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() token.Pos

type UpdateExpr

type UpdateExpr struct {
	OpPos   token.Pos
	Op      token.Type // token.INC or token.DEC
	Operand Expr
	Prefix  bool
}

UpdateExpr is an increment/decrement (++x, x--). Prefix distinguishes ++x from x++.

func (*UpdateExpr) End

func (e *UpdateExpr) End() token.Pos

func (*UpdateExpr) Pos

func (e *UpdateExpr) Pos() token.Pos

type VarDecl

type VarDecl struct {
	Keyword token.Pos
	Kind    token.Type // token.VAR, token.LET, or token.CONST
	Decls   []*VarDeclarator
	EndPos  token.Pos
}

VarDecl is a variable declaration: var/let/const with one or more declarators.

func (*VarDecl) End

func (s *VarDecl) End() token.Pos

func (*VarDecl) Pos

func (s *VarDecl) Pos() token.Pos

type VarDeclarator

type VarDeclarator struct {
	Target Expr // Ident or a destructuring pattern (ArrayLit/ObjectLit)
	Init   Expr // may be nil
}

VarDeclarator is a single name = init binding within a VarDecl.

func (*VarDeclarator) End

func (d *VarDeclarator) End() token.Pos

func (*VarDeclarator) Pos

func (d *VarDeclarator) Pos() token.Pos

type WhileStmt

type WhileStmt struct {
	Keyword token.Pos
	Test    Expr
	Body    Stmt
}

WhileStmt is a while loop.

func (*WhileStmt) End

func (s *WhileStmt) End() token.Pos

func (*WhileStmt) Pos

func (s *WhileStmt) Pos() token.Pos

type WithStmt

type WithStmt struct {
	Keyword token.Pos
	Object  Expr
	Body    Stmt
}

WithStmt is a `with (Object) Body` statement (legacy, sloppy-mode only).

func (*WithStmt) End

func (s *WithStmt) End() token.Pos

func (*WithStmt) Pos

func (s *WithStmt) Pos() token.Pos

type YieldExpr

type YieldExpr struct {
	Keyword  token.Pos
	Argument Expr // may be nil
	Delegate bool
}

YieldExpr is a yield expression inside a generator. Delegate marks yield*.

func (*YieldExpr) End

func (e *YieldExpr) End() token.Pos

func (*YieldExpr) Pos

func (e *YieldExpr) Pos() token.Pos

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL