Documentation
¶
Index ¶
- func CompileSourceToTypeScript(source string, packageName string) (string, error)
- type CompilationResult
- type CompileError
- type CompileRequest
- type CompileRequestOwner
- type CompileService
- func (s *CompileService) Compile(ctx context.Context, req *CompileRequest) (*CompilationResult, error)
- func (s *CompileService) LoweringOwner() *LoweringOwner
- func (s *CompileService) OverrideRegistryOwner() *OverrideRegistryOwner
- func (s *CompileService) PackageGraphOwner() *PackageGraphOwner
- func (s *CompileService) RequestOwner() *CompileRequestOwner
- func (s *CompileService) RuntimeContractOwner() *RuntimeContractOwner
- func (s *CompileService) SemanticModelOwner() *SemanticModelOwner
- func (s *CompileService) TypeScriptEmitOwner() *TypeScriptEmitOwner
- type Compiler
- type Config
- type DependencyMode
- type Diagnostic
- type DiagnosticSeverity
- type LoweredProgram
- type LoweringOwner
- type OverrideMetadata
- type OverrideRegistryOwner
- func (o *OverrideRegistryOwner) CopyPackages(ctx context.Context, req *CompileRequest, plan *overrideCopyPlan) ([]string, []Diagnostic)
- func (o *OverrideRegistryOwner) CopyPlan(ctx context.Context, req *CompileRequest, graph *PackageGraph) (*overrideCopyPlan, []Diagnostic)
- func (o *OverrideRegistryOwner) IsMethodAsync(pkgPath, method string) (bool, error)
- func (o *OverrideRegistryOwner) Metadata(pkgPath string) (*OverrideMetadata, error)
- type PackageGraph
- type PackageGraphNode
- type PackageGraphOwner
- type RuntimeContractOwner
- func (o *RuntimeContractOwner) BuiltinImport() RuntimeImport
- func (o *RuntimeContractOwner) Helper(helper RuntimeHelper) (RuntimeHelperContract, bool)
- func (o *RuntimeContractOwner) HelperName(helper RuntimeHelper) (string, bool)
- func (o *RuntimeContractOwner) Helpers() []RuntimeHelperContract
- func (o *RuntimeContractOwner) HelpersByCategory(category RuntimeHelperCategory) []RuntimeHelperContract
- func (o *RuntimeContractOwner) QualifiedHelper(helper RuntimeHelper) string
- type RuntimeEmissionMode
- type RuntimeHelper
- type RuntimeHelperCategory
- type RuntimeHelperContract
- type RuntimeImport
- type SemanticModel
- type SemanticModelOwner
- type TypeScriptEmitOwner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CompilationResult ¶ added in v0.0.25
type CompilationResult struct {
// CompiledPackages contains package paths compiled to TypeScript.
CompiledPackages []string
// CopiedPackages contains package paths copied from override packages.
CopiedPackages []string
// OriginalPackages contains the package patterns or package paths requested.
OriginalPackages []string
// Diagnostics contains all diagnostics produced by the compile request.
Diagnostics []Diagnostic
}
CompilationResult describes a compiler run after adapter normalization.
type CompileError ¶ added in v0.1.0
type CompileError struct {
// Diagnostics are the structured compiler diagnostics.
Diagnostics []Diagnostic
}
CompileError wraps structured diagnostics for ordinary Go error paths.
func NewCompileError ¶ added in v0.1.0
func NewCompileError(diagnostics []Diagnostic) *CompileError
NewCompileError creates a compile error from diagnostics.
func (*CompileError) Error ¶ added in v0.1.0
func (e *CompileError) Error() string
Error returns the human-readable diagnostic summary.
type CompileRequest ¶ added in v0.1.0
type CompileRequest struct {
// Patterns are the Go package patterns requested by the caller.
Patterns []string
// Dir is the working directory for package loading.
Dir string
// OutputPath is the root where TypeScript output would be written.
OutputPath string
// BuildFlags are forwarded to the Go package loader.
BuildFlags []string
// DependencyMode controls whether dependencies are included in the graph.
DependencyMode DependencyMode
// RuntimeEmissionMode controls runtime package emission policy.
RuntimeEmissionMode RuntimeEmissionMode
// AllDependencies controls whether the package graph should include deps.
AllDependencies bool
// DisableEmitBuiltin controls whether runtime packages are emitted.
DisableEmitBuiltin bool
}
CompileRequest describes one compiler invocation after adapter normalization.
type CompileRequestOwner ¶ added in v0.1.0
type CompileRequestOwner struct{}
CompileRequestOwner owns adapter input normalization and validation.
func NewCompileRequestOwner ¶ added in v0.1.0
func NewCompileRequestOwner() *CompileRequestOwner
NewCompileRequestOwner creates a compile request owner.
func (*CompileRequestOwner) NewRequest ¶ added in v0.1.0
func (o *CompileRequestOwner) NewRequest(conf Config, patterns []string) *CompileRequest
NewRequest builds a request from public compiler config and package patterns.
func (*CompileRequestOwner) Validate ¶ added in v0.1.0
func (o *CompileRequestOwner) Validate(req *CompileRequest) []Diagnostic
Validate returns request diagnostics that must stop compilation before output.
type CompileService ¶ added in v0.1.0
type CompileService struct {
// contains filtered or unexported fields
}
CompileService owns the v2 compiler pipeline.
func NewCompileService ¶ added in v0.1.0
func NewCompileService() *CompileService
NewCompileService creates a compile service with every pipeline owner.
func (*CompileService) Compile ¶ added in v0.1.0
func (s *CompileService) Compile(ctx context.Context, req *CompileRequest) (*CompilationResult, error)
Compile runs one request through the v2 pipeline.
func (*CompileService) LoweringOwner ¶ added in v0.1.0
func (s *CompileService) LoweringOwner() *LoweringOwner
LoweringOwner returns the lowering owner.
func (*CompileService) OverrideRegistryOwner ¶ added in v0.1.0
func (s *CompileService) OverrideRegistryOwner() *OverrideRegistryOwner
OverrideRegistryOwner returns the override registry owner.
func (*CompileService) PackageGraphOwner ¶ added in v0.1.0
func (s *CompileService) PackageGraphOwner() *PackageGraphOwner
PackageGraphOwner returns the package graph owner.
func (*CompileService) RequestOwner ¶ added in v0.1.0
func (s *CompileService) RequestOwner() *CompileRequestOwner
RequestOwner returns the compile request owner.
func (*CompileService) RuntimeContractOwner ¶ added in v0.1.0
func (s *CompileService) RuntimeContractOwner() *RuntimeContractOwner
RuntimeContractOwner returns the runtime contract owner.
func (*CompileService) SemanticModelOwner ¶ added in v0.1.0
func (s *CompileService) SemanticModelOwner() *SemanticModelOwner
SemanticModelOwner returns the semantic model owner.
func (*CompileService) TypeScriptEmitOwner ¶ added in v0.1.0
func (s *CompileService) TypeScriptEmitOwner() *TypeScriptEmitOwner
TypeScriptEmitOwner returns the TypeScript emit owner.
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler is the public Go adapter for the v2 compile service.
func NewCompiler ¶
NewCompiler builds a compiler adapter over the v2 compile service.
func (*Compiler) CompilePackages ¶
func (c *Compiler) CompilePackages(ctx context.Context, patterns ...string) (*CompilationResult, error)
CompilePackages compiles Go package patterns through the v2 pipeline.
type Config ¶
type Config struct {
// Dir is the working directory for the compiler.
Dir string
// OutputPath is the output path root.
OutputPath string
// BuildFlags are the Go build flags to use during package loading.
BuildFlags []string
// AllDependencies controls whether dependencies are included in the graph.
AllDependencies bool
// DisableEmitBuiltin controls whether runtime packages are emitted.
DisableEmitBuiltin bool
// contains filtered or unexported fields
}
Config is the public compiler configuration.
type DependencyMode ¶ added in v0.1.0
type DependencyMode string
DependencyMode describes how much of the loaded package graph to keep.
const ( // DependencyModeRequested keeps only requested package nodes. DependencyModeRequested DependencyMode = "requested" // DependencyModeAll keeps reachable dependency package nodes. DependencyModeAll DependencyMode = "all" )
type Diagnostic ¶ added in v0.1.0
type Diagnostic struct {
// Severity is the diagnostic severity.
Severity DiagnosticSeverity
// Code is a stable machine-readable diagnostic code.
Code string
// Message is the short human-readable diagnostic.
Message string
// Detail carries optional longer guidance.
Detail string
}
Diagnostic is a structured compiler message surfaced by every adapter.
type DiagnosticSeverity ¶ added in v0.1.0
type DiagnosticSeverity string
DiagnosticSeverity is the severity of a compiler diagnostic.
const ( // DiagnosticSeverityError marks a diagnostic that stops compilation. DiagnosticSeverityError DiagnosticSeverity = "error" // DiagnosticSeverityWarning marks a diagnostic that does not stop compilation. DiagnosticSeverityWarning DiagnosticSeverity = "warning" )
type LoweredProgram ¶ added in v0.1.0
type LoweredProgram struct {
// contains filtered or unexported fields
}
LoweredProgram is the compiler-owned IR consumed by TypeScript emission.
type LoweringOwner ¶ added in v0.1.0
type LoweringOwner struct {
// contains filtered or unexported fields
}
LoweringOwner owns conversion from the semantic model to compiler IR.
func NewLoweringOwner ¶ added in v0.1.0
func NewLoweringOwner(runtimeOwner *RuntimeContractOwner, overrideOwner *OverrideRegistryOwner) *LoweringOwner
NewLoweringOwner creates the lowering owner.
func (*LoweringOwner) Build ¶ added in v0.1.0
func (o *LoweringOwner) Build(ctx context.Context, model *SemanticModel) (*LoweredProgram, []Diagnostic)
Build converts the semantic model into the compiler IR.
type OverrideMetadata ¶ added in v0.1.0
type OverrideMetadata struct {
// Dependencies are override package dependencies.
Dependencies []string
// AsyncMethods maps Type.Method keys to async status.
AsyncMethods map[string]bool
}
OverrideMetadata describes compiler-visible facts from a package override.
type OverrideRegistryOwner ¶ added in v0.1.0
type OverrideRegistryOwner struct {
// contains filtered or unexported fields
}
OverrideRegistryOwner owns GoScript override package metadata and copy plans.
func NewOverrideRegistryOwner ¶ added in v0.1.0
func NewOverrideRegistryOwner() *OverrideRegistryOwner
NewOverrideRegistryOwner creates the override registry owner.
func (*OverrideRegistryOwner) CopyPackages ¶ added in v0.1.0
func (o *OverrideRegistryOwner) CopyPackages( ctx context.Context, req *CompileRequest, plan *overrideCopyPlan, ) ([]string, []Diagnostic)
CopyPackages writes override packages from a copy plan to the request output tree.
func (*OverrideRegistryOwner) CopyPlan ¶ added in v0.1.0
func (o *OverrideRegistryOwner) CopyPlan( ctx context.Context, req *CompileRequest, graph *PackageGraph, ) (*overrideCopyPlan, []Diagnostic)
CopyPlan builds the ordered override package copy plan for a request.
func (*OverrideRegistryOwner) IsMethodAsync ¶ added in v0.1.0
func (o *OverrideRegistryOwner) IsMethodAsync(pkgPath, method string) (bool, error)
IsMethodAsync returns true when override metadata marks a method async.
func (*OverrideRegistryOwner) Metadata ¶ added in v0.1.0
func (o *OverrideRegistryOwner) Metadata(pkgPath string) (*OverrideMetadata, error)
Metadata returns compiler-visible override metadata for a package path.
type PackageGraph ¶ added in v0.1.0
type PackageGraph struct {
// RequestedPatterns are the package patterns from the compile request.
RequestedPatterns []string
// RequestedPackagePaths are the loaded package paths for requested patterns.
RequestedPackagePaths []string
// Nodes are the deterministic package graph nodes.
Nodes []*PackageGraphNode
// NodesByPackagePath maps package path to graph node.
NodesByPackagePath map[string]*PackageGraphNode
// contains filtered or unexported fields
}
PackageGraph is the immutable package graph produced for a compile request.
type PackageGraphNode ¶ added in v0.1.0
type PackageGraphNode struct {
// ID is the go/packages package identity.
ID string
// PkgPath is the stable Go package path.
PkgPath string
// Name is the Go package name.
Name string
// ModulePath is the owning module path when known.
ModulePath string
// ModuleDir is the owning module directory when known.
ModuleDir string
// GoFiles are the package source files.
GoFiles []string
// CompiledGoFiles are files selected by build constraints.
CompiledGoFiles []string
// Imports are imported package paths.
Imports []string
// Requested marks packages matched by request patterns.
Requested bool
// OverrideCandidate marks packages with a matching GoScript override package.
OverrideCandidate bool
}
PackageGraphNode is one package in the loaded graph.
type PackageGraphOwner ¶ added in v0.1.0
type PackageGraphOwner struct{}
PackageGraphOwner owns Go package loading and graph identity.
func NewPackageGraphOwner ¶ added in v0.1.0
func NewPackageGraphOwner() *PackageGraphOwner
NewPackageGraphOwner creates the package graph owner.
func (*PackageGraphOwner) Load ¶ added in v0.1.0
func (o *PackageGraphOwner) Load(ctx context.Context, req *CompileRequest) (*PackageGraph, []Diagnostic)
Load builds the package graph for a validated request.
type RuntimeContractOwner ¶ added in v0.1.0
type RuntimeContractOwner struct {
// contains filtered or unexported fields
}
RuntimeContractOwner owns generated-code helper names and runtime capabilities.
func NewRuntimeContractOwner ¶ added in v0.1.0
func NewRuntimeContractOwner() *RuntimeContractOwner
NewRuntimeContractOwner creates the runtime contract owner.
func (*RuntimeContractOwner) BuiltinImport ¶ added in v0.1.0
func (o *RuntimeContractOwner) BuiltinImport() RuntimeImport
BuiltinImport returns the runtime import used by generated package modules.
func (*RuntimeContractOwner) Helper ¶ added in v0.1.0
func (o *RuntimeContractOwner) Helper(helper RuntimeHelper) (RuntimeHelperContract, bool)
Helper returns one runtime helper contract.
func (*RuntimeContractOwner) HelperName ¶ added in v0.1.0
func (o *RuntimeContractOwner) HelperName(helper RuntimeHelper) (string, bool)
HelperName returns the exported runtime symbol for a helper.
func (*RuntimeContractOwner) Helpers ¶ added in v0.1.0
func (o *RuntimeContractOwner) Helpers() []RuntimeHelperContract
Helpers returns every compiler-visible runtime helper contract.
func (*RuntimeContractOwner) HelpersByCategory ¶ added in v0.1.0
func (o *RuntimeContractOwner) HelpersByCategory(category RuntimeHelperCategory) []RuntimeHelperContract
HelpersByCategory returns helper contracts in a category.
func (*RuntimeContractOwner) QualifiedHelper ¶ added in v0.1.0
func (o *RuntimeContractOwner) QualifiedHelper(helper RuntimeHelper) string
QualifiedHelper returns a generated-code reference to a runtime helper.
type RuntimeEmissionMode ¶ added in v0.1.0
type RuntimeEmissionMode string
RuntimeEmissionMode describes how runtime packages should be handled.
const ( // RuntimeEmissionModeEmit emits required runtime packages with output. RuntimeEmissionModeEmit RuntimeEmissionMode = "emit" // RuntimeEmissionModeReference references runtime packages without emitting them. RuntimeEmissionModeReference RuntimeEmissionMode = "reference" )
type RuntimeHelper ¶ added in v0.1.0
type RuntimeHelper string
RuntimeHelper identifies one compiler-visible helper exported by @goscript/builtin.
const ( RuntimeHelperPrintln RuntimeHelper = "builtin.println" RuntimeHelperPrint RuntimeHelper = "builtin.print" RuntimeHelperInt RuntimeHelper = "builtin.int" RuntimeHelperByte RuntimeHelper = "builtin.byte" RuntimeHelperLen RuntimeHelper = "builtin.len" RuntimeHelperCap RuntimeHelper = "builtin.cap" RuntimeHelperClear RuntimeHelper = "builtin.clear" RuntimeHelperPanic RuntimeHelper = "builtin.panic" RuntimeHelperRecover RuntimeHelper = "builtin.recover" RuntimeHelperMin RuntimeHelper = "builtin.min" RuntimeHelperMax RuntimeHelper = "builtin.max" RuntimeHelperAssignStruct RuntimeHelper = "value.assignStruct" RuntimeHelperMarkAsStructValue RuntimeHelper = "value.markAsStructValue" RuntimeHelperPointerValue RuntimeHelper = "value.pointerValue" RuntimeHelperVarRef RuntimeHelper = "varref.varRef" RuntimeHelperUnref RuntimeHelper = "varref.unref" RuntimeHelperIsVarRef RuntimeHelper = "varref.isVarRef" RuntimeHelperMakeSlice RuntimeHelper = "slice.makeSlice" RuntimeHelperGoSlice RuntimeHelper = "slice.goSlice" RuntimeHelperArrayToSlice RuntimeHelper = "slice.arrayToSlice" RuntimeHelperAppend RuntimeHelper = "slice.append" RuntimeHelperCopy RuntimeHelper = "slice.copy" RuntimeHelperAsArray RuntimeHelper = "slice.asArray" RuntimeHelperStringToRunes RuntimeHelper = "slice.stringToRunes" RuntimeHelperStringToRune RuntimeHelper = "slice.stringToRune" RuntimeHelperRunesToString RuntimeHelper = "slice.runesToString" RuntimeHelperStringToBytes RuntimeHelper = "slice.stringToBytes" RuntimeHelperBytesToString RuntimeHelper = "slice.bytesToString" RuntimeHelperGenericBytesOrStringToString RuntimeHelper = "slice.genericBytesOrStringToString" RuntimeHelperIndexStringOrBytes RuntimeHelper = "slice.indexStringOrBytes" RuntimeHelperSliceStringOrBytes RuntimeHelper = "slice.sliceStringOrBytes" RuntimeHelperMakeMap RuntimeHelper = "map.makeMap" RuntimeHelperMapGet RuntimeHelper = "map.mapGet" RuntimeHelperMapSet RuntimeHelper = "map.mapSet" RuntimeHelperMapHas RuntimeHelper = "map.mapHas" RuntimeHelperDeleteMapEntry RuntimeHelper = "map.deleteMapEntry" RuntimeHelperNewError RuntimeHelper = "error.newError" RuntimeHelperToGoError RuntimeHelper = "error.toGoError" RuntimeHelperWrapPrimitiveError RuntimeHelper = "error.wrapPrimitiveError" RuntimeHelperTypeKind RuntimeHelper = "type.TypeKind" RuntimeHelperRegisterStructType RuntimeHelper = "type.registerStructType" RuntimeHelperRegisterInterfaceType RuntimeHelper = "type.registerInterfaceType" RuntimeHelperGetTypeByName RuntimeHelper = "type.getTypeByName" RuntimeHelperTypeAssert RuntimeHelper = "type.typeAssert" RuntimeHelperTypeAssertTuple RuntimeHelper = "type.typeAssertTuple" RuntimeHelperMustTypeAssert RuntimeHelper = "type.mustTypeAssert" RuntimeHelperIs RuntimeHelper = "type.is" RuntimeHelperTypeSwitch RuntimeHelper = "type.typeSwitch" RuntimeHelperTypedNil RuntimeHelper = "type.typedNil" RuntimeHelperInterfaceValue RuntimeHelper = "type.interfaceValue" RuntimeHelperFunctionValue RuntimeHelper = "type.functionValue" RuntimeHelperNamedFunction RuntimeHelper = "type.namedFunction" RuntimeHelperGenericZero RuntimeHelper = "type.genericZero" RuntimeHelperCallGenericMethod RuntimeHelper = "type.callGenericMethod" RuntimeHelperMakeChannel RuntimeHelper = "channel.makeChannel" RuntimeHelperMakeChannelRef RuntimeHelper = "channel.makeChannelRef" RuntimeHelperChanSend RuntimeHelper = "channel.chanSend" RuntimeHelperChanRecv RuntimeHelper = "channel.chanRecv" RuntimeHelperChanRecvWithOk RuntimeHelper = "channel.chanRecvWithOk" RuntimeHelperSelectStatement RuntimeHelper = "channel.selectStatement" RuntimeHelperDisposableStack RuntimeHelper = "defer.DisposableStack" RuntimeHelperAsyncDisposableStack RuntimeHelper = "defer.AsyncDisposableStack" RuntimeHelperGetHostRuntime RuntimeHelper = "host.getHostRuntime" RuntimeHelperWriteHostStdoutText RuntimeHelper = "host.writeHostStdoutText" RuntimeHelperWriteHostStderrText RuntimeHelper = "host.writeHostStderrText" RuntimeHelperIsMainScript RuntimeHelper = "host.isMainScript" )
type RuntimeHelperCategory ¶ added in v0.1.0
type RuntimeHelperCategory string
RuntimeHelperCategory names a runtime helper family owned by the contract.
const ( RuntimeHelperCategoryBuiltin RuntimeHelperCategory = "builtin" RuntimeHelperCategoryValue RuntimeHelperCategory = "value" RuntimeHelperCategoryVarRef RuntimeHelperCategory = "varref" RuntimeHelperCategorySlice RuntimeHelperCategory = "slice" RuntimeHelperCategoryMap RuntimeHelperCategory = "map" RuntimeHelperCategoryError RuntimeHelperCategory = "error" RuntimeHelperCategoryType RuntimeHelperCategory = "type" RuntimeHelperCategoryChannel RuntimeHelperCategory = "channel" RuntimeHelperCategoryDefer RuntimeHelperCategory = "defer" RuntimeHelperCategoryHost RuntimeHelperCategory = "host" )
type RuntimeHelperContract ¶ added in v0.1.0
type RuntimeHelperContract struct {
Helper RuntimeHelper
Export string
Category RuntimeHelperCategory
}
RuntimeHelperContract describes one helper exported by the runtime package.
type RuntimeImport ¶ added in v0.1.0
RuntimeImport is a generated TypeScript import owned by the runtime contract.
type SemanticModel ¶ added in v0.1.0
type SemanticModel struct {
// contains filtered or unexported fields
}
SemanticModel is the immutable compiler semantic surface consumed by lowering.
type SemanticModelOwner ¶ added in v0.1.0
type SemanticModelOwner struct {
// contains filtered or unexported fields
}
SemanticModelOwner owns immutable Go semantic facts used by lowering.
func NewSemanticModelOwner ¶ added in v0.1.0
func NewSemanticModelOwner(overrideOwners ...*OverrideRegistryOwner) *SemanticModelOwner
NewSemanticModelOwner creates the semantic model owner.
func (*SemanticModelOwner) Build ¶ added in v0.1.0
func (o *SemanticModelOwner) Build(ctx context.Context, graph *PackageGraph) (*SemanticModel, []Diagnostic)
Build constructs semantic facts for a package graph.
type TypeScriptEmitOwner ¶ added in v0.1.0
type TypeScriptEmitOwner struct {
// contains filtered or unexported fields
}
TypeScriptEmitOwner owns deterministic TypeScript file emission.
func NewTypeScriptEmitOwner ¶ added in v0.1.0
func NewTypeScriptEmitOwner(runtimeOwners ...*RuntimeContractOwner) *TypeScriptEmitOwner
NewTypeScriptEmitOwner creates the TypeScript emit owner.
func (*TypeScriptEmitOwner) Emit ¶ added in v0.1.0
func (o *TypeScriptEmitOwner) Emit( ctx context.Context, req *CompileRequest, program *LoweredProgram, ) ([]string, []Diagnostic)
Emit writes a lowered program to the configured TypeScript output tree.