Skip to content

fix: don't collect filtered reference warnings in sortByReference - #1763

Merged
jorenbroekema merged 1 commit into
style-dictionary:mainfrom
SahinurDEV:fix/output-references-filter-warning
Oct 9, 2026
Merged

jorenbroekema merged 1 commit into
style-dictionary:mainfrom
SahinurDEV:fix/output-references-filter-warning

Conversation

@SahinurDEV

Copy link
Copy Markdown
Contributor

Problem

When you combine a filter with outputReferences: outputReferencesFilter, Style Dictionary can still print "filtered out token references were found", even though the output has no references and every value is resolved (#1379). This happens when the filtered-out tokens reference other tokens (multiple levels of references). With only one token, the warning goes away.

Minimal repro:

tokens: {
  base:     { red: { value: '#f00' }, blue: { value: '#00f' } },
  mid:      { danger: { value: '{base.red}' }, info: { value: '{base.blue}' } },
  semantic: { error: { value: '{mid.danger}' }, notice: { value: '{mid.info}' } },
},
// file: filter: (t) => t.path[0] === 'semantic', options: { outputReferences: outputReferencesFilter }

The output is --semantic-error: #ff0000; --semantic-notice: #0000ff;, but the build still logs the warning for base.red / base.blue.

Cause

When outputReferences is set, formats sort tokens with sortByReference(tokens, { unfilteredTokens }). The sorter called getReferences(value, tokens, { unfilteredTokens, warnImmediately: false }), and that call adds a FilteredOutputReferences message for every reference missing from the filtered set. When two tokens reference other tokens but not each other, the sorter recurses into the referenced tokens (sorter(aRefs[0], bRefs[0])). Those tokens can be filtered out, so it also recorded their references (here base.red, base.blue). Those tokens are never output, so outputReferencesFilter never runs for them and can't remove the warnings.

Fix

Sorting only needs to resolve references. It doesn't need to report them. sortByReference now looks references up in unfilteredTokens ?? tokens directly, without the unfilteredTokens option, so it no longer adds filter warnings. Filtered references that really end up in the output are still reported by createPropertyFormatter. Without unfilteredTokens, behavior is unchanged.

One side effect: the verbose warning now lists references in output order. It used to list them in sort-comparison order (neutral.0 now comes before neutral.100), so I updated three snapshots for that. The set of references is the same.

Tests

  • sortByReference.test.js: sorting with unfilteredTokens and multi-level references collects no filter warnings, and still sorts correctly through references that resolve to filtered-out tokens.
  • __integration__/outputReferences.test.js: building the repro above with outputReferencesFilter logs no filtered-reference warning.
  • The new tests fail without the fix (4 failing) and pass with it.
  • npm run test:node: 998 passing, 4 pending. npm run lint (eslint, prettier, tsc) passes.
  • Added a patch changeset.

AI disclosure: I used an AI coding assistant to investigate this issue and draft the fix and tests. I reproduced the bug and checked the change and test results locally.

Fixes #1379

sortByReference passed the unfiltered tokens to getReferences as
`unfilteredTokens`, which records a "filtered out token references"
warning for every reference that isn't in the filtered set. Because the
sorter recurses into referenced tokens, this also recorded references of
tokens that are never output, and outputReferencesFilter could not
remove them, so the warning showed up even though no references were
output.

Resolve references against the unfiltered tokens directly instead; the
formatters still report filtered references they actually output.

Fixes #1379
@changeset-bot

changeset-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 23b268b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
style-dictionary Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for styledictionaryjs ready!

Name Link
🔨 Latest commit 23b268b
🔍 Latest deploy log https://app.netlify.com/projects/styledictionaryjs/deploys/6ac773cf81fc380008565d9a
😎 Deploy Preview https://deploy-preview-1763--styledictionaryjs.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.

@SahinurDEV
SahinurDEV marked this pull request as draft October 8, 2026 10:57

@jorenbroekema jorenbroekema left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's a pretty smart fix: sort on the filtered set, but grab the references from the unfiltered set, circumventing the warnings collection. After all, these warnings will be collected later anyways.
Thanks for the AI disclaimer, appreciate that.

@jorenbroekema
jorenbroekema marked this pull request as ready for review October 9, 2026 10:36
@jorenbroekema
jorenbroekema merged commit 7a80396 into style-dictionary:main Oct 9, 2026
9 checks passed
@SahinurDEV

Copy link
Copy Markdown
Contributor Author

Thanks a lot @jorenbroekema for the quick review and the kind words! Glad the fix fits well. Happy to help with more issues here.

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.

"filtered out token references were found" warning is reported while values are beign resolved in the output file.

2 participants