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 ¶
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.
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 ¶
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 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 ¶
Load loads the packages matching patterns (ordinary Go package patterns such as ./main or example.com/app/...) relative to dir.
func LoadOverlay ¶
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.