Skip to content

feat(core): report unresolved token references at build - #343

Merged
alexgrozav merged 2 commits into
mainfrom
report-unresolved-references-uxf-410
Oct 21, 2026
Merged

alexgrozav merged 2 commits into
mainfrom
report-unresolved-references-uxf-410

Conversation

@alexgrozav

@alexgrozav alexgrozav commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

A token reference that resolves to nothing used to build without a word. recipe({ base: { background: "@color.brnad" } }) emitted var(--color--brnad), a variable that is never declared, and a misspelled theme override or a second variable("color.brand", …) lost a value silently. The docs said the first case throws at compile time. It didn't.

This adds validate(instance) to @styleframe/core. It walks the finished instance once and returns every problem as a diagnostic (code, severity, message, path, optional suggestion):

  • unresolved-reference: an @token in a recipe (base, variants, compoundVariants, modifier blocks), a utility value (including a namespace fallback) or a css template literal, or a ref() anywhere, that resolves to no variable in scope. A plain @token string in a selector or theme declaration still throws when it's defined, as before. The path names where it was made, like recipe "button" › compoundVariants[0] › hover:enabled › background, and the suggestion is the closest token within two edits (@color.brnad → color.brand).
  • undefined-theme-override: a theme variable() whose name isn't defined at root.
  • duplicate-variable: two variable() calls with the same name and without default: true, with both values.

transpile() runs it once, after the licence step, and returns the diagnostics as diagnostics beside files, so existing builds keep emitting as before. With styleframe({ strict: true }), it throws one error that lists them all. Printing them in the CLI and the plugin comes in a follow-up.

Also in this PR:

  • Nested at-rules keep hyphenated names: "@starting-style" emitted @starting -style {, and "@font-feature-values Font One" broke the same way.
  • @styleframe/theme gains z-index.tooltip (700), which the tooltip recipe already referenced. The xs chip indicator, a dot with no text, used the undefined @font-size.4xs and now uses @font-size.3xs.
  • @styleframe/transpiler and styleframe peer on @styleframe/core as workspace:^, so they publish against the core release that ships validate().
  • main builds again: useSelectRecipeContrast.test.ts redeclared wcagContrast, which theme/src/shims.d.ts already declares.
  • The recipe and utility API pages no longer promise a compile-time error, and the instance page documents strict.

Related issue

None.

Type of change

  • 🐞 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📖 Documentation
  • ♻️ Refactor / internal (no functional change)
  • 🔧 Build / tooling / CI

Checklist

  • My commits follow Conventional Commits with a package scope (e.g. feat(theme): …)
  • I ran pnpm build:nodocs && pnpm lint && pnpm typecheck && pnpm test and everything passes
  • I added a changeset (pnpm changeset) for changes to publishable packages, or this change only touches docs/storybook/app/playground/tests
  • I added or updated tests where relevant
  • I updated documentation where relevant
  • I did not edit generated files (dist/, .styleframe/)
  • My PR targets main and stays focused in scope

Notes / screenshots

A test builds an instance with useDesignTokensPreset, useModifiersPreset, useUtilitiesPreset and every use*Recipe composable the theme exports, and asserts validate(s) returns []. That test is what found the tooltip and chip references.

A ref() with a fallback isn't reported, since it resolves to its fallback. Only references inside the fallback are checked.

A reference to a missing token in a recipe or a utility value built
silently and emitted a var() that is never declared, and a misspelled
theme override or a duplicate variable lost a value without a word.

validate(instance) walks the finished instance and returns every
problem in one pass: unresolved-reference, undefined-theme-override and
duplicate-variable, each with the path that made it and the closest
token name within two edits. transpile() runs it once and returns the
diagnostics beside files, or throws one error listing them all under
the new strict option. variable() and the utility namespace fallback
keep a record on the root of what the finished tree no longer holds.

Nested at-rules keep hyphenated names, so @starting-style and
@font-feature-values emit as written. The theme gains z-index.tooltip,
which the tooltip recipe already used, and the xs chip indicator stops
referencing the undefined font-size.4xs. The transpiler and barrel peer
on the core release that ships validate(). The theme typecheck builds
again without the duplicate wcagContrast declaration.
@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
styleframe-dev Ready Ready Preview Oct 21, 2026 6:46am UTC
styleframe-dev-storybook Ready Ready Preview Oct 21, 2026 6:46am UTC

Request Review

A plain @token string in a selector or theme still throws when it's
defined, so the docs and changeset now say which references validate()
reports. The default z-index output blocks list the tooltip level, and a
namespace fallback whose variable was defined later says so instead of
claiming no variable exists.
@alexgrozav alexgrozav self-assigned this Oct 21, 2026
@alexgrozav
alexgrozav marked this pull request as ready for review October 21, 2026 06:48
@alexgrozav
alexgrozav merged commit 23efb06 into main Oct 21, 2026
14 checks passed
@alexgrozav
alexgrozav deleted the report-unresolved-references-uxf-410 branch October 21, 2026 06:55
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026

This branch was successfully deployed

2 active deployments
Preview – styleframe-dev — 13c6d781 Deployed Oct 21, 2026 by vercel[bot]
Preview – styleframe-dev-storybook — 13c6d781 Deployed Oct 21, 2026 by vercel[bot]
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