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 ¶
IsComponentTag reports whether a JSX tag names a component rather than a host element: capitalized, dotted, or namespaced.
func IsDelegatedEvent ¶
IsDelegatedEvent reports whether an event name is delegated by solid-js.
func IsVoidElement ¶
IsVoidElement reports whether tag is an HTML void element.
func NormalizeJSXText ¶
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.
type Component ¶
Component is a capitalized or dotted tag, which compiles to a createComponent call rather than to 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.
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 (*Module) Compile ¶
Compile lowers one JSX node into a JavaScript expression, suitable for substituting in place of the original JSX.
func (*Module) Helpers ¶
Helpers returns the runtime helpers used so far, sorted. The template helper is included whenever any template was hoisted.
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 Text ¶
type Text struct {
Value string
}
Text is literal text between tags. Value is the already-normalized text; see NormalizeJSXText.