CMX is the native markup syntax built into CLS, inspired by JSX and HTML. It lets you describe tree-shaped data structures — UI components, documents, configuration hierarchies — directly insideDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
.clsx source files without any transpilation step or external dependency. A CMX expression evaluates to a first-class CLS value called a CmxValue, which your code can inspect, transform, pass to functions, and store like any other value. CMX is not a templating engine: it produces data, not strings.
Syntax Overview
CMX elements look like HTML tags embedded in CLS code. You can use them anywhere an expression is expected.- Self-closing
- With children
- With attributes
- Multi-element
Tag Forms
| Syntax | Description |
|---|---|
<Name attr="val"> | Opening tag — begins a block with children. |
</Name> | Closing tag — ends the block opened by <Name>. |
<Name attr="val" /> | Self-closing tag — no children. |
Attribute Forms
| Syntax | Value type |
|---|---|
attr="literal" | String literal — always a String value. |
attr={expression} | Any CLS expression — evaluated at runtime. |
Lowercase Tags → String tag
When the tag name starts with a lowercase letter, CLS stores the tag name as a plainString in the .tag field. Evaluating the element builds a CmxValue with three fields:
| Field | Type | Contents |
|---|---|---|
.tag | Value (a String) | The tag name string as written in source. |
.props | Record<String, Value> | All attributes as key-value pairs. |
.children | Array<Value> | Child elements and text nodes, in order. |
Uppercase Tags → Reference Stored in .tag
When the tag name starts with an uppercase letter, CLS performs a scope lookup and stores whatever value the name resolves to (a function, class, variable, etc.) directly in the .tag field — without calling it. If no variable with that name exists, .tag falls back to the tag name string.
CmxValue data structure; what happens to .tag (whether it is called, rendered, or inspected) is entirely up to your code.
<App title="Hello" /> does not call App. It creates a CmxValue whose .tag field holds the App function reference. Your framework layer decides when and how to call it.Text Children and Nested Elements
Text content between tags becomes aString value in the children array. Nested elements become CmxValue values recursively.
Expression Interpolation in Children
Wrap any CLS expression in{ } to embed it as a child value:
{ } is evaluated at the point the CMX element is constructed, so you can use variables, function calls, arithmetic — anything that produces a value.
Complex Example
Here is a realistic component tree that combines string attributes, expression attributes, and nested elements. Because uppercase tags store function references in.tag rather than calling them, the tree is pure data until your code acts on it:
Event Handler Pattern
Because expression attributes accept any CLS value, the idiomatic way to attach a callback is to pass an arrow function:Implementation Notes
CMX processing is integrated directly into the CLS compiler pipeline:Lexer
The lexer recognises
<TagName …> token sequences and emits dedicated markup tokens, distinguishing them from comparison operators and generics.Parser
parse_cmx_element consumes the markup tokens and builds a Expression::Cmx AST node containing the tag name, a list of attribute pairs, and a list of child expressions.Interpreter
evaluate_cmx walks the Expression::Cmx node. It evaluates all attribute expressions and child expressions, then constructs and returns a CmxValue. For lowercase tags the .tag field is a String; for uppercase tags the interpreter performs a scope lookup and stores the resolved value (function, class, variable) directly in .tag — without calling it.CmxValue Field Summary
| Field | Access | Description |
|---|---|---|
.tag | el.tag | Value: a String for lowercase tags; the resolved scope value (function, class, etc.) for uppercase tags. |
.props | el.props.attrName | Record of all attribute key/value pairs. |
.children | el.children[i] | Ordered array of child strings and CmxValues. |