loader

package
v0.0.1-beta.9 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package loader is goesm's Go frontend. It does no parsing, module resolution or type checking of its own: everything is delegated to the go command (via golang.org/x/tools/go/packages) and to go/types, so goesm accepts exactly the Go that the current toolchain accepts, with the module semantics (go.mod, go.sum, go.work, GOPROXY, ...) the go command implements.

Index

Constants

This section is empty.

Variables

View Source
var BuildTags = []string{"purego", "math_big_pure_go"}

BuildTags select the standard library's portable Go implementations where it has assembly ones: purego (crypto and others) and math_big_pure_go. goesm cannot use assembly, and these build tags are also how gc builds these packages without it.

View Source
var TargetEnv = []string{"GOOS=js", "GOARCH=wasm", "CGO_ENABLED=0"}

Target build constraints. GOOS=js GOARCH=wasm is the existing Go port that matches a JS host most closely: it selects js-specific files in the standard library and gives go/types the 64-bit wasm sizes.

Functions

func VersionHint

func VersionHint(dir string) string

VersionHint explains a frontend/toolchain skew. go/types is linked into the goesm binary, so the newest Go syntax goesm understands is that of the toolchain goesm was built with. goesm does not pin a Go version; running it via `go tool goesm` (a tool directive in go.mod) or `go run` rebuilds it with the toolchain the module selects.

Types

type Diagnostic

type Diagnostic struct {
	Layer string // "go list", "go/parser", "go/types"
	Pos   string // file:line:col as reported by the Go frontend
	Msg   string
}

Diagnostic is a frontend error reported at its original .go position.

func (Diagnostic) String

func (d Diagnostic) String() string

type Error

type Error struct{ Diags []Diagnostic }

Error aggregates frontend diagnostics.

func (*Error) Error

func (e *Error) Error() string

type Program

type Program struct {
	Fset *token.FileSet
	// Roots are the packages named on the command line.
	Roots []*packages.Package
	// All packages in dependency order (dependencies first).
	All []*packages.Package
	// Std is the set of standard library packages (sources in GOROOT).
	Std map[*packages.Package]bool
	// Deps is the set of packages from modules other than those of the
	// roots: third-party dependencies.
	Deps map[*packages.Package]bool
}

Program is a loaded, type-checked package graph.

func Load

func Load(dir string, patterns ...string) (*Program, error)

Load loads the packages matching patterns (ordinary Go package patterns such as ./main or example.com/app/...) relative to dir.

func LoadOverlay

func LoadOverlay(dir string, overlay map[string][]byte, patterns ...string) (*Program, error)

LoadOverlay is Load with file contents that replace or add files on disk, keyed by absolute path. It is the go command's own overlay mechanism (go build -overlay, packages.Config.Overlay): the go command still resolves packages and modules, it only reads these files from memory. Hosts that embed Go in other files (such as gosfc for Vue SFCs) use it to hand goesm a generated file without writing it into the user's source tree.

Jump to

Keyboard shortcuts

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