typescript

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCompilerOptions = CompilerOptions{

	"target": "ES2015",
	"module": "commonjs",

	"allowJs":            false,
	"checkJs":            true,
	"declaration":        false,
	"declarationMap":     false,
	"sourceMap":          false,
	"removeComments":     true,
	"noEmit":             true,
	"importHelpers":      false,
	"downlevelIteration": false,
	"isolatedModules":    true,

	"strict":                       true,
	"noImplicitAny":                true,
	"strictNullChecks":             true,
	"strictFunctionTypes":          true,
	"strictBindCallApply":          true,
	"strictPropertyInitialization": true,
	"noImplicitThis":               true,
	"alwaysStrict":                 true,

	"noUnusedLocals":                     true,
	"noImplicitReturns":                  true,
	"noFallthroughCasesInSwitch":         true,
	"noUncheckedIndexedAccess":           true,
	"noPropertyAccessFromIndexSignature": true,

	"moduleResolution": "node",
	"esModuleInterop":  true,

	"inlineSourceMap": false,
	"inlineSources":   false,

	"experimentalDecorators": true,
	"emitDecoratorMetadata":  true,
}

DefaultCompilerOptions a set of default compiler options for typescript

Functions

func InstallPlugins

func InstallPlugins(runtime *goja.Runtime, plugins []Plugin) (err error)

func LoadCompiler

func LoadCompiler() (*goja.Program, error)

LoadCompiler loads the embedded version of typescript and compiles it with goja

Types

type CompilerOptions

type CompilerOptions map[string]interface{}

CompilerOptions an object that represents compilerOptions from tsconfig.json

type Library

type Library struct {
	Path   string
	Prefix string
}

Library represents an alias for library paths

type Module

type Module map[string]interface{}

Module is an alias type that can be installed in the module resolver

type ModuleList

type ModuleList map[string]Module

ModuleList a structure used to install many modules into the typescript runtime quickly

type ModuleResolver

type ModuleResolver struct {
	Transpiler      *Transpiler
	CompilerOptions map[string]interface{}
	Libraries       []Library
	// contains filtered or unexported fields
}

ModuleResolver a goja runtime plugin that provides module resolution and automatic typescript transpilation

func DefaultModuleResolver

func DefaultModuleResolver(transpiler *Transpiler) *ModuleResolver

DefaultModuleResolver creates a pointer to a ModuleResolver with the DefaultCompilerOptions

func (*ModuleResolver) Install

func (m *ModuleResolver) Install(runtime *goja.Runtime) error

Install the module resolver into a Runtime instance

func (*ModuleResolver) SearchLibraries

func (m *ModuleResolver) SearchLibraries(modulePath string) string

SearchLibraries resolves path on a given library

type Plugin

type Plugin interface {
	Install(vm *goja.Runtime) error
}

type Transpiler

type Transpiler struct {
	CompilerOptions CompilerOptions
	// contains filtered or unexported fields
}

Transpiler is a wrapper around goja and uses typescript to transpile code

func NewTranspiler

func NewTranspiler() (*Transpiler, error)

func (*Transpiler) Install

func (t *Transpiler) Install(runtime *goja.Runtime) error

func (*Transpiler) Transpile

func (t *Transpiler) Transpile(source io.Reader) (string, error)

Transpile uses the provides source and compiler options to transpile from typescript to javascript

type VirtualMachine

type VirtualMachine struct {
	Runtime *goja.Runtime
	// contains filtered or unexported fields
}

VirtualMachine an opinionated wrapper around the goja Runtime that provides native support for typescript

func MustInitVM

func MustInitVM(libraries []Library) *VirtualMachine

MustInitVM initialize a JS or panic

func NewVirtualMachine

func NewVirtualMachine(libraries []Library) (vm *VirtualMachine, err error)

NewVirtualMachine creates a new typescript virtual machine

func (*VirtualMachine) CreateNewRuntimeObject

func (vm *VirtualMachine) CreateNewRuntimeObject() *goja.Object

CreateNewRuntimeObject creates a new *goja.Object using the VMs Runtime

func (*VirtualMachine) GetModule

func (vm *VirtualMachine) GetModule(name string) (*goja.Object, error)

GetModule ...

func (*VirtualMachine) InstallModule

func (vm *VirtualMachine) InstallModule(name string, module Module) error

InstallModule installs a native module in the resolver allows creating libraries in go that can be imported or required returns an error if a module with the same name already exits in the VM's ModuleResolver cache

func (*VirtualMachine) InstallModuleListWithPrefix

func (vm *VirtualMachine) InstallModuleListWithPrefix(prefix string, modules ModuleList) error

InstallModuleListWithPrefix uses InstallModule to quickly install a large number of modules and expose them in different ways Example:

import * as arksdk from 'arksdk'
import * as filepath from 'arksdk/filepath'

func (*VirtualMachine) InstallPlugins

func (vm *VirtualMachine) InstallPlugins(plugins []Plugin) error

InstallPlugins allows the typescript Runtime to be extended with plugins

func (*VirtualMachine) ResolveModule

func (vm *VirtualMachine) ResolveModule(filename string) (*goja.Object, error)

ResolveModule resolve, transpiles, and caches the given typescript file

func (*VirtualMachine) RunScript

func (vm *VirtualMachine) RunScript(filename, src string) (goja.Value, error)

RunScript executes the given src in the global context. uses the filename for source mapping

func (*VirtualMachine) SetRuntimeValue

func (vm *VirtualMachine) SetRuntimeValue(name string, value interface{}) error

SetRuntimeValue sets a variable by name and value in the VMs Runtime

Directories

Path Synopsis
runtime

Jump to

Keyboard shortcuts

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