compiler

package
v0.55.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 12 Imported by: 4

Documentation

Overview

Package compiler implements additional functionality for k6 to compile js code. more specifically wrapping code in CommonJS wrapper or transforming it through esbuild for typescript support. TODO this package name makes little sense now that it only parses and tranforms javascript. Although people do call such transformation - compilation, so maybe it is still fine

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripTypes added in v0.55.0

func StripTypes(src, filename string) (code string, srcMap []byte, err error)

StripTypes transpiles the input source string and strip types from it. this is done using esbuild

Types

type Compiler

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

A Compiler compiles JavaScript or TypeScript source code into a sobek.Program

func New

func New(logger logrus.FieldLogger) *Compiler

New returns a new Compiler

func (*Compiler) Parse added in v0.53.0

func (c *Compiler) Parse(
	src, filename string, commonJSWrap bool, esm bool,
) (prg *ast.Program, finalCode string, err error)

Parse parses the provided source. It wraps as the same as CommonJS support. The returned program can be compiled directly by Sobek. Additionally, it returns the end code that has been parsed including any required transformations.

func (*Compiler) WithUsage added in v0.54.0

func (c *Compiler) WithUsage(u *usage.Usage)

WithUsage allows the compiler to be given usage.Usage to use

type Options added in v0.36.0

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

Options are options to the compiler

Jump to

Keyboard shortcuts

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