goesprima

package module
v0.0.0-...-ba369af Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 6 Imported by: 0

README

Go Esprima

Esprima JS implementation in Go for code generation & script execution. Based on the Esprima AST and the JQuery implementation.

Installation

go install github.com/MichaelCombs28/goesprima

Usage

Currently goesprima only supports manual AST code generation.

package main

import (
  "fmt"
  esp "github.com/MichaelCombs28/goesprima"
)

func main() {
  gen := esp.NewGenerator()
  gen.AddStatements(
    &esp.ImportDeclaration{
      Source: "@aws-amplify/core",
      Specifiers: []esp.ImportDeclarationSpecifier{
        &esp.ImportDefaultSpecifier{
          Local: &esp.Identifier{
            Name: "Amplify",
          },
        },
      },
    },
  )
  fmt.Println(gen.String())
}

Roadmap

  • Parsing & Tokenization
  • Code Execution

License

MIT

Documentation

Index

Constants

View Source
const (
	AssignmentOperatorEq     assignmentOperator = "="
	AssignmentOperatorPlus   assignmentOperator = "+="
	AssignmentOperatorMinus  assignmentOperator = "-="
	AssignmentOperatorTimes  assignmentOperator = "*="
	AssignmentOperatorDivide assignmentOperator = "/="
	AssignmentOperatorMod    assignmentOperator = "%="
)
View Source
const (
	BinaryOperatorADD                binaryOperator = "+"
	BinaryOperatorMinus              binaryOperator = "-"
	BinaryOperatorMultiply           binaryOperator = "*"
	BinaryOperatorExponent           binaryOperator = "*"
	BinaryOperatorDivide             binaryOperator = "/"
	BinaryOperatorModulus            binaryOperator = "%"
	BinaryOperatorAND                binaryOperator = "&"
	BinaryOperatorOR                 binaryOperator = "|"
	BinaryOperatorXOR                binaryOperator = "^"
	BinaryOperatorNOT                binaryOperator = "~"
	BinaryOperatorSHIFTLEFT          binaryOperator = "<<"
	BinaryOperatorSHIFTRIGHT         binaryOperator = ">>"
	BinaryOperatorZEROFILLSHIFTRIGHT binaryOperator = ">>>"
)
View Source
const (
	LogicalOperatorOr                logicalOperator = "||"
	LogicalOperatorAnd               logicalOperator = "&&"
	LogicalOperatorNullishCoelescing logicalOperator = "??"
)

Variables

This section is empty.

Functions

func SetGlobaIndentor

func SetGlobaIndentor(i Indentor)

Types

type ArgumentListElement

type ArgumentListElement interface {
	JSElement
	// contains filtered or unexported methods
}

type ArrayExpression

type ArrayExpression struct {
	Elements []ArrayExpressionElement
	*Node
}

Expressions

func (*ArrayExpression) String

func (a *ArrayExpression) String() (s string)

type ArrayExpressionElement

type ArrayExpressionElement interface {
	JSElement
	// contains filtered or unexported methods
}

type ArrayPattern

type ArrayPattern struct {
	Elements []ArrayPatternElement
	*Node
}

func (*ArrayPattern) String

func (a *ArrayPattern) String() (s string)

type ArrayPatternElement

type ArrayPatternElement interface {
	JSElement
	// contains filtered or unexported methods
}

type ArrowFunctionExpression

type ArrowFunctionExpression struct {
	Params []FunctionParameter
	Body   BlockStatement
	Async  bool
	*Node
}

func (*ArrowFunctionExpression) String

func (a *ArrowFunctionExpression) String() (s string)

type AssignmentExpression

type AssignmentExpression struct {
	Operator assignmentOperator
	Left     Expression
	Right    Expression
	*Node
}

func (*AssignmentExpression) String

func (a *AssignmentExpression) String() string

type AssignmentPattern

type AssignmentPattern struct {
	Left  BindingIdentifierOrPattern
	Right Expression
}

func (*AssignmentPattern) String

func (a *AssignmentPattern) String() string

type AwaitExpression

type AwaitExpression struct {
	Arguement Expression
	*Node
}

func (*AwaitExpression) String

func (a *AwaitExpression) String() string

type BinaryExpression

type BinaryExpression struct {
	Operator binaryOperator
	Left     Expression
	Right    Expression
	*Node
}

func (*BinaryExpression) String

func (b *BinaryExpression) String() string

type BindingIdentifierOrPattern

type BindingIdentifierOrPattern interface {
	JSElement
	// contains filtered or unexported methods
}

type BindingPattern

type BindingPattern interface {
	JSElement
	ExportableDefaultDeclaration
	BindingIdentifierOrPattern
	FunctionParameter
	PropertyValue
	// contains filtered or unexported methods
}

Deconstruction patterns eg. ({one, two}) => ...

type BlockStatement

type BlockStatement struct {
	Items []Statement
	*Node
}

func (*BlockStatement) String

func (b *BlockStatement) String() string

type BreakStatement

type BreakStatement struct {
	Label *Identifier
	*Node
}

Statements

func (*BreakStatement) String

func (b *BreakStatement) String() (s string)

type CallExpression

type CallExpression struct {
	Callee    Expression
	Arguments []ArgumentListElement
	Optional  bool
	*Node
}

func (*CallExpression) String

func (c *CallExpression) String() string

type CatchClause

type CatchClause struct {
	BindingIdentifierOrPattern
	Body BlockStatement
	*Node
}

func (CatchClause) String

func (c CatchClause) String() string

type ChainElement

type ChainElement interface {
	JSElement
	// contains filtered or unexported methods
}

type ChainExpression

type ChainExpression struct {
	Expression ChainElement
	*Node
}

func (*ChainExpression) String

func (c *ChainExpression) String() (s string)

type ClassBody

type ClassBody struct {
	Properties []ClassProperty
	*Node
}

func (*ClassBody) String

func (c *ClassBody) String() string

type ClassDeclaration

type ClassDeclaration struct {
	ID         *Identifier
	SuperClass Expression
	Body       *ClassBody
	*Node
}

Declarations

func (*ClassDeclaration) String

func (c *ClassDeclaration) String() (s string)

type ClassExpression

type ClassExpression struct {
	ID         *Identifier
	SuperClass *Identifier
	Body       *ClassBody
	*Node
}

func (*ClassExpression) String

func (c *ClassExpression) String() (s string)

type ClassProperty

type ClassProperty interface {
	JSElement
	// contains filtered or unexported methods
}

type ComputedMemberExpression

type ComputedMemberExpression struct {
	Object   Expression
	Property Expression
	Optional bool
	*Node
}

func (*ComputedMemberExpression) String

func (c *ComputedMemberExpression) String() string

type ConditionalExpression

type ConditionalExpression struct {
	Test       Expression
	Consequent Expression
	Alternate  Expression
	*Node
}

func (*ConditionalExpression) String

func (c *ConditionalExpression) String() string

type ContinueStatement

type ContinueStatement struct {
	Label *Identifier
	*Node
}

func (*ContinueStatement) String

func (c *ContinueStatement) String() (s string)

type DebuggerStatement

type DebuggerStatement struct {
	*Node
}

func (*DebuggerStatement) String

func (d *DebuggerStatement) String() string

type Declaration

type Declaration interface {
	JSElement
	StatementListItem
	// contains filtered or unexported methods
}

type Directive

type Directive struct {
	Expression
	Directive string
	*Node
}

func (*Directive) String

func (d *Directive) String() string

type DoWhileStatement

type DoWhileStatement struct {
	Body BlockStatement
	Test Expression
	*Node
}

func (*DoWhileStatement) String

func (d *DoWhileStatement) String() string

type EmptyStatement

type EmptyStatement struct {
	*Node
}

func (*EmptyStatement) String

func (e *EmptyStatement) String() string

type ExportAllDeclaration

type ExportAllDeclaration struct {
	Source Literal
	*Node
}

func (*ExportAllDeclaration) String

func (e *ExportAllDeclaration) String() string

type ExportDeclaration

type ExportDeclaration interface {
	Declaration
	// contains filtered or unexported methods
}

type ExportDefaultDeclaration

type ExportDefaultDeclaration struct {
	Declaration ExportableDefaultDeclaration
	*Node
}

func (*ExportDefaultDeclaration) String

func (e *ExportDefaultDeclaration) String() string

type ExportNamedDeclaration

type ExportNamedDeclaration struct {
	Declaration ExportableNamedDeclaration
	Specifiers  []ExportSpecifier
	*Node
}

func (*ExportNamedDeclaration) String

func (e *ExportNamedDeclaration) String() (s string)

type ExportSpecifier

type ExportSpecifier struct {
	Exported *Identifier
	Local    *Identifier
	*Node
}

func (ExportSpecifier) String

func (e ExportSpecifier) String() (s string)

type ExportableDefaultDeclaration

type ExportableDefaultDeclaration interface {
	JSElement
	// contains filtered or unexported methods
}

type ExportableNamedDeclaration

type ExportableNamedDeclaration interface {
	JSElement
	// contains filtered or unexported methods
}

type Expression

type Expression interface {
	JSElement
	ExportableDefaultDeclaration
	ArgumentListElement
	ArrayExpressionElement
	ExpressionOrImport
	// contains filtered or unexported methods
}

type ExpressionOrImport

type ExpressionOrImport interface {
	JSElement
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Expression
	*Node
}

func (*ExpressionStatement) String

func (e *ExpressionStatement) String() string

type ForInStatement

type ForInStatement struct {
	Left  Expression
	Right Expression
	Body  BlockStatement
	Each  bool
	*Node
}

func (*ForInStatement) String

func (f *ForInStatement) String() string

type ForOfStatement

type ForOfStatement struct {
	Await bool
	Left  Expression
	Right Expression
	Body  BlockStatement
	*Node
}

func (*ForOfStatement) String

func (f *ForOfStatement) String() (s string)

type ForStatement

type ForStatement struct {
	Init   Expression
	Test   Expression
	Update Expression
	Body   BlockStatement
	*Node
}

func (*ForStatement) String

func (f *ForStatement) String() string

type FunctionDeclaration

type FunctionDeclaration struct {
	ID     *Identifier
	Params []FunctionParameter
	Body   BlockStatement
	FunctionType
	*Node
}

func (*FunctionDeclaration) String

func (f *FunctionDeclaration) String() (s string)

type FunctionExpression

type FunctionExpression struct {
	ID     *Identifier
	Params []FunctionParameter
	Body   BlockStatement
	FunctionType
	*Node
}

func (*FunctionExpression) String

func (f *FunctionExpression) String() (s string)

type FunctionParameter

type FunctionParameter interface {
	JSElement
	// contains filtered or unexported methods
}

type FunctionType

type FunctionType string
const (
	FunctionTypeNormal    FunctionType = "normal"
	FunctionTypeAsync     FunctionType = "async"
	FunctionTypeGenerator FunctionType = "generator"
)

type Generator

type Generator struct {
	ModuleName string
	Statements []StatementListItem
}

func NewGenerator

func NewGenerator() *Generator

func (*Generator) AddStatement

func (g *Generator) AddStatement(s StatementListItem) *Generator

func (*Generator) AddStatements

func (g *Generator) AddStatements(ss ...StatementListItem) *Generator

func (*Generator) String

func (g *Generator) String() string

type Identifier

type Identifier struct {
	Name string
	*Node
}

func (*Identifier) String

func (i *Identifier) String() string

type IfStatement

type IfStatement struct {
	Test       Expression
	Consequent Statement
	Alternate  Statement
	*Node
}

func (*IfStatement) String

func (f *IfStatement) String() (s string)

type Import

type Import struct {
	*Node
}

type ImportDeclaration

type ImportDeclaration struct {
	Specifiers []ImportDeclarationSpecifier
	Source     string
	*Node
}

func (*ImportDeclaration) String

func (i *ImportDeclaration) String() (s string)

type ImportDeclarationSpecifier

type ImportDeclarationSpecifier interface {
	JSElement
	// contains filtered or unexported methods
}

type ImportDefaultSpecifier

type ImportDefaultSpecifier struct {
	Local *Identifier
	*Node
}

Imports

func (*ImportDefaultSpecifier) String

func (i *ImportDefaultSpecifier) String() string

type ImportNamespaceSpecifier

type ImportNamespaceSpecifier struct {
	Local *Identifier
	*Node
}

func (*ImportNamespaceSpecifier) String

func (i *ImportNamespaceSpecifier) String() string

type ImportSpecifier

type ImportSpecifier struct {
	NamedImports []NamedImport
	*Node
}

func (ImportSpecifier) String

func (i ImportSpecifier) String() (s string)

type Indentor

type Indentor interface {
	Indent(string) string
	IndentArray([]string) []string
}

type JSElement

type JSElement interface {
	String() string
}

type LabeledStatement

type LabeledStatement struct {
	Label Identifier
	Body  Statement
	*Node
}

type Literal

type Literal interface {
	JSElement

	PropertyKey
	ArgumentListElement
	ArrayExpressionElement
	Expression
	ExpressionOrImport
	ExportableDefaultDeclaration
	// contains filtered or unexported methods
}
var (

	// LiteralValues
	LiteralValueUndefined Literal = &literalValueUndefined{}
	LiteralValueNull      Literal = &literalValueNull{}
)

Compiler checks

func NumberLiteral

func NumberLiteral(n interface{}) Literal

type LiteralValueBigFloat

type LiteralValueBigFloat big.Float

func (*LiteralValueBigFloat) String

func (l *LiteralValueBigFloat) String() string

type LiteralValueBool

type LiteralValueBool bool

func BoolLiteral

func BoolLiteral(b bool) *LiteralValueBool

func (*LiteralValueBool) String

func (l *LiteralValueBool) String() string

type LiteralValueNumber

type LiteralValueNumber float64

func (*LiteralValueNumber) String

func (l *LiteralValueNumber) String() string

type LiteralValueString

type LiteralValueString string

func StringLiteral

func StringLiteral(s string) *LiteralValueString

func (*LiteralValueString) String

func (l *LiteralValueString) String() string

type LogicalExpression

type LogicalExpression struct {
	Operator logicalOperator
	Left     Expression
	Right    Expression
	*Node
}

func (*LogicalExpression) String

func (l *LogicalExpression) String() string

type MetaProperty

type MetaProperty struct {
	Meta     Identifier
	Property Identifier
	*Node
}

type MethodDefinition

type MethodDefinition struct {
	Static bool
	Key    PropertyKey
	Value  FunctionExpression
	*Node
}

func (*MethodDefinition) String

func (m *MethodDefinition) String() (s string)

type NamedImport

type NamedImport struct {
	Local    *Identifier
	Imported *Identifier
	*Node
}

func (NamedImport) String

func (n NamedImport) String() (s string)

type NewExpression

type NewExpression struct {
	Callee    Expression
	Arguments []ArgumentListElement
	*Node
}

func (*NewExpression) String

func (n *NewExpression) String() string

type Node

type Node struct {
	Location *SourceLocation
	*Range
}

type ObjectExpression

type ObjectExpression struct {
	Properties []ObjectExpressionProperty
	*Node
}

func (*ObjectExpression) String

func (o *ObjectExpression) String() string

type ObjectExpressionProperty

type ObjectExpressionProperty interface {
	JSElement
	// contains filtered or unexported methods
}

type ObjectPattern

type ObjectPattern struct {
	Properties []ObjectPatternProperty
	*Node
}

func (*ObjectPattern) String

func (o *ObjectPattern) String() (s string)

type ObjectPatternProperty

type ObjectPatternProperty interface {
	JSElement
	// contains filtered or unexported methods
}

type Position

type Position struct {
	Line   int
	Column int
}

type Program

type Program struct {
	Name string
	Body []StatementListItem
	*Range
}

type Property

type Property struct {
	Key       PropertyKey
	Value     Expression
	Kind      string
	Method    bool
	ShortHand bool
	*Node
}

func (*Property) String

func (p *Property) String() (s string)

type PropertyDefinition

type PropertyDefinition struct {
	Static bool
	Key    PropertyKey
	Value  Expression
	*Node
}

func (*PropertyDefinition) String

func (p *PropertyDefinition) String() (s string)

type PropertyKey

type PropertyKey interface {
	JSElement
	// contains filtered or unexported methods
}

type PropertyPattern

type PropertyPattern struct {
	Key       PropertyKey
	Computed  bool
	Value     PropertyValue
	Kind      string
	Method    bool
	ShortHand bool
	*Node
}

func (*PropertyPattern) String

func (p *PropertyPattern) String() (s string)

type PropertyValue

type PropertyValue interface {
	JSElement
	// contains filtered or unexported methods
}

type Range

type Range struct {
	Start int
	End   int
}

type RestElement

type RestElement struct {
	Argument BindingIdentifierOrPattern
	*Node
}

misc

func (*RestElement) String

func (r *RestElement) String() string

type ReturnStatement

type ReturnStatement struct {
	Argument Expression
	*Node
}

func (*ReturnStatement) String

func (r *ReturnStatement) String() (s string)

type SequenceExpression

type SequenceExpression struct {
	Expressions []Expression
	*Node
}

func (*SequenceExpression) String

func (s *SequenceExpression) String() string

type SourceLocation

type SourceLocation struct {
	Start  Position
	End    Position
	Source string
}

type Spaces

type Spaces struct {
	Spaces int
}

func (*Spaces) Indent

func (sp *Spaces) Indent(s string) string

func (*Spaces) IndentArray

func (sp *Spaces) IndentArray(strs []string) []string

type SpreadElement

type SpreadElement struct {
	Argument Expression
	*Node
}

func (*SpreadElement) String

func (s *SpreadElement) String() string

type Statement

type Statement interface {
	JSElement
	// contains filtered or unexported methods
}

type StatementListItem

type StatementListItem interface {
	JSElement
	// contains filtered or unexported methods
}

type StaticMemberExpression

type StaticMemberExpression struct {
	Object   Expression
	Property Expression
	*Node
}

func (*StaticMemberExpression) String

func (s *StaticMemberExpression) String() string

type Super

type Super struct {
	*Node
}

type SwitchCase

type SwitchCase struct {
	Test       Expression
	Consequent BlockStatement
}

func (SwitchCase) String

func (s SwitchCase) String() string

type SwitchStatement

type SwitchStatement struct {
	Discriminant Expression
	Cases        []SwitchCase
	*Node
}

func (*SwitchStatement) String

func (r *SwitchStatement) String() string

type Tabs

type Tabs struct {
	Tabs int
}

func (*Tabs) Indent

func (t *Tabs) Indent(s string) string

func (*Tabs) IndentArray

func (t *Tabs) IndentArray(strs []string) []string

type TaggedTemplateExpression

type TaggedTemplateExpression struct {
	Tag   Expression
	Quasi TemplateLiteral
	*Node
}

func (*TaggedTemplateExpression) String

func (t *TaggedTemplateExpression) String() string

type TemplateElement

type TemplateElement struct {
}

type TemplateLiteral

type TemplateLiteral struct {
	Quasis      []TemplateElement
	Expressions []Expression
	*Node
}

type ThrowStatement

type ThrowStatement struct {
	Argument Expression
	*Node
}

func (*ThrowStatement) String

func (t *ThrowStatement) String() string

type TryStatement

type TryStatement struct {
	Block     BlockStatement
	Handler   CatchClause
	Finalizer *BlockStatement
	*Node
}

func (*TryStatement) String

func (t *TryStatement) String() (s string)

type UnaryExpression

type UnaryExpression struct {
	Operator UnaryOperatorType
	Argument Expression
	*Node
}

func (*UnaryExpression) String

func (u *UnaryExpression) String() string

type UnaryOperatorType

type UnaryOperatorType string
const (
	UnaryOperatorTypePlus             UnaryOperatorType = "+%s"
	UnaryOperatorTypeMinus            UnaryOperatorType = "-%s"
	UnaryOperatorTypeIncrementPrefix  UnaryOperatorType = "++%s"
	UnaryOperatorTypeIncrementPostfix UnaryOperatorType = "%s++"
	UnaryOperatorTypeDecrementPrefix  UnaryOperatorType = "--%s"
	UnaryOperatorTypeDecrementPostfix UnaryOperatorType = "%s--"
)

type UpdateExpression

type UpdateExpression struct {
	Argument Expression
	*Node
}

func (*UpdateExpression) String

func (u *UpdateExpression) String() string

type VariableDeclaration

type VariableDeclaration struct {
	Declarations []VariableDeclarator
	Kind         VariableDeclarationType
	*Node
}

func (*VariableDeclaration) String

func (v *VariableDeclaration) String() (s string)

type VariableDeclarationType

type VariableDeclarationType string
const (
	VariableDeclarationTypeConst VariableDeclarationType = "const"
	VariableDeclarationTypeLet   VariableDeclarationType = "let"
	VariableDeclarationTypeVar   VariableDeclarationType = "var"
)

type VariableDeclarator

type VariableDeclarator struct {
	ID   BindingIdentifierOrPattern
	Init Expression
}

type WhileStatement

type WhileStatement struct {
	Test Expression
	Body Statement
	*Node
}

func (*WhileStatement) String

func (w *WhileStatement) String() string

type WithStatement

type WithStatement struct {
	Object Expression
	Body   Statement
	*Node
}

func (*WithStatement) String

func (w *WithStatement) String() string

type YieldExpression

type YieldExpression struct {
	Argument Expression
	Delegate bool
	*Node
}

func (*YieldExpression) String

func (y *YieldExpression) String() (s string)

Jump to

Keyboard shortcuts

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