You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/assets/internal.md
+29-30Lines changed: 29 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Internal docs
2
2
3
-
Below is a **"mental model"** of the Zero‑UI variant extractor—distilled so that *another* human (or LLM) can reason about, extend, or safely refactor the code‑base.
3
+
Below is a **"mental model"** of the Zero‑UI variant extractor—distilled so that _another_ human (or LLM) can reason about, extend, or safely refactor the code‑base.
4
4
5
5
---
6
6
@@ -13,13 +13,12 @@ Below is a **"mental model"** of the Zero‑UI variant extractor—distilled so
13
13
```
14
14
15
15
2.**Resolve** (using §3) the `stateKey` and `initialValue` arguments **at build‑time.**
16
-
17
-
*`stateKey` must be a *local*, static string.
18
-
*`initialValue` follows the same rule.
16
+
-`stateKey` must be a _local_, static string.
17
+
-`initialValue` follows the same rule.
19
18
20
19
3.**Globally scan all project files** for **variant tokens that match any discovered `stateKey`**—regardless of where hooks are declared. `(scanner.cts) → scanVariantTokens`
|**A - collectUseUIHooks**| Single AST traversal per file.<br>• Validate `useUI()` shapes.<br>• Resolve **stateKey** & **initialValue** with **`literalFromNode`** (§3).<br>• Builds global set of all state keys. |`HookMeta[]` = `{ stateKey, initialValue }[]`, global `Set<stateKey>`|
72
-
|**B - global scanVariantTokens**| Single global regex scan pass over all files (same glob & delimiters Tailwind uses).<br>Matches tokens for **every stateKey discovered in Stage A**. |`Map<stateKey, Set<value>>`|
|**A - collectUseUIHooks**| Single AST traversal per file.<br>• Validate `useUI()` shapes.<br>• Resolve **stateKey** & **initialValue** with **`literalFromNode`** (§3).<br>• Builds global set of all state keys. |`HookMeta[]` = `{ stateKey, initialValue }[]`, global `Set<stateKey>`|
71
+
|**B - global scanVariantTokens**| Single global regex scan pass over all files (same glob & delimiters Tailwind uses).<br>Matches tokens for **every stateKey discovered in Stage A**. |`Map<stateKey, Set<value>>`|
73
72
74
73
The pipeline now ensures tokens are captured globally—regardless of hook declarations in each file.
75
74
76
75
---
77
76
78
77
## 3. The literal‑resolution micro‑framework
79
78
80
-
Everything funnels through **`literalFromNode`**. Think of it as a deterministic *static evaluator* restricted to a very small grammar.
79
+
Everything funnels through **`literalFromNode`**. Think of it as a deterministic _static evaluator_ restricted to a very small grammar.
81
80
82
81
### 3.1 Supported input forms (stateKey & initialValue)
83
82
@@ -112,11 +111,11 @@ Everything funnels through **`literalFromNode`**. Think of it as a deterministic
112
111
113
112
### 3.2 Resolvers
114
113
115
-
| Helper | Purpose |
116
-
| -- | -- |
117
-
|**`resolveTemplateLiteral`**| Ensures every `${expr}` resolves via `literalFromNode`. |
118
-
|**`resolveLocalConstIdentifier`**| Maps an `Identifier` → its `const` initializer *iff* initializer is a local static string/template. Imported bindings rejected explicitly. |
119
-
|**`resolveMemberExpression`**| Static walk of `obj.prop`, `obj['prop']`, `obj?.prop`, arrays, numeric indexes, optional‑chaining… Throws if unresolved. |
|**`resolveTemplateLiteral`**| Ensures every `${expr}` resolves via `literalFromNode`.|
117
+
|**`resolveLocalConstIdentifier`**| Maps an `Identifier` → its `const` initializer _iff_ initializer is a local static string/template. Imported bindings rejected explicitly. |
118
+
|**`resolveMemberExpression`**| Static walk of `obj.prop`, `obj['prop']`, `obj?.prop`, arrays, numeric indexes, optional‑chaining… Throws if unresolved.|
120
119
|**`literalFromNode`**| Router calling above; memoised (`WeakMap`) per AST node. |
121
120
122
121
Resolvers throw contextual errors via **`throwCodeFrame`** (`@babel/code-frame`).
0 commit comments