Documentation ¶
Index ¶
- Variables
- func InstallPlugins(runtime *goja.Runtime, plugins []Plugin) (err error)
- func LoadCompiler() (*goja.Program, error)
- type CompilerOptions
- type Library
- type Module
- type ModuleList
- type ModuleResolver
- type Plugin
- type Transpiler
- type VirtualMachine
- func (vm *VirtualMachine) CreateNewRuntimeObject() *goja.Object
- func (vm *VirtualMachine) GetModule(name string) (*goja.Object, error)
- func (vm *VirtualMachine) InstallModule(name string, module Module) error
- func (vm *VirtualMachine) InstallModuleListWithPrefix(prefix string, modules ModuleList) error
- func (vm *VirtualMachine) InstallPlugins(plugins []Plugin) error
- func (vm *VirtualMachine) ResolveModule(filename string) (*goja.Object, error)
- func (vm *VirtualMachine) RunScript(filename, src string) (goja.Value, error)
- func (vm *VirtualMachine) SetRuntimeValue(name string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
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 LoadCompiler ¶
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 Module ¶
type Module map[string]interface{}
Module is an alias type that can be installed in the module resolver
type ModuleList ¶
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 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)
type VirtualMachine ¶
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