Documentation ¶
Overview ¶
The esbuilder package implements an ECMAScript AST for easier generation of code with source mapping references.
Index ¶
- func BuildSource(builder SourceBuilder) bytes.Buffer
- func BuildSourceAndMap(builder SourceBuilder, sm *sourcemap.SourceMap) bytes.Buffer
- type ExpressionBuilder
- func Array(values ...ExpressionBuilder) ExpressionBuilder
- func Assignment(target ExpressionBuilder, value ExpressionBuilder) ExpressionBuilder
- func Binary(left ExpressionBuilder, op string, right ExpressionBuilder) ExpressionBuilder
- func Call(expression ExpressionBuilder, arguments ...ExpressionBuilder) ExpressionBuilder
- func Closure(body SourceBuilder, parameters ...string) ExpressionBuilder
- func ExprMember(expression ExpressionBuilder, name ExpressionBuilder) ExpressionBuilder
- func ExpressionList(valueExpr ExpressionBuilder, exprs ...ExpressionBuilder) ExpressionBuilder
- func Function(name string, body SourceBuilder, parameters ...string) ExpressionBuilder
- func Identifier(name string) ExpressionBuilder
- func LiteralValue(value string) ExpressionBuilder
- func Member(expression ExpressionBuilder, name string) ExpressionBuilder
- func Object(entries ...ExpressionBuilder) ExpressionBuilder
- func ObjectEntry(key string, value ExpressionBuilder) ExpressionBuilder
- func Postfix(child ExpressionBuilder, op string) ExpressionBuilder
- func Prefix(op string, child ExpressionBuilder) ExpressionBuilder
- func Snippet(code string) ExpressionBuilder
- func Ternary(check ExpressionBuilder, left ExpressionBuilder, right ExpressionBuilder) ExpressionBuilder
- func Value(value interface{}) ExpressionBuilder
- type SourceBuilder
- type StatementBuilder
- func ExprStatement(expr ExpressionBuilder) StatementBuilder
- func If(condition ExpressionBuilder, thenStatement StatementBuilder) StatementBuilder
- func IfElse(condition ExpressionBuilder, thenStatement StatementBuilder, ...) StatementBuilder
- func Return() StatementBuilder
- func Returns(value ExpressionBuilder) StatementBuilder
- func Statements(statements ...StatementBuilder) StatementBuilder
- func Variable(name string) StatementBuilder
- func VariableWithInit(name string, value ExpressionBuilder) StatementBuilder
- type TemplateSourceBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSource ¶
func BuildSource(builder SourceBuilder) bytes.Buffer
BuildSource builds the full source for the given builder.
func BuildSourceAndMap ¶
func BuildSourceAndMap(builder SourceBuilder, sm *sourcemap.SourceMap) bytes.Buffer
BuildSourceAndMap builds the full source and sourcemap for the given builder.
Types ¶
type ExpressionBuilder ¶
type ExpressionBuilder interface { // WithMapping adds a source mapping to the expression being built. WithMapping(mapping sourcemap.SourceMapping) SourceBuilder // WithMappingAsExpr adds a source mapping to the expression being built. WithMappingAsExpr(mapping sourcemap.SourceMapping) ExpressionBuilder // Member returns an expression builder of an expression of a member under // this expression. Member(name interface{}) ExpressionBuilder // Call returns an expression builder of an expression calling this expression. Call(arguments ...interface{}) ExpressionBuilder // Returns true if the current expression is stateless. IsStateless() bool // contains filtered or unexported methods }
ExpressionBuilder defines an interface for all expressions.
func Array ¶
func Array(values ...ExpressionBuilder) ExpressionBuilder
Array returns an array literal.
func Assignment ¶
func Assignment(target ExpressionBuilder, value ExpressionBuilder) ExpressionBuilder
Assignment returns a new assignment operator.
func Binary ¶
func Binary(left ExpressionBuilder, op string, right ExpressionBuilder) ExpressionBuilder
Binary returns a new binary operator on left and right child expressions.
func Call ¶
func Call(expression ExpressionBuilder, arguments ...ExpressionBuilder) ExpressionBuilder
Call returns a function call.
func Closure ¶
func Closure(body SourceBuilder, parameters ...string) ExpressionBuilder
Closure returns an anonymous closure.
func ExprMember ¶
func ExprMember(expression ExpressionBuilder, name ExpressionBuilder) ExpressionBuilder
ExprMember returns a member under another expression.
func ExpressionList ¶
func ExpressionList(valueExpr ExpressionBuilder, exprs ...ExpressionBuilder) ExpressionBuilder
ExpressionList returns an expression list.
func Function ¶
func Function(name string, body SourceBuilder, parameters ...string) ExpressionBuilder
Function returns a named function.
func Identifier ¶
func Identifier(name string) ExpressionBuilder
Identifier returns a new identifier.
func LiteralValue ¶
func LiteralValue(value string) ExpressionBuilder
LiteralValue returns a literal value.
func Member ¶
func Member(expression ExpressionBuilder, name string) ExpressionBuilder
Member returns a member under another expression.
func Object ¶
func Object(entries ...ExpressionBuilder) ExpressionBuilder
Object returns an object literal.
func ObjectEntry ¶
func ObjectEntry(key string, value ExpressionBuilder) ExpressionBuilder
ObjectEntry returns an object literal entry.
func Postfix ¶
func Postfix(child ExpressionBuilder, op string) ExpressionBuilder
Postfix returns a new postfixed operator on an expression.
func Prefix ¶
func Prefix(op string, child ExpressionBuilder) ExpressionBuilder
Prefix returns a new prefixed operator on an expression.
func Ternary ¶
func Ternary(check ExpressionBuilder, left ExpressionBuilder, right ExpressionBuilder) ExpressionBuilder
Ternary returns a new ternary operator on the check, left and right child expressions.
type SourceBuilder ¶
type SourceBuilder interface { // WithMapping adds a source mapping to the item being built. WithMapping(mapping sourcemap.SourceMapping) SourceBuilder // contains filtered or unexported methods }
SourceBuilder defines an interface for all expressions, statements and templates.
type StatementBuilder ¶
type StatementBuilder interface { // WithMapping adds a source mapping to the statement being built. WithMapping(mapping sourcemap.SourceMapping) SourceBuilder // contains filtered or unexported methods }
StatementBuilder defines an interface for all statements.
func ExprStatement ¶
func ExprStatement(expr ExpressionBuilder) StatementBuilder
ExprStatement returns an expression as a statement.
func If ¶
func If(condition ExpressionBuilder, thenStatement StatementBuilder) StatementBuilder
If returns a new conditional statement.
func IfElse ¶
func IfElse(condition ExpressionBuilder, thenStatement StatementBuilder, elseStatement StatementBuilder) StatementBuilder
IfElse returns a new conditional statement.
func Returns ¶
func Returns(value ExpressionBuilder) StatementBuilder
Returns returns a new return statement with a value.
func Statements ¶
func Statements(statements ...StatementBuilder) StatementBuilder
Statements returns a block of statements.
func Variable ¶
func Variable(name string) StatementBuilder
Variable returns a variable declaration statement.
func VariableWithInit ¶
func VariableWithInit(name string, value ExpressionBuilder) StatementBuilder
VariableWithInit returns a variable declaration statement.
type TemplateSourceBuilder ¶
type TemplateSourceBuilder interface { // WithMapping adds a source mapping to the block being built. WithMapping(mapping sourcemap.SourceMapping) SourceBuilder // AsExpression returns the template as an expression. AsExpression() ExpressionBuilder // contains filtered or unexported methods }
TemplateSourceBuilder defines an interface for a templated code block.
func Template ¶
func Template(name string, template string, data interface{}) TemplateSourceBuilder
Template returns an inline templated code block.