Skip to content

Support parsing modifiers#11

Merged
TrySound merged 3 commits into
mainfrom
parse-modifiers
Feb 16, 2026
Merged

Support parsing modifiers#11
TrySound merged 3 commits into
mainfrom
parse-modifiers

Conversation

@TrySound
Copy link
Copy Markdown
Owner

@TrySound TrySound commented Feb 16, 2026

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.

Summary by CodeRabbit

  • New Features

    • Added token modifiers and contexts to represent variant token groups and isolated contexts.
  • Improvements

    • Resolver and serialization now recognize and emit modifiers and their contexts.
    • Export and variable-generation (CSS/SCSS) workflows now skip modifier/context subtrees so generated variables exclude modifier-only tokens.
    • Tree rendering now defaults to showing token sets at root, adjusting initial selection/expansion.
  • Tests

    • Added comprehensive tests covering modifier parsing, serialization, and variable-generation behavior.

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.
@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 16, 2026

Deploy Preview for tools-for-web ready!

Name Link
🔨 Latest commit 8890397
🔍 Latest deploy log https://app.netlify.com/projects/tools-for-web/deploys/6992d38af7f5f00008303baa
😎 Deploy Preview https://deploy-preview-11--tools-for-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Core Type Definitions
src/state.svelte.ts
Added ModifierMeta and ContextMeta types; extended TreeNodeMeta union; updated token type resolution to treat token-modifier and token-context as non-inheriting nodes.
Tree Rendering & UI
src/app.svelte, src/export-dialog.svelte
src/app.svelte now derives root nodes by filtering to only meta.nodeType === "token-set"; src/export-dialog.svelte explicitly skips token-modifier and token-context nodes when building export maps/sets.
Resolver Logic & Types
src/resolver.ts
Major resolver expansion to support modifiers and contexts: collects context-specific intermediaries, creates context nodes under modifiers, preserves default contexts, prevents global pollution from modifiers, and serializes both ResolverSet and ResolverModifier entries. Introduces use of ResolverModifier and related metadata handling.
Variable Generation
src/css-variables.ts, src/scss.ts
Added early returns to skip processing entire subtrees whose nodeType is token-modifier or token-context, leaving token-set children processed but excluding modifier/context-derived variables.
Export / Serialization Tests
src/resolver.test.ts
Extensive new and updated tests covering parsing, serialization, round-trips, modifier context counts, default context linkage, reparenting, preservation of descriptions/extensions, isolation rules, cross-set reference validation, and error conditions involving modifiers.
Variable Generation Tests
src/css-variables.test.ts, src/scss.test.ts
Added tests asserting modifiers/contexts are skipped during CSS/SCSS variable generation and validating various modifier-context scenarios (skipped subtrees, nested groups, multiple modifiers).

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

🐰 A modifier hopped into the glade,
Contexts nested where tokens played,
The resolver sorted set from shade,
Skipping subtrees the hunters made,
I cheered — a tidy forest newly laid 🌿

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Support parsing modifiers' accurately and concisely summarizes the main objective of the PR, which adds support for token modifiers in the resolver.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch parse-modifiers

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 16, 2026

Deploy Preview for engramma-website canceled.

Name Link
🔨 Latest commit 8890397
🔍 Latest deploy log https://app.netlify.com/projects/engramma-website/deploys/6992d38a128eb300082a8af3

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: Deduplicate nodesToMap helper 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", () => {

Comment thread src/app.svelte Outdated
Comment thread src/export-dialog.svelte
@TrySound TrySound merged commit 3396920 into main Feb 16, 2026
10 checks passed
@TrySound TrySound deleted the parse-modifiers branch February 16, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant