Skip to content

Commit

Permalink
fix: validation issue when using color opacity modifier in config tok… (
Browse files Browse the repository at this point in the history
#2326)

fix: validation issue when using color opacity modifier in config tokens/semanticTokens
  • Loading branch information
astahmer authored Mar 8, 2024
1 parent 8ea91b3 commit 58388de
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .changeset/shaggy-carrots-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
'@pandacss/config': patch
---

Fix a false positive with the validation check that reported `Missing token` when using a color opacity modifier in
config `tokens` or `semanticTokens`

```ts
import { defineConfig } from '@pandacss/dev'

export default defineConfig({
validation: 'warn',
conditions: {
light: '.light &',
dark: '.dark &',
},
theme: {
tokens: {
colors: {
blue: { 500: { value: 'blue' } },
green: { 500: { value: 'green' } },
},
opacity: {
half: { value: 0.5 },
},
},
semanticTokens: {
colors: {
secondary: {
value: {
base: 'red',
_light: '{colors.blue.500/32}',
_dark: '{colors.green.500/half}',
},
},
},
},
},
})
```

Would incorrectly report:

- [tokens] Missing token: `colors.green.500/half` used in `config.semanticTokens.colors.secondary`
- [tokens] Missing token: `colors.blue.500/32` used in `config.semanticTokens.colors.secondary`
34 changes: 34 additions & 0 deletions packages/config/__tests__/validate-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,38 @@ describe('validateConfig', () => {

expect(validateConfig(config)).toMatchInlineSnapshot(`undefined`)
})

test('using color opacity modifier on known color shouldnt throw', () => {
const config: Partial<UserConfig> = {
validation: 'warn',
conditions: {
light: '.light &',
dark: '.dark &',
},
theme: {
tokens: {
colors: {
blue: { 500: { value: 'blue' } },
green: { 500: { value: 'green' } },
},
opacity: {
half: { value: 0.5 },
},
},
semanticTokens: {
colors: {
secondary: {
value: {
base: 'red',
_light: '{colors.blue.500/32}', // <-- wasn't working as expected
_dark: '{colors.green.500/half}',
},
},
},
},
},
}

expect(validateConfig(config)).toMatchInlineSnapshot(`undefined`)
})
})
6 changes: 5 additions & 1 deletion packages/config/src/validation/validate-token-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const validateTokenReferences = (
const stack = [path]

while (stack.length > 0) {
const currentPath = stack.pop()!
let currentPath = stack.pop()!
if (currentPath.includes('/')) {
const [tokenPath] = currentPath.split('/')
currentPath = tokenPath
}

const value = valueAtPath.get(currentPath)

Expand Down

0 comments on commit 58388de

Please sign in to comment.