compiler

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: AGPL-3.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultOpts = map[string]interface{}{

		"plugins": []interface{}{

			[]interface{}{"transform-es2015-modules-commonjs", map[string]interface{}{"loose": false}},
		},
		"ast":           false,
		"sourceMaps":    false,
		"babelrc":       false,
		"compact":       false,
		"retainLines":   true,
		"highlightCode": false,
	}
)

Functions

This section is empty.

Types

type Compiler

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

A Compiler compiles JavaScript source code (ES5.1 or ES6) into a goja.Program

func New

func New(logger logrus.FieldLogger) *Compiler

New returns a new Compiler

func (*Compiler) Compile added in v0.18.0

func (c *Compiler) Compile(src, filename string, isESM bool) (*goja.Program, string, error)

Compile the program in the given CompatibilityMode, wrapping it between pre and post code TODO isESM will be used once goja support ESM modules natively

func (*Compiler) Transform

func (c *Compiler) Transform(src, filename string, inputSrcMap []byte) (code string, srcMap []byte, err error)

Transform the given code into ES5

type Options added in v0.36.0

type Options struct {
	CompatibilityMode lib.CompatibilityMode
	SourceMapLoader   func(string) ([]byte, error)
	Strict            bool
}

Options are options to the compiler

type Pool added in v0.34.0

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

Pool is a pool of compilers so it can be used easier in parallel tests as they have their own babel.

func NewPool added in v0.34.0

func NewPool(logger logrus.FieldLogger, count int) *Pool

NewPool creates a Pool that will be using the provided logger and will preallocate (in parallel) the count of compilers each with their own babel.

func (*Pool) Get added in v0.34.0

func (c *Pool) Get() *Compiler

Get a compiler from the pool.

func (*Pool) Put added in v0.34.0

func (c *Pool) Put(co *Compiler)

Put a compiler back in the pool.

Jump to

Keyboard shortcuts

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