Support parsing modifiers#11
Conversation
Adds support for token modifiers with contexts in the resolver document format. - Parse and serialize modifier items with their contexts - Implement namespace isolation: modifiers can only reference global set tokens and their own context tokens, not other modifiers - Skip modifier and context nodes in CSS/SCSS variable generation - Add comprehensive tests for modifier parsing, serialization, isolation, and export behavior - Add new ModifierMeta and ContextMeta node types Modifiers provide conditional token variations (e.g., theme modes like light/dark, contrast levels) that don't pollute the global namespace and can be resolved at build time.
✅ Deploy Preview for tools-for-web ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds token-modifier and token-context node types across the codebase, updates resolver to parse/serialize modifiers and contexts, excludes modifier/context subtrees from variable generation and tree rendering, and expands tests to validate modifier handling, isolation, serialization, and variable-generation skipping. Changes
Sequence DiagramsequenceDiagram
participant Parser as Parser
participant ResolverP1 as Resolver (Phase 1)
participant ResolverP2 as Resolver (Phase 2)
participant Serializer as Serializer
Parser->>ResolverP1: Parse document (sets + modifiers)
Note over ResolverP1: Collect global intermediaries from sets<br/>Collect context-specific intermediaries under each modifier
ResolverP1->>ResolverP2: Provide intermediaries & node graph
ResolverP2->>ResolverP2: Resolve sets using global intermediaries<br/>Resolve modifier contexts using local + global intermediaries
Note over ResolverP2: Attach context nodes under modifiers<br/>Aggregate errors and defaults
ResolverP2->>Serializer: Emit resolved structure
Note over Serializer: Serialize `token-sets` as sets and `token-modifiers` with contexts
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
✅ Deploy Preview for engramma-website canceled.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/app.svelte`:
- Around line 89-94: The initial selection/expansion logic uses rootNodes[0] but
treeData filters rootNodes to only token-sets, causing selectedItems,
expandedItems, and NewProject onCreate to point at hidden nodes; create a
derived rootTokenSets array (e.g., const rootTokenSets = rootNodes.filter(n =>
n.meta.nodeType === "token-set")) and use it wherever initial or created
selections/expansions are set (replace uses of rootNodes[0] in selectedItems,
expandedItems, and the NewProject onCreate handler) so selection/expansion
aligns with the filtered treeData and newly created nodes are selected within
the visible token-set list.
In `@src/export-dialog.svelte`:
- Around line 20-24: The current if-check adding nodeIds to setIds (checking
node.meta.nodeType === "token-set" || "token-modifier" || "token-context")
causes modifier/context subtrees to be treated as global sets and flattens their
children into the root JSON; change the logic in export-dialog.svelte so that
only "token-set" nodeIds are added to setIds (i.e., remove "token-modifier" and
"token-context" from that branch) or, if you prefer namespacing, keep them out
of setIds and instead namespace their descendant keys during JSON assembly
(e.g., prefix descendant token keys with the modifier/context id) so
modifier/context tokens are not reparented into the global namespace.
🧹 Nitpick comments (1)
src/css-variables.test.ts (1)
1117-1125: DeduplicatenodesToMaphelper to avoid drift.A helper with the same implementation already exists at the top of the file. Reusing it keeps behavior consistent and reduces maintenance overhead.
♻️ Proposed refactor
describe("generateCssVariables with modifiers and contexts", () => { - // Helper to convert array to Map - const nodesToMap = (nodes: TreeNode<TreeNodeMeta>[]) => { - const map = new Map<string, TreeNode<TreeNodeMeta>>(); - for (const node of nodes) { - map.set(node.nodeId, node); - } - return map; - }; - test("skips modifier nodes and their entire subtrees", () => {
Adds support for token modifiers with contexts in the resolver document format.
Modifiers provide conditional token variations (e.g., theme modes like light/dark, contrast levels) that don't pollute the global namespace and can be resolved at build time.
Summary by CodeRabbit
New Features
Improvements
Tests