solid

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package solid lowers JSX into the DOM-expressions calls that solid-js/web provides.

The transform operates on the JSX intermediate representation defined in this file rather than on any parser's AST. Build the IR directly, or use the tsx package to produce it from TypeScript source.

m := solid.NewModule(solid.Options{})
expr := m.Compile(node)
src := m.Prelude() + "const C = () => " + expr + ";" + m.Postlude()

Compile returns a JavaScript expression. Prelude returns the runtime import and hoisted templates the compiled expressions refer to, and Postlude the event delegation registration; both must be included in the emitted module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsComponentTag

func IsComponentTag(tag string) bool

IsComponentTag reports whether a JSX tag names a component rather than a host element: capitalized, dotted, or namespaced.

func IsDelegatedEvent

func IsDelegatedEvent(name string) bool

IsDelegatedEvent reports whether an event name is delegated by solid-js.

func IsVoidElement

func IsVoidElement(tag string) bool

IsVoidElement reports whether tag is an HTML void element.

func NormalizeJSXText

func NormalizeJSXText(s string) string

NormalizeJSXText applies JSX's whitespace rules to raw text between tags: whitespace-only lines vanish, indentation is stripped, and interior line breaks collapse to a single space.

The empty string means the text contributes nothing.

Types

type Attr

type Attr struct {
	Namespace string
	Name      string
	Kind      AttrKind
	// Value is the string content for AttrString, or the expression source
	// for AttrExpr.
	Value string
}

Attr is a JSX attribute. Namespace holds the part before a colon, as in on:click, use:directive, prop:value, attr:id, bool:x, style:color, class:active.

func (Attr) IsDynamic

func (a Attr) IsDynamic() bool

IsDynamic reports whether the value must be re-evaluated when reactive state changes.

type AttrKind

type AttrKind uint8

AttrKind discriminates how an attribute's value was written.

const (
	// AttrBare is a valueless attribute, as in <input disabled />, which means
	// the boolean true.
	AttrBare AttrKind = iota
	// AttrString is a literal string value, as in class="card".
	AttrString
	// AttrExpr is an interpolated value, as in class={x}.
	AttrExpr
)

type Component

type Component struct {
	Tag      string
	Attrs    []Attr
	Children []Node
}

Component is a capitalized or dotted tag, which compiles to a createComponent call rather than to DOM.

type Element

type Element struct {
	Tag      string
	Attrs    []Attr
	Children []Node
}

Element is a host element: a lowercase tag that becomes real DOM.

type Expr

type Expr struct {
	Code string
}

Expr is a {...} interpolation. Code is the original TypeScript source of the expression, which is emitted verbatim.

func (*Expr) IsDynamic

func (e *Expr) IsDynamic() bool

IsDynamic reports whether an interpolated child must be wrapped so that it re-runs on change.

type Fragment

type Fragment struct {
	Children []Node
}

Fragment is <>...</>, which compiles to an array.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module accumulates the state shared across every JSX expression in one source file: hoisted templates, the runtime helpers used, and the events needing delegation.

Compile one expression at a time, then take the Prelude and Postlude. A Module is not safe for concurrent use.

func NewModule

func NewModule(opts Options) *Module

NewModule returns a Module ready to compile the JSX of one source file.

func (*Module) Compile

func (m *Module) Compile(n Node) string

Compile lowers one JSX node into a JavaScript expression, suitable for substituting in place of the original JSX.

func (*Module) Helpers

func (m *Module) Helpers() []string

Helpers returns the runtime helpers used so far, sorted. The template helper is included whenever any template was hoisted.

func (*Module) Postlude

func (m *Module) Postlude() string

Postlude returns the statements that must appear at the end of the module: the event delegation registration, if any.

func (*Module) Prelude

func (m *Module) Prelude() string

Prelude returns the statements that must appear at the top of the module: the runtime import and the hoisted template declarations.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node is a node of the JSX intermediate representation.

type Options

type Options struct {
	// ModuleName is the import source for runtime helpers.
	// Defaults to "solid-js/web".
	ModuleName string

	// Delegate routes supported events through a single document-level
	// listener. Defaults to true; set DisableDelegation to turn it off.
	DisableDelegation bool

	// Prefix is prepended to generated runtime helper identifiers.
	// Defaults to "_$", matching solid's own output.
	Prefix string
}

Options configures the transform. The zero value is valid.

type Spread

type Spread struct {
	Code string
}

Spread is a {...props} attribute position.

type Text

type Text struct {
	Value string
}

Text is literal text between tags. Value is the already-normalized text; see NormalizeJSXText.

Jump to

Keyboard shortcuts

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