Documentation
¶
Overview ¶
Package compiler parses .gx files into an AST. The AST is the input of the formatter, the type checker and the code generator.
Index ¶
- Constants
- Variables
- func ClassesPath(root string) string
- func Dead(root string) (*DeadReport, []Diagnostic)
- func Describe(root string) (*AppModel, []Diagnostic)
- func DirectiveBehavior(module string) ([]byte, bool)
- func ElementModules(root string) []string
- func Failed(diags []Diagnostic) bool
- func FileSignature(path string) (string, bool)
- func Format(f *File) []byte
- func ImportPath(raw string) string
- func ImportQualifier(raw string) string
- func PackagePath(dir string) string
- func ParseFile(file string, src []byte) (*File, []Diagnostic)
- func ParseFragment(src []byte) (*File, []Diagnostic)
- func Quoted(s string) string
- func Routes(root string) ([]RouteReport, []Diagnostic)
- func SetDirectives(directives []PluginDirective)
- func SetPluginAdapters(list []PluginAdapter)
- func WidgetManifest(widgets []WidgetBuild) ([]byte, error)
- func Widgets(root string) ([]WidgetBuild, []Diagnostic)
- type ActionModel
- type AppModel
- type Attr
- type AttrKind
- type Case
- type CheckOptions
- type CollectionRef
- type Comment
- type Component
- type ComponentModel
- type ComponentRef
- type ContentComponent
- type Control
- type DeadComponent
- type DeadReport
- type DeadRoute
- type Diagnostic
- func APIFiles(root string) (map[string][]byte, []Diagnostic)
- func Check(root string) []Diagnostic
- func CheckApp(root string, opt CheckOptions) []Diagnostic
- func CheckWith(root string, opt CheckOptions) []Diagnostic
- func FormatSource(file string, src []byte) ([]byte, []Diagnostic)
- func Generate(root string) (map[string][]byte, []Diagnostic)
- func Stale(root string) []Diagnostic
- type DirectiveAttr
- type DirectiveUse
- type Element
- type ElementAttr
- type ElementDef
- type ElementModel
- type ElementSet
- type Expr
- type Field
- type FieldModel
- type File
- type FormFieldModel
- type FormModel
- type FragmentModel
- type HTMLComment
- type IconSetModel
- type Import
- type Info
- type Island
- type IslandModel
- type IslandRef
- type Let
- type Model
- type Module
- type Node
- type Package
- type ParamModel
- type PluginAdapter
- type PluginDirective
- type Pos
- type Prop
- type PropModel
- type RegistryModel
- type RouteModel
- type RouteRef
- type RouteReport
- type Session
- func (s *Session) ClearOverlay(path string)
- func (s *Session) Content(root string) []Diagnostic
- func (s *Session) Diagnostics() []Diagnostic
- func (s *Session) Generate(root string) (map[string][]byte, []Diagnostic)
- func (s *Session) Model(root string) (*Model, []Diagnostic)
- func (s *Session) SetOverlay(path string, src []byte)
- type SignalModel
- type Symbol
- type Text
- type TransitionModel
- type WidgetAttribute
- type WidgetBuild
- type WidgetEvent
- type WidgetField
Constants ¶
const ( CodeParse = "GX1000" CodeFileName = "GX1001" CodeStale = "GX1002" CodeRouteField = "GX3000" CodePathVar = "GX3001" CodePathField = "GX3002" CodeUnmounted = "GX3003" CodeDuplicate = "GX3004" CodeRoutePkg = "GX3005" CodeRouteMethod = "GX3006" CodeRequiredProp = "GX2001" CodeUnknownComponent = "GX2002" CodeUnknownAttr = "GX2003" CodeStaticStringProp = "GX2004" CodeType = "GX2000" CodeSpread = "GX2005" CodeDuplicateSlot = "GX2006" CodeEventAttr = "GX2007" CodeFragment = "GX2008" CodeLoopKey = "GX2009" CodeSignal = "GX2010" CodeURLAttr = "GX2011" CodeUnrenderable = "GX2013" CodeImgAlt = "GX2016" CodeControlLabel = "GX2017" CodeNestedInteractive = "GX2018" CodeDuplicateID = "GX2019" CodeBadParent = "GX2020" CodeHeadingOrder = "GX2021" CodeTrustedHTML = "GX7001" CodeSecret = "GX7002" CodeEnum = "GX5001" CodeTransition = "GX5002" CodeRuntimeClass = "GX5003" CodeContentFrontmatter = "GX8001" CodeContentComponent = "GX8002" CodeContentLink = "GX8003" CodeCodeFile = "GX8004" CodeBudget = "GX9001" CodeActionMissing = "GX4001" CodeActionTwice = "GX4002" CodeActionMissingSignal = "GX4003" CodeSignalTypeMismatch = "GX4004" CodeClientCall = "GX4005" CodeAdapterSignals = "GX4006" CodeClientType = "GX4007" CodeInstanceKey = "GX2012" CodeSignalDefault = "GX2014" CodeSignalRoot = "GX2015" CodeEventMod = "GX4010" // CodeTool is a tool with no description, or with an input field that // a JSON value cannot fill (REQ-AI-06, REQ-AI-09). CodeTool = "GX4011" CodeUpdateNoFragment = "GX4012" CodeOptimistic = "GX4013" CodeActionMethod = "GX4009" CodeSignalRules = "GX4008" CodeIslandProps = "GX6001" CodeIslandType = "GX6002" CodeIslandLoad = "GX6004" // CodeIslandTypeScript is one error of the TypeScript compiler in an // island file (REQ-ISL-08). CodeIslandTypeScript = "GX6005" // CodeWidgetTag is a widget with no tag, with a tag that is not a // custom element name, or with the tag of a different widget // (REQ-ISL-10). CodeWidgetTag = "GX6003" // CodeWidgetAttr is a field of a widget input that an attribute // cannot hold (REQ-ISL-15). CodeWidgetAttr = "GX6006" // CodeWidgetHead is gx.Head in the view of a widget, or in a // component that the view uses (REQ-ISL-20). CodeWidgetHead = "GX6007" // CodeWidgetOrigins is a widget, or an action that its component // invokes, in a group with no gx.AllowOrigins (REQ-ISL-22). CodeWidgetOrigins = "GX6008" // CodeCredentialOrigin is a wildcard origin in gx.AllowCredentials // (REQ-ISL-22, SI-14). CodeCredentialOrigin = "GX6009" // CodeEmail is a construct that an email cannot hold (REQ-REG-17). CodeEmail = "GX6010" )
Diagnostic codes. Every code is stable and has a docs page (REQ-AUT-19).
const ( ElementString = "string" ElementBool = "bool" ElementNumber = "number" // ElementEnum is a string with a fixed set of values. ElementEnum = "enum" )
The kinds of an element attribute.
const APIDir = "api"
APIDir is the directory of the files that gx api writes, under the module root.
const ElementsFile = "gx-elements.json"
ElementsFile is the file that describes the imported web components of a package (REQ-ISL-09). `gx wc pin` writes it from the custom elements manifest of an npm package.
Variables ¶
var Catalog = []Info{ {CodeParse, "parse error"}, {CodeFileName, "component file name is not an exported identifier"}, {CodeStale, "generated code is missing or stale"}, {CodeType, "type error in an expression"}, {CodeRequiredProp, "missing required prop"}, {CodeUnknownComponent, "unknown component"}, {CodeUnknownAttr, "unknown attribute or slot"}, {CodeStaticStringProp, "static value for a typed prop"}, {CodeSpread, "attribute spread on a component"}, {CodeDuplicateSlot, "duplicate slot"}, {CodeEventAttr, "dynamic event attribute"}, {CodeFragment, "fragment free variable"}, {CodeLoopKey, "loop needs a key"}, {CodeSignal, "signal in a server expression"}, {CodeInstanceKey, "signal instance needs a key"}, {CodeSignalDefault, "signal needs an initial value"}, {CodeSignalRoot, "component with signals has no top-level HTML element"}, {CodeImgAlt, "img has no alt attribute"}, {CodeControlLabel, "form control has no label"}, {CodeNestedInteractive, "interactive element inside a link or a button"}, {CodeDuplicateID, "one id on two elements of a component"}, {CodeBadParent, "element in a parent where a browser moves or drops it"}, {CodeHeadingOrder, "heading skips a level"}, {CodeURLAttr, "dynamic URL attribute"}, {CodeUnrenderable, "value cannot render as text"}, {CodeRouteField, "route field type cannot bind"}, {CodePathVar, "pattern variable has no field"}, {CodePathField, "path field has no pattern variable"}, {CodeUnmounted, "route value is not held by any gx.Collect"}, {CodeDuplicate, "duplicate route pattern"}, {CodeRoutePkg, "route package contents"}, {CodeRouteMethod, "route field has the name of a generated method"}, {CodeActionMissing, "no action is registered for a route type"}, {CodeActionTwice, "more than one action is registered for a route type"}, {CodeActionMissingSignal, "no signal is declared for a signal-bound field"}, {CodeSignalTypeMismatch, "signal type does not match the action field"}, {CodeClientCall, "call is not allowed in a client expression"}, {CodeAdapterSignals, "signal or client expression under an adapter with no signals"}, {CodeClientType, "value or operator is not allowed in a client expression"}, {CodeSignalRules, "signal-bound fields need rules or gx.Unchecked"}, {CodeActionMethod, "action method cannot be invoked from the client"}, {CodeEventMod, "unknown event modifier or special event"}, {CodeTool, "tool has no description or an input with no JSON form"}, {CodeUpdateNoFragment, "c.Update takes a component with no fragment"}, {CodeOptimistic, "optimistic directive has no action or writes no signal"}, {CodeSharedSignal, "shared signal in a component with no gx.Room prop"}, {CodeEnum, "gx.Enum misses a constant of its type"}, {CodeTransition, "duplicate view-transition-name in one template"}, {CodeRuntimeClass, "class string is built at runtime"}, {CodeIslandProps, "island has no props struct"}, {CodeIslandType, "island prop type has no TypeScript mapping"}, {CodeWidgetTag, "widget tag is missing, not valid or used two times"}, {CodeIslandLoad, "unknown island load strategy"}, {CodeIslandTypeScript, "TypeScript error in an island"}, {CodeWidgetAttr, "widget input field cannot be an attribute"}, {CodeWidgetHead, "gx.Head in a widget"}, {CodeWidgetOrigins, "widget route is in a group with no origins"}, {CodeCredentialOrigin, "origin with cookies is not exact"}, {CodeEmail, "construct that an email cannot hold"}, {CodeTrustedHTML, "conversion to gx.SafeHTML needs //gx:trusted"}, {CodeSecret, "gx.Secret cannot cross to the client"}, {CodeContentFrontmatter, "frontmatter is malformed or unknown"}, {CodeContentComponent, "component is not declared in this collection"}, {CodeContentLink, "content link or anchor is broken"}, {CodeCodeFile, "code file or line range is missing"}, {CodeBudget, "page route is over its budget"}, }
Catalog lists every diagnostic code (REQ-AUT-19). Keep it in step with the code constants above; the catalog test fails when it does not.
var DescribeSchema []byte
DescribeSchema is the JSON Schema of AppModel. `gx describe --schema` prints it.
Functions ¶
func ClassesPath ¶ added in v0.2.0
ClassesPath returns the path of the generated class list of the app at root. The stylesheet build reads it.
func Dead ¶ added in v0.4.0
func Dead(root string) (*DeadReport, []Diagnostic)
Dead returns the dead-code report of the module under root.
func Describe ¶
func Describe(root string) (*AppModel, []Diagnostic)
Describe returns the app model of the module under root (REQ-AI-01).
func DirectiveBehavior ¶ added in v0.3.0
DirectiveBehavior returns the ES module of a directive behaviour by its module name. The island bundle holds it as one entry.
func ElementModules ¶ added in v0.2.0
ElementModules returns the modules of the imported elements that the .gx files under root use, in order (REQ-ISL-09). The island bundler makes one entry file for each.
func Failed ¶ added in v0.4.0
func Failed(diags []Diagnostic) bool
Failed reports whether a list of diagnostics fails a check: it holds one that is not a hint.
func FileSignature ¶ added in v0.2.0
FileSignature returns the part of a .gx file that other code depends on: the package, the imports, the props, the signals and the fragment parameters. A change that keeps it is a change of markup only, which the dev server can swap into the running app (REQ-DEV-02).
func ImportPath ¶
ImportPath returns the path of an import spec as written, without the alias and quotes (REQ-DEV-08).
func ImportQualifier ¶
ImportQualifier returns the name an import spec is used by. An import without an alias uses the last path segment.
func PackagePath ¶ added in v0.2.0
PackagePath returns the import path of the Go package in dir, or "".
func ParseFile ¶
func ParseFile(file string, src []byte) (*File, []Diagnostic)
ParseFile parses a .gx file. file may be empty for input with no file name, such as stdin; the component name check is then skipped.
func ParseFragment ¶
func ParseFragment(src []byte) (*File, []Diagnostic)
ParseFragment parses markup with no package clause, imports, props or signals. It is used by the HTML corpus tests.
func Routes ¶
func Routes(root string) ([]RouteReport, []Diagnostic)
Routes reports every route of the module under root.
func SetDirectives ¶ added in v0.3.0
func SetDirectives(directives []PluginDirective)
SetDirectives gives the compiler the directives of the plugins of the project. It replaces the directives of an earlier call.
func SetPluginAdapters ¶ added in v0.3.0
func SetPluginAdapters(list []PluginAdapter)
SetPluginAdapters gives the compiler the adapters of the plugins of the project. It replaces the adapters of an earlier call.
func WidgetManifest ¶ added in v0.3.0
func WidgetManifest(widgets []WidgetBuild) ([]byte, error)
WidgetManifest writes the custom elements manifest of the widgets (custom-elements.json, schema 1.0.0). `gx wc check` compares it with the manifest of the last release (REQ-ISL-13).
func Widgets ¶ added in v0.3.0
func Widgets(root string) ([]WidgetBuild, []Diagnostic)
Widgets returns the widgets of the module under root, by tag. It returns the diagnostics of the module when the module does not check.
Types ¶
type ActionModel ¶
type ActionModel struct {
Handler string `json:"handler"`
Route string `json:"route"`
Method string `json:"method"`
Pattern string `json:"pattern"`
// Signals lists the signal names the action reads.
Signals []string `json:"signals"`
// External is true when another server answers the action.
External bool `json:"external"`
}
ActionModel is one gx.Action.
type AppModel ¶
type AppModel struct {
Module string `json:"module"`
Components []ComponentModel `json:"components"`
Routes []RouteModel `json:"routes"`
Actions []ActionModel `json:"actions"`
Forms []FormModel `json:"forms"`
Islands []IslandModel `json:"islands"`
Elements []ElementModel `json:"elements"`
Transitions []TransitionModel `json:"transitions"`
Icons []IconSetModel `json:"icons"`
Registry []RegistryModel `json:"registry"`
}
AppModel is the machine-readable model of an app (REQ-AI-01). `gx describe --json` prints it and the dev MCP server answers with it. The CLI adds the icon sets and the registry items from gx.lock.
type Attr ¶
type Attr struct {
At Pos
Kind AttrKind
Name string
Value string
ValueAt Pos
// Optimistic is true for an optimistic:<event> directive
// (REQ-ACT-18). The loader gives it the name of a capture handler of
// the event, so each pass reads it as an on: handler with signal
// statements.
Optimistic bool
}
Attr is one attribute of an element.
type CheckOptions ¶
type CheckOptions struct {
// ExternalLinks requests every external content link.
ExternalLinks bool
// Client is the HTTP client of the external check.
Client *http.Client
// Adapter checks the files for this adapter and not for the adapter
// key of gx.toml (REQ-ACT-09). The registry has no gx.toml, and its
// items must compile for each adapter.
Adapter string
}
CheckOptions configure one check (REQ-CNT-10).
type CollectionRef ¶
type CollectionRef struct {
Dir string
Components []ContentComponent
}
CollectionRef is one gx.Collection declaration (REQ-CNT-03).
type Component ¶
type Component struct {
Name string
File *File
Props []Prop
// Island is set when the component is a TypeScript island. File is then
// an empty file that names the .ts source.
Island *Island
}
Component is one component definition.
type ComponentModel ¶
type ComponentModel struct {
Name string `json:"name"`
Package string `json:"package"`
File string `json:"file"`
Props []PropModel `json:"props"`
Signals []SignalModel `json:"signals"`
Fragments []FragmentModel `json:"fragments"`
// Fixtures holds the fixture names of the component, in order.
Fixtures []string `json:"fixtures"`
}
ComponentModel is one .gx component.
type ComponentRef ¶
ComponentRef is one component of the module (REQ-DEV-08).
type ContentComponent ¶
ContentComponent is one component a collection allows in its Markdown files.
type DeadComponent ¶ added in v0.4.0
type DeadComponent struct {
Name string `json:"name"`
Package string `json:"package"`
File string `json:"file"`
}
DeadComponent is one component with no caller.
type DeadReport ¶ added in v0.4.0
type DeadReport struct {
// Components are the components with no caller: no tag in a .gx file
// and no call in a Go file.
Components []DeadComponent `json:"components"`
// Routes are the page routes with no typed link to them.
Routes []DeadRoute `json:"routes"`
// Classes are the classes that app/theme.css declares and that no
// file of the app uses.
Classes []string `json:"classes"`
}
DeadReport is the report of gx check --dead (REQ-DEV-14): code of the module that nothing uses. It is a report and never a failure: a registry component that the app does not use yet, and a page that only an email links to, are correct.
type Diagnostic ¶
type Diagnostic struct {
Code string
File string
Line int
Col int
Msg string
Fix string
// Hint is true for a diagnostic that does not fail a check
// (REQ-ACT-17). Only CheckApp gives hints.
Hint bool
}
Diagnostic is one compiler message.
func APIFiles ¶ added in v0.4.0
func APIFiles(root string) (map[string][]byte, []Diagnostic)
APIFiles returns the files of the JSON wire of the module under root, by name: openapi.json and client.ts. It returns no file for a module with no action with .API().
func Check ¶
func Check(root string) []Diagnostic
Check checks every .gx package under root and returns the diagnostics, ordered by file, line and column. It checks props and components, then type-checks every server expression.
func CheckApp ¶
func CheckApp(root string, opt CheckOptions) []Diagnostic
CheckApp is the whole check of an app, as `gx check` runs it: every diagnostic of CheckWith, the diagnostics that only the generator can give, and a GX1002 for each generated file that is missing or stale. A diagnostic that both passes find is reported once.
The check and the generator share one analysis: the generator starts with the same steps as CheckWith, so a second analysis finds nothing new and takes as long as the first (NFR-05).
func CheckWith ¶
func CheckWith(root string, opt CheckOptions) []Diagnostic
CheckWith checks a module with options (REQ-CNT-10).
func FormatSource ¶
func FormatSource(file string, src []byte) ([]byte, []Diagnostic)
FormatSource parses src and returns its canonical form (REQ-AUT-17). It returns the parse diagnostics instead when src does not parse.
func Generate ¶
func Generate(root string) (map[string][]byte, []Diagnostic)
Generate generates Go source for every .gx file under root. The result maps each generated file path to its source. It returns diagnostics instead when any check fails.
func Stale ¶
func Stale(root string) []Diagnostic
Stale returns GX1002 for every .gx file whose generated file is missing or out of date (REQ-AUT-18).
func (Diagnostic) Doc ¶
func (d Diagnostic) Doc() string
Doc returns the documentation path of the diagnostic (REQ-AUT-19).
func (Diagnostic) String ¶
func (d Diagnostic) String() string
type DirectiveAttr ¶ added in v0.3.0
DirectiveAttr is one HTML attribute that a directive writes.
type DirectiveUse ¶ added in v0.3.0
type DirectiveUse struct {
// Tag is the name of the element.
Tag string
// Value is the static value of the attribute. HasValue is false for
// the directive with no value.
Value string
HasValue bool
}
DirectiveUse is one use of a plugin directive in a .gx file.
type Element ¶
type Element struct {
At Pos
Name string
Attrs []Attr
Children []Node
RawText string
HasRaw bool
SelfClose bool
// contains filtered or unexported fields
}
Element is an HTML element, a component tag or a slot.
type ElementAttr ¶ added in v0.2.0
type ElementAttr struct {
Name string `json:"name"`
Kind string `json:"kind"`
Values []string `json:"values,omitempty"`
Doc string `json:"doc,omitempty"`
}
ElementAttr is one attribute of an imported element.
type ElementDef ¶ added in v0.2.0
type ElementDef struct {
Name string `json:"name"`
Tag string `json:"tag"`
Doc string `json:"doc,omitempty"`
// Module is the import specifier of the module that defines the
// element. gx pin holds its file.
Module string `json:"module"`
Attributes []ElementAttr `json:"attributes"`
Events []string `json:"events"`
Slots []string `json:"slots"`
}
ElementDef is one imported custom element. A tag <pkg.Name> renders the element <Tag>.
type ElementModel ¶ added in v0.2.0
type ElementModel struct {
Name string `json:"name"`
Package string `json:"package"`
Tag string `json:"tag"`
// Module is the import specifier of the module that defines the
// element.
Module string `json:"module"`
Attributes []ElementAttr `json:"attributes"`
Events []string `json:"events"`
Slots []string `json:"slots"`
}
ElementModel is one imported web component (REQ-ISL-09): the typed tag <package name>.<Name> renders the custom element Tag.
type ElementSet ¶ added in v0.2.0
type ElementSet struct {
// Package and Version name the npm package.
Package string `json:"package"`
Version string `json:"version"`
Elements []ElementDef `json:"elements"`
}
ElementSet is the content of an ElementsFile.
type Field ¶
type Field struct {
At Pos
Doc string
Name string
Type string
Default string
HasDefault bool
// each viewer of a room sees its value (REQ-ACT-21).
Shared bool
}
Field is one props or signals field. Doc is the text of the // lines above it, one line per comment line.
type FieldModel ¶
type FieldModel struct {
Name string `json:"name"`
Type string `json:"type"`
// Source is "path", "query", "signal" or "form".
Source string `json:"source"`
// Key is the name of the field in its source.
Key string `json:"key"`
Default string `json:"default,omitempty"`
}
FieldModel is one input field of a route.
type File ¶
type File struct {
File string
Package string
Imports []Import
HasProps bool
Props []Field
HasSignals bool
Signals []Field
Body []Node
}
File is the parsed form of one .gx file or fragment.
type FormFieldModel ¶
type FormFieldModel struct {
Name string `json:"name"`
Type string `json:"type"`
Rules []string `json:"rules"`
}
FormFieldModel is one form field. Name is the form control name; a nested field has a dotted name.
type FormModel ¶
type FormModel struct {
Handler string `json:"handler"`
Route string `json:"route"`
Method string `json:"method"`
Pattern string `json:"pattern"`
Fields []FormFieldModel `json:"fields"`
}
FormModel is one gx.Form with the rules of its input.
type FragmentModel ¶
type FragmentModel struct {
Name string `json:"name"`
// Func is the generated function, for example "CartTotal".
Func string `json:"func"`
// Params is the parameter list of the generated function.
Params []ParamModel `json:"params"`
// Keyed is true when the first parameter is the instance or loop key.
Keyed bool `json:"keyed"`
}
FragmentModel is one #fragment of a component and its generated function.
type HTMLComment ¶
HTMLComment is a <!-- ... --> comment. It renders.
func (*HTMLComment) Position ¶
func (n *HTMLComment) Position() Pos
type IconSetModel ¶
IconSetModel is one pinned icon set.
type Import ¶
type Import struct {
Raw string
}
Import is one import spec, as written, without the import keyword.
type Island ¶ added in v0.2.0
type Island struct {
Name string
// File is the path of the .ts file.
File string
// Props holds the exported fields of the props struct, in source order.
Props []Prop
// HasProps is false when the package declares no <Name>Props struct.
HasProps bool
// contains filtered or unexported fields
}
Island is one TypeScript island: a .ts file in a Go package that exports a default mount function (REQ-ISL-01). Its props are the Go struct <Name>Props of the same package.
type IslandModel ¶
type IslandModel struct {
Name string `json:"name"`
Package string `json:"package"`
File string `json:"file"`
Props []PropModel `json:"props"`
}
IslandModel is one TypeScript island (REQ-ISL-01). Props are the exported fields of its Go props struct.
type IslandRef ¶ added in v0.2.0
type IslandRef struct {
// ID is the name the server and the browser use: the import path of the
// package and the component name.
ID string
Name string
// File is the path of the .ts file.
File string
}
IslandRef is one island of a module (REQ-ISL-03).
type Model ¶
type Model struct {
Root string
Files []*File
Components []ComponentRef
Routes []RouteRef
Symbols []Symbol
Packages map[string][]string // import path -> exported names
Collections []CollectionRef // gx.Collection declarations (REQ-CNT-03)
}
Model is the whole-module index of one analysis pass (REQ-DEV-11). The LSP answers completion, hover and definition from it.
type Node ¶
type Node interface {
Position() Pos
// contains filtered or unexported methods
}
Node is a markup node.
func VisibleNodes ¶
VisibleNodes returns the nodes a renderer emits: all nodes except {/* ... */} comments (REQ-AUT-16).
type Package ¶
type Package struct {
Dir string
Module *Module
Files map[string]*File // base name without .gx
// Islands holds the TypeScript islands of the directory by name
// (REQ-ISL-01).
Islands map[string]*Island
// Elements holds the imported web components of the directory by name
// (REQ-ISL-09).
Elements map[string]*ElementDef
Diags []Diagnostic
}
Package is the parsed .gx files of one directory.
type ParamModel ¶
ParamModel is one parameter of a generated function.
type PluginAdapter ¶ added in v0.3.0
type PluginAdapter struct {
Name string
// Signals reports whether the adapter has client signals and client
// expressions.
Signals bool
// Modifiers are the event modifiers that an adapter with no signals
// can express.
Modifiers []string
}
PluginAdapter is an adapter that a plugin of the project adds (REQ-PLG-01): its name in gx.toml and what the compiler must know of it.
type PluginDirective ¶ added in v0.3.0
type PluginDirective struct {
Name string
Plugin string
// Transform returns the HTML attributes that take the place of one use
// of the directive. It runs at compile time.
Transform func(DirectiveUse) ([]DirectiveAttr, error)
// Behavior is the ES module that a page with the directive loads, or
// nil.
Behavior []byte
}
PluginDirective is one directive of a plugin of the project (REQ-PLG-03). The gx command gives the compiler the directives of its plugins before a compile. A directive has a namespace: its name is "namespace:name".
type PropModel ¶
type PropModel struct {
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Default string `json:"default,omitempty"`
Doc string `json:"doc,omitempty"`
}
PropModel is one prop of a component.
type RegistryModel ¶
type RegistryModel struct {
Name string `json:"name"`
Version string `json:"version"`
Files []string `json:"files"`
}
RegistryModel is one installed registry item.
type RouteModel ¶
type RouteModel struct {
// Type is the import path and the type name.
Type string `json:"type"`
Method string `json:"method"`
Pattern string `json:"pattern"`
Fields []FieldModel `json:"fields"`
// Kind is "page", "action", "form" or "none" when nothing handles the
// route.
Kind string `json:"kind"`
// Handler is the package-level value that handles the route.
Handler string `json:"handler,omitempty"`
Prefix string `json:"prefix,omitempty"`
Layouts []string `json:"layouts,omitempty"`
Middleware []string `json:"middleware,omitempty"`
}
RouteModel is one route type.
type RouteRef ¶
type RouteRef struct {
Key string // import path and type name
PkgPath string
Name string
Pattern string
Method string
File string
Line int
Col int
Fields []string
Registered bool
}
RouteRef is one route struct of the module (REQ-DEV-08, REQ-DEV-11).
type RouteReport ¶
type RouteReport struct {
Type string `json:"type"`
Method string `json:"method"`
Pattern string `json:"pattern"`
Fields []string `json:"fields"`
Page string `json:"page,omitempty"`
Prefix string `json:"prefix,omitempty"`
Layouts []string `json:"layouts,omitempty"`
Middleware []string `json:"middleware,omitempty"`
}
RouteReport is one entry of `gx routes` (REQ-RTE-14).
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session caches one module analysis across Generate calls, so a change to one .gx body re-checks that file alone and regenerates that file alone (NFR-05, REQ-DEV-03). A change to a Go file, to a .gx signature or to the file set falls back to a full Generate.
func (*Session) ClearOverlay ¶
ClearOverlay drops the in-memory content of one file.
func (*Session) Content ¶
func (s *Session) Content(root string) []Diagnostic
Content returns the diagnostics of the Markdown files of every gx.Collection declaration (REQ-CNT-03). An open buffer wins over disk.
func (*Session) Diagnostics ¶
func (s *Session) Diagnostics() []Diagnostic
Diagnostics returns the diagnostics of the last Generate call.
func (*Session) Generate ¶
func (s *Session) Generate(root string) (map[string][]byte, []Diagnostic)
Generate returns the generated files and diagnostics of root, reusing the previous analysis when only .gx bodies changed (NFR-05).
func (*Session) Model ¶
func (s *Session) Model(root string) (*Model, []Diagnostic)
Model runs the analysis and returns the whole-module index. It reuses the session cache, so an edit only re-checks the changed file (REQ-DEV-11).
func (*Session) SetOverlay ¶
SetOverlay records in-memory content for one input file. The next Generate call reads the overlay instead of the file on disk.
type SignalModel ¶
type SignalModel struct {
Name string `json:"name"`
Type string `json:"type"`
Default string `json:"default"`
Doc string `json:"doc,omitempty"`
}
SignalModel is one client signal of a component.
type Symbol ¶
type Symbol struct {
File string
Line int
Col int
EndCol int
Text string
Type string
ObjectFile string
ObjectLine int
ObjectCol int
}
Symbol is one typed identifier in a .gx file (REQ-DEV-08). ObjectFile is the definition position, mapped through the //line directives.
type TransitionModel ¶
type TransitionModel struct {
// Name is the package-level value.
Name string `json:"name"`
// Base is the view-transition base name.
Base string `json:"base"`
// Key is the key type.
Key string `json:"key"`
}
TransitionModel is one gx.Transition value.
type WidgetAttribute ¶ added in v0.3.0
type WidgetAttribute struct {
Name string
// Type is the TypeScript type: string, number or boolean.
Type string
Default string
}
WidgetAttribute is one attribute of a widget element.
type WidgetBuild ¶ added in v0.3.0
type WidgetBuild struct {
// Tag is the element name.
Tag string
// Class is the name of the element class in the type files.
Class string
// Dir is the directory of the package that declares the widget.
Dir string
// Path is the path of the GET route of the widget, with the prefix of
// its Group call. It has no base path of the app.
Path string
// Attributes are the fields of the route input, in the order of the
// struct.
Attributes []WidgetAttribute
// Events are the domain events of the package of the widget, by name.
Events []WidgetEvent
// Classes are the classes that the widget uses, as the class list of
// the widget has them (REQ-ISL-11).
Classes []string
// CSSVariables are the tokens of the theme that the stylesheet of the
// widget reads. The compiler does not build a stylesheet: the caller
// sets them, and WidgetManifest writes them.
CSSVariables []string
// DTS is the type file of the element, and ReactDTS the JSX types of
// the element for a React host.
DTS []byte
ReactDTS []byte
}
WidgetBuild is what `gx wc build` knows about one widget (REQ-ISL-10): the contract of its custom element with a host page.
type WidgetEvent ¶ added in v0.3.0
type WidgetEvent struct {
Name string
// Detail is the TypeScript type of the detail.
Detail string
// Contract is the type of the detail for the contract check: the
// values of a string enum are in the place of its name.
Contract string
// Fields are the fields of a detail that is an object, with the fields
// of each object below it.
Fields []WidgetField
}
WidgetEvent is one domain event of a widget.
type WidgetField ¶ added in v0.3.0
WidgetField is one field of the detail of an event. The name of a field of an object in the detail has the path to it: "item.sku", and "items[].sku" for the objects of a list.
Source Files
¶
- adapter.go
- api.go
- ast.go
- check.go
- checktypes.go
- classes.go
- classruntime.go
- clientexpr.go
- clienttranspile.go
- codefile.go
- codegen.go
- content.go
- contentbody.go
- contentmodel.go
- contentrender.go
- dead.go
- describe.go
- diag.go
- directive.go
- element.go
- email.go
- enum.go
- fiximports.go
- format.go
- frontmatter.go
- gallery.go
- island.go
- islandprops.go
- links.go
- model.go
- optimistic.go
- overlay.go
- parser.go
- pkg.go
- report.go
- routecss.go
- routes.go
- session.go
- shared.go
- symbols.go
- template.go
- tool.go
- transition.go
- updatehint.go
- wcbuild.go
- widget.go