esbuilder

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 7 Imported by: 4

Documentation

Overview

The esbuilder package implements an ECMAScript AST for easier generation of code with source mapping references.

Index

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

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 Snippet

func Snippet(code string) ExpressionBuilder

Snippet returns a new snippet.

func Ternary

Ternary returns a new ternary operator on the check, left and right child expressions.

func Value

func Value(value interface{}) ExpressionBuilder

Value returns a literal value.

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 Return

func Return() StatementBuilder

Return returns a new return 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.

Jump to

Keyboard shortcuts

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