clientlang

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package clientlang parses GOWDK component-local client handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalExpr

func CanonicalExpr(source string) (string, error)

CanonicalExpr returns a deterministic representation of the supported expression subset. It is intended for compiler fingerprints, not for source rewriting.

func CanonicalStatement

func CanonicalStatement(statement string) string

CanonicalStatement returns a deterministic representation of the supported client statement subset. It is intended for fingerprints only.

func EvalBool

func EvalBool(source string, values map[string]string) (bool, error)

EvalBool evaluates a supported expression as a bool against scalar values.

func EvalScalar

func EvalScalar(source string, values map[string]string) (string, error)

EvalScalar evaluates a supported expression and returns the browser-visible scalar string representation.

func EvalValue

func EvalValue(source string, values map[string]string) (any, error)

EvalValue evaluates a supported expression and returns its typed value.

func ExprCalls

func ExprCalls(source string) ([]string, error)

ExprCalls returns helper function call names from a syntactically valid expression. It does not require type information.

func ExprFields

func ExprFields(source string) ([]string, error)

ExprFields returns identifier references from a syntactically valid expression. It does not require type information.

func IsFunctionCall

func IsFunctionCall(expr string) (string, bool)

IsFunctionCall reports whether expr is a no-argument client function call.

func IslandExpressionFields added in v0.5.0

func IslandExpressionFields(expr string) []string

IslandExpressionFields returns field references in a supported island event expression.

func IslandRefStatement added in v0.5.0

func IslandRefStatement(expr string) (string, bool)

IslandRefStatement reports whether expr is a safe DOM ref method call.

func ParseClearStatement added in v0.5.0

func ParseClearStatement(statement string) (string, bool)

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

func ValidateIslandBoolExpression(expr string, fields map[string]bool) error

ValidateIslandBoolExpression validates a g:if-style bool expression.

func ValidateIslandBoolExpressionTyped added in v0.5.0

func ValidateIslandBoolExpressionTyped(expr string, symbols map[string]ValueType) error

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 Call

type Call struct {
	Name string
	Args []string
}

Call is a component-local function invocation expression.

func ParseCall

func ParseCall(expr string) (Call, bool)

ParseCall reports whether expr is a component-local function call.

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

func OrderComputed(computeds []Computed) ([]Computed, error)

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

type EmitCall struct {
	Name string
	Args []string
}

EmitCall is a component event dispatch statement.

func ParseEmitCall

func ParseEmitCall(expr string) (EmitCall, bool)

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 ParseExpr

func ParseExpr(source string) (Expr, error)

ParseExpr parses the supported client expression subset.

func ParseExprWithSpans

func ParseExprWithSpans(source string) (Expr, error)

ParseExprWithSpans parses the supported client expression subset and records 1-based source columns on every expression node.

type ExprFunction

type ExprFunction struct {
	Params []ValueType
	Return ValueType
}

ExprFunction describes a return-valued helper callable from expressions.

type ExprSourceSpan

type ExprSourceSpan struct {
	StartColumn int
	EndColumn   int
}

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 Param

type Param struct {
	Name string
	Type string
}

Param describes one typed function parameter.

type ParseError

type ParseError struct {
	Line int
	Err  error
}

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 Parse

func Parse(source string) (Program, error)

Parse parses the first component client {} language slice.

func (Program) Canonical

func (program Program) Canonical() string

Canonical returns a deterministic representation used for component redundancy checks.

func (Program) HandlerMap

func (program Program) HandlerMap() map[string]Handler

HandlerMap returns deterministic handlers keyed by function name.

func (Program) HasLifecycle

func (program Program) HasLifecycle() bool

HasLifecycle reports whether the program needs the runtime bootstrap envelope.

func (Program) HelperMap

func (program Program) HelperMap() map[string]Helper

HelperMap returns deterministic return-valued helpers keyed by function name.

func (Program) NeedsBootstrap

func (program Program) NeedsBootstrap() bool

NeedsBootstrap reports whether the program needs the runtime bootstrap envelope instead of the older direct handler map.

func (Program) OrderedComputed

func (program Program) OrderedComputed() ([]Computed, error)

OrderedComputed returns computed values in dependency order. References to other computed names must be evaluated before the dependent value.

func (Program) RefMap

func (program Program) RefMap() map[string]Ref

RefMap returns declared DOM refs keyed by name.

func (Program) StoreNames

func (program Program) StoreNames() []string

StoreNames returns deterministic page-scoped store names used by the program.

func (Program) UseMap

func (program Program) UseMap() map[string]Use

UseMap returns declared page-scoped store uses keyed by store name.

type Ref

type Ref struct {
	Name string
	Kind string
}

Ref is a declared DOM reference.

type Span

type Span struct {
	StartLine int
	EndLine   int
}

Span is a 1-based source span relative to the component client {} body.

type StatementValidationError added in v0.5.0

type StatementValidationError struct {
	Index int
	Err   error
}

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

type Use struct {
	Name         string
	PackageAlias string
	StoreName    string
	Type         string
	Span         Span
}

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.

const (
	TypeUnknown ValueType = ""
	TypeString  ValueType = "string"
	TypeInt     ValueType = "int"
	TypeFloat   ValueType = "float"
	TypeBool    ValueType = "bool"
	TypeNil     ValueType = "nil"
	TypeObject  ValueType = "object"
	TypeArray   ValueType = "array"
)

func CheckExpr

func CheckExpr(source string, symbols map[string]ValueType) (ValueType, []string, error)

CheckExpr parses and type-checks a client expression against symbols.

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

func NormalizeType(value string) ValueType

NormalizeType maps Go/GOWDK scalar type names into client expression types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL