Documentation
¶
Overview ¶
Package ast defines the abstract syntax tree (AST) for the TypeScript programming language and provides functionality for traversing the AST.
Example ¶
package main import ( "fmt" "github.com/armsnyder/typescript-ast-go/ast" "github.com/armsnyder/typescript-ast-go/parser" ) func main() { sourceFile := parser.Parse([]byte(` export interface ProgressParams<T> { token: ProgressToken; }`)) ast.Inspect(sourceFile, func(node ast.Node) bool { if node != nil { fmt.Printf("Visited %T\n", node) } return true }) }
Output: Visited *ast.SourceFile Visited *ast.InterfaceDeclaration Visited *ast.Identifier Visited *ast.PropertySignature Visited *ast.Identifier Visited *ast.TypeReference Visited *ast.Identifier
Index ¶
- func Inspect(node Node, f func(Node) bool)
- func Walk(v Visitor, node Node)
- type ArrayLiteralExpression
- type ArrayType
- type EnumDeclaration
- type EnumMember
- type Expr
- type ExpressionWithTypeArguments
- type HeritageClause
- type Identifier
- type IndexSignature
- type InterfaceDeclaration
- type LiteralType
- type ModuleBlock
- type ModuleDeclaration
- type Node
- type NumericLiteral
- type Parameter
- type ParenthesizedType
- type PrefixUnaryExpression
- type PropertySignature
- type QualifiedName
- type Signature
- type SourceFile
- type Stmt
- type StringLiteral
- type TupleType
- type Type
- type TypeAliasDeclaration
- type TypeLiteral
- type TypeParameter
- type TypeReference
- type UnionType
- type VariableDeclaration
- type VariableDeclarationList
- type VariableStatement
- type Visitor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Inspect ¶
Inspect traverses the AST rooted at node in depth-first order.
It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call to f(nil).
func Walk ¶
Walk traverses the AST rooted at node in depth-first order.
It starts by calling v.Visit(node); node must not be nil. If the visitor returned by v.Visit(node) is not nil, Walk is called recursively with the visitor and each of the non-nil children of node, followed by a call to w.Visit(nil).
Types ¶
type ArrayLiteralExpression ¶
type ArrayLiteralExpression struct {
Elements []Expr
}
ArrayLiteralExpression is an array literal expression.
type EnumDeclaration ¶
type EnumDeclaration struct { Name *Identifier Members []*EnumMember LeadingComment string }
EnumDeclaration is a statement that introduces a new enum.
func (*EnumDeclaration) String ¶
func (n *EnumDeclaration) String() string
type EnumMember ¶
type EnumMember struct { Name *Identifier Initializer Expr LeadingComment string }
EnumMember is an enum member expression.
func (*EnumMember) String ¶
func (n *EnumMember) String() string
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
Expr is a Node that represents an expression. An expression produces a value.
type ExpressionWithTypeArguments ¶
type ExpressionWithTypeArguments struct {
Expression *Identifier
}
ExpressionWithTypeArguments is an expression with type arguments.
type HeritageClause ¶
type HeritageClause struct {
Types []*ExpressionWithTypeArguments
}
HeritageClause is a heritage clause expression.
type Identifier ¶
type Identifier struct {
Text string
}
Identifier is an identifier literal expression.
func (*Identifier) String ¶
func (n *Identifier) String() string
type IndexSignature ¶
IndexSignature is an expression that defines an object index signature.
func (*IndexSignature) String ¶
func (n *IndexSignature) String() string
type InterfaceDeclaration ¶
type InterfaceDeclaration struct { Name *Identifier TypeParameters []*TypeParameter HeritageClauses []*HeritageClause Members []Signature LeadingComment string }
InterfaceDeclaration is a statement that introduces a new interface.
func (*InterfaceDeclaration) String ¶
func (n *InterfaceDeclaration) String() string
type LiteralType ¶
type LiteralType struct {
Literal Expr
}
LiteralType is a literal type expression.
type ModuleBlock ¶
type ModuleBlock struct {
Statements []Stmt
}
ModuleBlock is a statement that represents a block of statements in a module.
type ModuleDeclaration ¶
type ModuleDeclaration struct { Name *Identifier Body *ModuleBlock LeadingComment string }
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is a common interface that all nodes in the AST implement.
type NumericLiteral ¶
type NumericLiteral struct {
Text string
}
NumericLiteral is a numeric literal expression.
func (*NumericLiteral) String ¶
func (n *NumericLiteral) String() string
type Parameter ¶
type Parameter struct { Name *Identifier Type Type }
Parameter is a parameter expression.
type ParenthesizedType ¶
type ParenthesizedType struct {
Type Type
}
ParenthesizedType is an expression that wraps another expression in parentheses.
type PrefixUnaryExpression ¶
PrefixUnaryExpression is an expression that applies a unary operator to an operand.
type PropertySignature ¶
type PropertySignature struct { Name *Identifier QuestionToken bool Type Type LeadingComment string TrailingComment string }
PropertySignature is an expression that defines an object property.
func (*PropertySignature) String ¶
func (n *PropertySignature) String() string
type QualifiedName ¶
type QualifiedName struct { Left *Identifier Right *Identifier }
QualifiedName is a qualified name expression.
type Signature ¶
type Signature interface { Expr // contains filtered or unexported methods }
Signature is a Node that represents a signature. A signature defines a property.
type SourceFile ¶
type SourceFile struct {
Statements []Stmt
}
SourceFile is a statement that represents a source file.
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
Stmt is a Node that represents a statement. A statement performs an action.
type StringLiteral ¶
type StringLiteral struct {
Text string
}
StringLiteral is a string literal expression.
func (*StringLiteral) String ¶
func (n *StringLiteral) String() string
type Type ¶
type Type interface { Expr // contains filtered or unexported methods }
Type is a Node that represents a type expression. A type expression is a specific Expr that represents a type.
type TypeAliasDeclaration ¶
type TypeAliasDeclaration struct { Name *Identifier Type Type LeadingComment string }
TypeAliasDeclaration is a statement that introduces a new type alias.
func (*TypeAliasDeclaration) String ¶
func (n *TypeAliasDeclaration) String() string
type TypeLiteral ¶
type TypeLiteral struct {
Members []Signature
}
TypeLiteral is a type literal expression.
type TypeParameter ¶
type TypeParameter struct {
Name *Identifier
}
TypeParameter is a type parameter expression.
type TypeReference ¶
type TypeReference struct {
TypeName Expr
}
TypeReference is a type reference expression.
type VariableDeclaration ¶
type VariableDeclaration struct { Name *Identifier Type Type Initializer Expr }
VariableDeclaration is an expression that declares a variable.
type VariableDeclarationList ¶
type VariableDeclarationList struct {
Declarations []*VariableDeclaration
}
VariableDeclarationList is an expression that declares a list of variables.
type VariableStatement ¶
type VariableStatement struct { DeclarationList *VariableDeclarationList LeadingComment string }
VariableStatement is a statement that declares a variable.
func (*VariableStatement) String ¶
func (n *VariableStatement) String() string