Documentation
¶
Overview ¶
Package native compiles the modules of an app's server build to Go, so pages render without the JavaScript engine (ADR 0011). The modules come from the Vite plugin in packages/tern/src/vite/native.ts, as ESTree.
Index ¶
Constants ¶
const IRVersion = 1
IRVersion is the format of .tern/native/ir.json that this package reads.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler turns the IR into Go.
type IR ¶
type IR struct {
Version int `json:"version"`
Svelte string `json:"svelte"`
Entry string `json:"entry"`
// Bundled holds the modules the bundle has; the rest were tree-shaken.
// Nil means all of them.
Bundled map[string]bool `json:"bundled"`
// Env is import.meta.env in the server build.
Env map[string]any `json:"env"`
// FileURLs maps import.meta's asset URL placeholders to the URLs
// the bundle has.
FileURLs map[string]string `json:"fileUrls"`
Modules []struct {
ID string `json:"id"`
Imports map[string]*string `json:"imports"`
AST *Node `json:"ast"`
// Code is the module's source, for functions' toString.
Code string `json:"code"`
} `json:"modules"`
}
IR is the server build's modules, as the Vite plugin recorded them.
type Node ¶
Node is an ESTree node.
func (*Node) Raw ¶
func (n *Node) Raw(key string) json.RawMessage
Raw is a field's JSON, for literal values.
func (*Node) UnmarshalJSON ¶
UnmarshalJSON keeps a node's fields raw and decodes them as they are used.
type Options ¶
type Options struct {
// Package is the Go package name; the default is native.
Package string
// Prefix starts the names the file declares, so it can share a package:
// with "tern", the realm type is ternRealm and New is ternNew.
Prefix string
// Register, if set, is an assignable expression, such as
// "ternManifest.Native", that an init function sets to New.
Register string
// EmbedSources, if set, is the path the caller writes Result.Sources
// to, which the file embeds; otherwise the sources are in the file.
EmbedSources string
}
Options say how the Go comes out.
type Problem ¶
Problem is something the compiler couldn't compile. The code compiles to a stub that raises js.Unsupported when it runs, so only a request that reaches it falls back to the JavaScript engine.
type Result ¶
type Result struct {
// Source is the Go file, package native.
Source []byte
// Problems lists what couldn't be compiled, in module order.
Problems []Problem
// Modules is how many modules were compiled.
Modules int
// Mismatches lists the intrinsics not used because the function they
// stand for has changed, with its fingerprint now.
Mismatches []string
// Sources is the modules' code, gzipped, for Options.EmbedSources.
Sources []byte
}
Result is a compiled app.