feat(wrn): support native structured prop expressions

This commit is contained in:
2026-07-29 16:46:18 +05:30
parent 6afe32f63f
commit 8fc6f15402
68 changed files with 210 additions and 118 deletions
+13 -4
View File
@@ -15,14 +15,20 @@ WRNexusJS 0.3 keeps all previously supported declarations, including:
- `data-for`, `{#each}`, conditions, interpolations, events, and `class:*`
New syntax is additive. Existing projects do not need to adopt it immediately.
Dynamic attribute expressions should be single-quoted so braces remain unambiguous:
Since WRNexusJS 0.5.1, dynamic component props may use JSX-style unquoted
expressions. Quoted expression attributes remain supported for compatibility:
```wrn
<FeatureList items='{items}' primaryAction='{{ label: "Open" }}' />
state items = [{"label":"Accessibility","href":"/accessibility"}]
<FeatureList items={items} />
<FeatureList items={[{"label":"Accessibility","href":"/accessibility"}]} />
<FeatureList primaryAction={{"label":"Open","href":"/open"}} />
<FeatureList items="{items}" />
```
The 0.3 updater only rewrites simple, unambiguous `prop={expression}` values. Nested
brace expressions are left unchanged and reported for manual review.
Expression-valued component props serialize arrays and objects as JSON while preserving
booleans, numbers, and strings. Literal HTML attributes continue to require quotes.
## File structure
@@ -76,9 +82,12 @@ props {
}
state open: boolean = false
state links = [{"label":"Home","href":"/"}]
state options = {"dense":true}
```
A prop without an initializer is required. State always requires an initializer.
State initializers are JavaScript expressions, including native arrays and objects.
Typed initializers are validated when their literal type can be determined.
## Computed values and effects