compiler

package
v0.0.0-...-58ba716 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler is the root compiler for a project.

func NewCompiler

func NewCompiler(conf *Config, le *logrus.Entry, opts *packages.Config) (*Compiler, error)

NewCompiler builds a new Compiler opts can be nil

func (*Compiler) CompilePackages

func (c *Compiler) CompilePackages(ctx context.Context, patterns ...string) error

CompilePackages attempts to build packages.

type CompilerContext

type CompilerContext struct {
	// GoPackage is the name of the go package to compile
	GoPackage string
	// ComputedTsPackage is the path to the typescript package for this Go package.
	ComputedTsPackage string
}

CompilerContext is the context for the compiler.

type Config

type Config struct {

	// GoPathRoot is the GOPATH root.
	GoPathRoot string
	// OutputPathRoot is the output path root.
	OutputPathRoot string
	// contains filtered or unexported fields
}

Config is the configuration for the compiler

func (*Config) ComputePackagePath

func (c *Config) ComputePackagePath(pkgPath string) string

ComputePackagePath computes the path to a package in the gopath.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the config.

type FileCompiler

type FileCompiler struct {
	// contains filtered or unexported fields
}

FileCompiler is the root compiler for a file.

func NewFileCompiler

func NewFileCompiler(
	compilerConf *Config,
	pkg *packages.Package,
	ast *ast.File,
	fullPath string,
) (*FileCompiler, error)

NewFileCompiler builds a new FileCompiler

func (*FileCompiler) Compile

func (c *FileCompiler) Compile(ctx context.Context) error

Compile compiles a file.

type GoToTSCompiler

type GoToTSCompiler struct {
	// contains filtered or unexported fields
}

GoToTSCompiler compiles Go code to TypeScript code.

func NewGoToTSCompiler

func NewGoToTSCompiler(tsw *TSCodeWriter) *GoToTSCompiler

NewGoToTSCompiler builds a new GoToTSCompiler

func (*GoToTSCompiler) WriteDeclFunc

func (c *GoToTSCompiler) WriteDeclFunc(decl *ast.FuncDecl)

WriteDeclFunc writes a function declaration

func (*GoToTSCompiler) WriteDecls

func (c *GoToTSCompiler) WriteDecls(decls []ast.Decl)

WriteDecls writes a slice of declarations.

func (*GoToTSCompiler) WriteDoc

func (c *GoToTSCompiler) WriteDoc(doc *ast.CommentGroup)

WriteDoc writes a comment group.

func (*GoToTSCompiler) WriteExpr

func (c *GoToTSCompiler) WriteExpr(a ast.Expr, interpretType bool)

WriteExpr writes an expression to the output.

func (*GoToTSCompiler) WriteExprBasicLiteral

func (c *GoToTSCompiler) WriteExprBasicLiteral(exp *ast.BasicLit, interpretType bool)

WriteExprBasicLiteral writes a basic literal.

func (*GoToTSCompiler) WriteExprCall

func (c *GoToTSCompiler) WriteExprCall(exp *ast.CallExpr)

WriteExprCall writes a call expression.

func (*GoToTSCompiler) WriteExprCompositeLit

func (c *GoToTSCompiler) WriteExprCompositeLit(exp *ast.CompositeLit, interpretType bool)

WriteExprCompositeLit writes a composite literal expression.

func (*GoToTSCompiler) WriteExprFunc

func (c *GoToTSCompiler) WriteExprFunc(exp *ast.FuncType, interpretType bool)

WriteExprFunc writes a FuncType to the output

func (*GoToTSCompiler) WriteExprIdent

func (c *GoToTSCompiler) WriteExprIdent(exp *ast.Ident, interpretType bool)

WriteExprIdent writes an ident expr.

func (*GoToTSCompiler) WriteExprKeyValue

func (c *GoToTSCompiler) WriteExprKeyValue(exp *ast.KeyValueExpr, interpretType bool)

WriteExprKeyValue writes a key value expression to the output.

func (*GoToTSCompiler) WriteExprSelector

func (c *GoToTSCompiler) WriteExprSelector(exp *ast.SelectorExpr, interpretType bool)

WriteExprSelector writes an expression selector.

func (*GoToTSCompiler) WriteExprStar

func (c *GoToTSCompiler) WriteExprStar(exp *ast.StarExpr, interpretType bool)

WriteExprStar writes a star expression.

func (*GoToTSCompiler) WriteExprStructType

func (c *GoToTSCompiler) WriteExprStructType(exp *ast.StructType)

WriteExprStructType writes a structtype expr.

func (*GoToTSCompiler) WriteField

func (c *GoToTSCompiler) WriteField(field *ast.Field, isArguments bool)

WriteField writes a field definition.

func (*GoToTSCompiler) WriteFieldList

func (c *GoToTSCompiler) WriteFieldList(a *ast.FieldList, isArguments bool)

WriteFieldList writes a field list.

func (*GoToTSCompiler) WriteImportSpec

func (c *GoToTSCompiler) WriteImportSpec(a *ast.ImportSpec)

WriteImportSpec writes an import specification to the output.

func (*GoToTSCompiler) WriteSpec

func (c *GoToTSCompiler) WriteSpec(a ast.Spec)

WriteSpec writes a specification to the output.

func (*GoToTSCompiler) WriteStmt

func (c *GoToTSCompiler) WriteStmt(a ast.Stmt)

WriteStmt writes a statement to the output.

func (*GoToTSCompiler) WriteStmtAssign

func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt)

WriteStmtAssign writes an assign statement.

func (*GoToTSCompiler) WriteStmtBlock

func (c *GoToTSCompiler) WriteStmtBlock(exp *ast.BlockStmt)

WriteStmtBlock writes a block statement.

func (*GoToTSCompiler) WriteStmtExpr

func (c *GoToTSCompiler) WriteStmtExpr(exp *ast.ExprStmt)

WriteStmtExpr writes an expr statement.

func (*GoToTSCompiler) WriteStmtIf

func (s *GoToTSCompiler) WriteStmtIf(exp *ast.IfStmt)

WriteStmtIf writes an if statement.

func (*GoToTSCompiler) WriteStmtReturn

func (c *GoToTSCompiler) WriteStmtReturn(exp *ast.ReturnStmt)

WriteStmtReturn writes a return statement.

func (*GoToTSCompiler) WriteTypeSpec

func (c *GoToTSCompiler) WriteTypeSpec(a *ast.TypeSpec)

WriteTypeSpec writes the type specification to the output.

func (*GoToTSCompiler) WriteValueSpec

func (c *GoToTSCompiler) WriteValueSpec(a *ast.ValueSpec)

WriteValueSpec writes the value specification to the output.

type PackageCompiler

type PackageCompiler struct {
	// contains filtered or unexported fields
}

PackageCompiler compiles an entire package.

func NewPackageCompiler

func NewPackageCompiler(
	le *logrus.Entry,
	compilerConf *Config,
	pkg *packages.Package,
) (*PackageCompiler, error)

NewPackageCompiler builds a new PackageCompiler.

func (*PackageCompiler) Compile

func (c *PackageCompiler) Compile(ctx context.Context) error

Compile compiles the package.

func (*PackageCompiler) CompileFile

func (p *PackageCompiler) CompileFile(ctx context.Context, name string, syntax *ast.File) error

CompileFile compiles a file.

type TSCodeWriter

type TSCodeWriter struct {
	// contains filtered or unexported fields
}

TSCodeWriter writes TypeScript code.

func NewTSCodeWriter

func NewTSCodeWriter(w io.Writer) *TSCodeWriter

NewTSCodeWriter builds a new TypeScript code writer.

func (*TSCodeWriter) Indent

func (w *TSCodeWriter) Indent(count int)

Indent changes the indentation level by a delta.

func (*TSCodeWriter) WriteComment

func (w *TSCodeWriter) WriteComment(commentText string)

WriteComment writes a comment.

func (*TSCodeWriter) WriteImport

func (w *TSCodeWriter) WriteImport(symbolName, importPath string)

WriteImport writes a TypeScript import.

func (*TSCodeWriter) WriteLine

func (w *TSCodeWriter) WriteLine(line string)

WriteLine writes a line of code to the output.

func (*TSCodeWriter) WriteLinePreamble

func (w *TSCodeWriter) WriteLinePreamble()

WriteLinePreamble writes the indentation.

func (*TSCodeWriter) WriteLinef

func (w *TSCodeWriter) WriteLinef(line string, args ...interface{})

WriteLinef writes a formatted line of code to the output.

func (*TSCodeWriter) WriteLiterally

func (w *TSCodeWriter) WriteLiterally(literal string)

WriteLiterally writes something to the output without processing

func (*TSCodeWriter) WriteSectionTail

func (w *TSCodeWriter) WriteSectionTail()

WriteSectionTail writes the end of a section.

Jump to

Keyboard shortcuts

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