Documentation
¶
Overview ¶
Package clientlang parses GOWDK component-local client handlers.
Index ¶
- func CanonicalExpr(source string) (string, error)
- func CanonicalStatement(statement string) string
- func EvalBool(source string, values map[string]string) (bool, error)
- func EvalScalar(source string, values map[string]string) (string, error)
- func EvalValue(source string, values map[string]string) (any, error)
- func ExprCalls(source string) ([]string, error)
- func ExprFields(source string) ([]string, error)
- func IsFunctionCall(expr string) (string, bool)
- func IslandExpressionFields(expr string) []string
- func IslandRefStatement(expr string) (string, bool)
- func ParseClearStatement(statement string) (string, bool)
- func ValidateIslandBoolExpression(expr string, fields map[string]bool) error
- func ValidateIslandBoolExpressionTyped(expr string, symbols map[string]ValueType) error
- func ValidateIslandClientStatementTyped(expr string, writeSymbols map[string]ValueType, ...) error
- func ValidateIslandClientStatementTypedWithEvents(expr string, writeSymbols map[string]ValueType, ...) error
- func ValidateIslandClientStatementTypedWithFunctions(expr string, writeSymbols map[string]ValueType, ...) error
- func ValidateIslandClientStatementsTyped(statements []string, writeSymbols map[string]ValueType, ...) (map[string]bool, error)
- func ValidateIslandClientStatementsTypedWithEvents(statements []string, writeSymbols map[string]ValueType, ...) (map[string]bool, error)
- func ValidateIslandClientStatementsTypedWithFunctions(statements []string, writeSymbols map[string]ValueType, ...) (map[string]bool, error)
- func ValidateIslandClientStatementsTypedWithOptions(statements []string, writeSymbols map[string]ValueType, ...) (map[string]bool, error)
- func ValidateIslandEventExpression(expr string, fields map[string]bool, handlers ...map[string]Handler) error
- func ValidateIslandEventExpressionTyped(expr string, readSymbols map[string]ValueType, ...) error
- func ValidateIslandEventExpressionTypedWithEvents(expr string, readSymbols map[string]ValueType, ...) error
- func ValidateIslandEventExpressionTypedWithFunctions(expr string, readSymbols map[string]ValueType, ...) error
- func ValidateIslandStateStatement(expr string, writeFields map[string]bool, readFields map[string]bool) error
- func ValidateIslandStateStatementTyped(expr string, writeSymbols map[string]ValueType, ...) error
- func ValidateIslandStateStatementTypedWithFunctions(expr string, writeSymbols map[string]ValueType, ...) error
- type BinaryExpr
- type Bootstrap
- type Call
- type CallExpr
- type Computed
- type ConditionalExpr
- type Effect
- type Emit
- type EmitCall
- type Expr
- type ExprFunction
- type ExprSourceSpan
- type ExprValidationError
- type Function
- type Handler
- type Helper
- type IdentExpr
- type IndexExpr
- type LiteralExpr
- type MemberExpr
- type Param
- type ParseError
- type Program
- func (program Program) Canonical() string
- func (program Program) HandlerMap() map[string]Handler
- func (program Program) HasLifecycle() bool
- func (program Program) HelperMap() map[string]Helper
- func (program Program) NeedsBootstrap() bool
- func (program Program) OrderedComputed() ([]Computed, error)
- func (program Program) RefMap() map[string]Ref
- func (program Program) StoreNames() []string
- func (program Program) UseMap() map[string]Use
- type Ref
- type Span
- type StatementValidationError
- type UnaryExpr
- type Use
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalExpr ¶
CanonicalExpr returns a deterministic representation of the supported expression subset. It is intended for compiler fingerprints, not for source rewriting.
func CanonicalStatement ¶
CanonicalStatement returns a deterministic representation of the supported client statement subset. It is intended for fingerprints only.
func EvalScalar ¶
EvalScalar evaluates a supported expression and returns the browser-visible scalar string representation.
func ExprCalls ¶
ExprCalls returns helper function call names from a syntactically valid expression. It does not require type information.
func ExprFields ¶
ExprFields returns identifier references from a syntactically valid expression. It does not require type information.
func IsFunctionCall ¶
IsFunctionCall reports whether expr is a no-argument client function call.
func IslandExpressionFields ¶ added in v0.5.0
IslandExpressionFields returns field references in a supported island event expression.
func IslandRefStatement ¶ added in v0.5.0
IslandRefStatement reports whether expr is a safe DOM ref method call.
func ParseClearStatement ¶ added in v0.5.0
ParseClearStatement reports whether statement is a `clear <store>` builtin and returns the referenced store name. The store name is the same identifier used in the component's `use <store>` declaration (it may be package-qualified).
func ValidateIslandBoolExpression ¶ added in v0.5.0
ValidateIslandBoolExpression validates a g:if-style bool expression.
func ValidateIslandBoolExpressionTyped ¶ added in v0.5.0
ValidateIslandBoolExpressionTyped validates a g:if-style bool expression with scalar type information.
func ValidateIslandClientStatementTyped ¶ added in v0.5.0
func ValidateIslandClientStatementTyped(expr string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref) error
ValidateIslandClientStatementTyped validates a client statement that may mutate state or call a safe DOM ref method.
func ValidateIslandClientStatementTypedWithEvents ¶ added in v0.5.0
func ValidateIslandClientStatementTypedWithEvents(expr string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref, helpers map[string]ExprFunction, emits map[string]Emit, stores map[string]bool) error
ValidateIslandClientStatementTypedWithEvents validates a client statement that may mutate state, call a safe DOM ref method, read helper functions, dispatch declared component events, or clear a used page store. stores is the set of store names the component declares with `use`; a `clear <store>` statement is rejected unless the store is in that set.
func ValidateIslandClientStatementTypedWithFunctions ¶ added in v0.5.0
func ValidateIslandClientStatementTypedWithFunctions(expr string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref, helpers map[string]ExprFunction) error
ValidateIslandClientStatementTypedWithFunctions validates a client statement that may mutate state, call a safe DOM ref method, or read helper functions.
func ValidateIslandClientStatementsTyped ¶ added in v0.5.0
func ValidateIslandClientStatementsTyped(statements []string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref) (map[string]bool, error)
ValidateIslandClientStatementsTyped validates an ordered client statement block. Local variables declared with let are visible only to later statements in the same block.
func ValidateIslandClientStatementsTypedWithEvents ¶ added in v0.5.0
func ValidateIslandClientStatementsTypedWithEvents(statements []string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref, helpers map[string]ExprFunction, async bool, emits map[string]Emit, stores map[string]bool) (map[string]bool, error)
ValidateIslandClientStatementsTypedWithEvents validates an ordered client statement block with optional component event dispatch support. stores is the set of store names the component declares with `use`, used to validate `clear <store>` statements.
func ValidateIslandClientStatementsTypedWithFunctions ¶ added in v0.5.0
func ValidateIslandClientStatementsTypedWithFunctions(statements []string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref, helpers map[string]ExprFunction) (map[string]bool, error)
ValidateIslandClientStatementsTypedWithFunctions validates an ordered client statement block. Local variables declared with let are visible only to later statements in the same block.
func ValidateIslandClientStatementsTypedWithOptions ¶ added in v0.5.0
func ValidateIslandClientStatementsTypedWithOptions(statements []string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, refs map[string]Ref, helpers map[string]ExprFunction, async bool) (map[string]bool, error)
ValidateIslandClientStatementsTypedWithOptions validates an ordered client statement block with the same local-variable rules as ValidateIslandClientStatementsTypedWithFunctions. Async blocks may use compiler-owned await expressions.
func ValidateIslandEventExpression ¶ added in v0.5.0
func ValidateIslandEventExpression(expr string, fields map[string]bool, handlers ...map[string]Handler) error
ValidateIslandEventExpression validates a client event expression. When fields is non-nil, every referenced field must exist.
func ValidateIslandEventExpressionTyped ¶ added in v0.5.0
func ValidateIslandEventExpressionTyped(expr string, readSymbols map[string]ValueType, writeSymbols map[string]ValueType, handlers map[string]Handler) error
ValidateIslandEventExpressionTyped validates an event expression with scalar type information.
func ValidateIslandEventExpressionTypedWithEvents ¶ added in v0.5.0
func ValidateIslandEventExpressionTypedWithEvents(expr string, readSymbols map[string]ValueType, writeSymbols map[string]ValueType, handlers map[string]Handler, helpers map[string]ExprFunction, emits map[string]Emit) error
ValidateIslandEventExpressionTypedWithEvents validates an event expression, including component event dispatch statements.
func ValidateIslandEventExpressionTypedWithFunctions ¶ added in v0.5.0
func ValidateIslandEventExpressionTypedWithFunctions(expr string, readSymbols map[string]ValueType, writeSymbols map[string]ValueType, handlers map[string]Handler, helpers map[string]ExprFunction) error
ValidateIslandEventExpressionTypedWithFunctions validates an event expression with scalar type information and return-valued helper functions.
func ValidateIslandStateStatement ¶ added in v0.5.0
func ValidateIslandStateStatement(expr string, writeFields map[string]bool, readFields map[string]bool) error
ValidateIslandStateStatement validates a client statement that may write only writeFields and may read readFields plus scalar literals.
func ValidateIslandStateStatementTyped ¶ added in v0.5.0
func ValidateIslandStateStatementTyped(expr string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType) error
ValidateIslandStateStatementTyped validates a state statement with scalar type information.
func ValidateIslandStateStatementTypedWithFunctions ¶ added in v0.5.0
func ValidateIslandStateStatementTypedWithFunctions(expr string, writeSymbols map[string]ValueType, readSymbols map[string]ValueType, helpers map[string]ExprFunction) error
ValidateIslandStateStatementTypedWithFunctions validates a state statement with scalar type information and return-valued helper functions.
Types ¶
type BinaryExpr ¶
type BinaryExpr struct {
Op string
Left, Right Expr
Span ExprSourceSpan
}
BinaryExpr applies a binary operator.
type Bootstrap ¶
type Bootstrap struct {
Handlers map[string]Handler `json:"handlers,omitempty"`
Helpers map[string]Helper `json:"helpers,omitempty"`
Emits map[string]Emit `json:"emits,omitempty"`
Exports []string `json:"exports,omitempty"`
Stores []string `json:"stores,omitempty"`
Mount []string `json:"mount,omitempty"`
Destroy []string `json:"destroy,omitempty"`
Effects []Effect `json:"effects,omitempty"`
Computed []Computed `json:"computed,omitempty"`
}
Bootstrap is the runtime payload emitted into data-gowdk-client when a component has lifecycle/effect blocks.
type CallExpr ¶
type CallExpr struct {
Name string
Args []Expr
Span ExprSourceSpan
}
CallExpr invokes a component-local helper function.
type Computed ¶
type Computed struct {
Name string `json:"name"`
Type string `json:"-"`
Expr string `json:"expr"`
Span Span `json:"-"`
ExprSpan Span `json:"-"`
}
Computed describes one derived component-local value.
func OrderComputed ¶
OrderComputed returns computed values in dependency order and rejects cycles.
type ConditionalExpr ¶
type ConditionalExpr struct {
Cond Expr
Then Expr
Else Expr
Span ExprSourceSpan
}
ConditionalExpr chooses between two expressions from a bool condition.
type Effect ¶
type Effect struct {
Field string `json:"field"`
Statements []string `json:"statements"`
Cleanup []string `json:"cleanup,omitempty"`
StatementSpans []Span `json:"-"`
CleanupSpans []Span `json:"-"`
Span Span `json:"-"`
}
Effect is a dependency-triggered client block.
type Emit ¶
type Emit struct {
Name string `json:"-"`
Params []string `json:"params,omitempty"`
ParamTypes []ValueType `json:"-"`
}
Emit describes one component event exposed to parent component calls.
type EmitCall ¶
EmitCall is a component event dispatch statement.
func ParseEmitCall ¶
ParseEmitCall reports whether expr is an emit event(args...) statement.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr describes a parsed client expression.
func ParseExprWithSpans ¶
ParseExprWithSpans parses the supported client expression subset and records 1-based source columns on every expression node.
type ExprFunction ¶
ExprFunction describes a return-valued helper callable from expressions.
type ExprSourceSpan ¶
ExprSourceSpan is a 1-based column span within the expression source. End is exclusive.
func ExprSpan ¶
func ExprSpan(expr Expr) ExprSourceSpan
ExprSpan returns the source span recorded for expr.
type ExprValidationError ¶
type ExprValidationError struct {
Span ExprSourceSpan
Err error
}
ExprValidationError wraps an expression validation failure with the source columns of the expression node that failed.
func (ExprValidationError) Error ¶
func (err ExprValidationError) Error() string
func (ExprValidationError) Unwrap ¶
func (err ExprValidationError) Unwrap() error
type Function ¶
type Function struct {
Name string
Async bool
Params []Param
ReturnType string
Statements []string
StatementSpans []Span
Span Span
}
Function is a component-local browser handler.
type Handler ¶
type Handler struct {
Params []string `json:"params,omitempty"`
ParamTypes []ValueType `json:"-"`
Async bool `json:"async,omitempty"`
Statements []string `json:"statements"`
}
Handler is the runtime representation emitted into island bootstrap data.
type Helper ¶
type Helper struct {
Params []string `json:"params,omitempty"`
ParamTypes []ValueType `json:"-"`
ReturnType ValueType `json:"-"`
Return string `json:"return"`
}
Helper is a return-valued component-local function callable from expressions. Helpers cannot be called directly as event handlers.
type IdentExpr ¶
type IdentExpr struct {
Name string
Span ExprSourceSpan
}
IdentExpr reads a state, prop, param, or local name.
type IndexExpr ¶
type IndexExpr struct {
X Expr
Index Expr
Span ExprSourceSpan
}
IndexExpr reads an item from an array expression.
type LiteralExpr ¶
type LiteralExpr struct {
Type ValueType
Value string
Span ExprSourceSpan
}
LiteralExpr is a scalar literal.
type MemberExpr ¶
type MemberExpr struct {
X Expr
Name string
Span ExprSourceSpan
}
MemberExpr reads a field from an object expression.
type ParseError ¶
ParseError reports a client {} parse failure with a 1-based line relative to the client block body when available.
func (*ParseError) Error ¶
func (err *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (err *ParseError) Unwrap() error
type Program ¶
type Program struct {
Functions []Function
Mount []string
MountSpans []Span
Destroy []string
DestroySpans []Span
Effects []Effect
Refs []Ref
Uses []Use
Computed []Computed
}
Program is the parsed representation of a component client {} block.
func (Program) Canonical ¶
Canonical returns a deterministic representation used for component redundancy checks.
func (Program) HandlerMap ¶
HandlerMap returns deterministic handlers keyed by function name.
func (Program) HasLifecycle ¶
HasLifecycle reports whether the program needs the runtime bootstrap envelope.
func (Program) HelperMap ¶
HelperMap returns deterministic return-valued helpers keyed by function name.
func (Program) NeedsBootstrap ¶
NeedsBootstrap reports whether the program needs the runtime bootstrap envelope instead of the older direct handler map.
func (Program) OrderedComputed ¶
OrderedComputed returns computed values in dependency order. References to other computed names must be evaluated before the dependent value.
func (Program) StoreNames ¶
StoreNames returns deterministic page-scoped store names used by the program.
type StatementValidationError ¶ added in v0.5.0
StatementValidationError identifies the statement index that failed within a client statement block.
func (StatementValidationError) Error ¶ added in v0.5.0
func (err StatementValidationError) Error() string
func (StatementValidationError) Unwrap ¶ added in v0.5.0
func (err StatementValidationError) Unwrap() error
type UnaryExpr ¶
type UnaryExpr struct {
Op string
X Expr
Span ExprSourceSpan
}
UnaryExpr applies a unary operator.
type Use ¶
Use declares one page-scoped store used by this component. Type is the optional Go type annotation (`use cart ui.CartState`) that binds the store's shape into the component's client scope so its fields can be referenced without redeclaring a matching state contract.
type ValueType ¶
type ValueType string
ValueType is the small client expression type universe.
func CheckExprWithFunctions ¶
func CheckExprWithFunctions(source string, symbols map[string]ValueType, functions map[string]ExprFunction) (ValueType, []string, error)
CheckExprWithFunctions parses and type-checks a client expression against value symbols and return-valued helper functions.
func NormalizeType ¶
NormalizeType maps Go/GOWDK scalar type names into client expression types.