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)
- 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 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.
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"`
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 UnaryExpr ¶
type UnaryExpr struct {
Op string
X Expr
Span ExprSourceSpan
}
UnaryExpr applies a unary operator.
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.