@@ -6,6 +6,7 @@ import { getClassOrder } from './sort'
66import type { Theme , ThemeKey } from './theme'
77import { Utilities , createUtilities , withAlpha } from './utilities'
88import { DefaultMap } from './utils/default-map'
9+ import * as ValueParser from './value-parser'
910import { Variants , createVariants } from './variants'
1011
1112export type DesignSystem = {
@@ -29,6 +30,8 @@ export type DesignSystem = {
2930 getVariantOrder ( ) : Map < Variant , number >
3031 resolveThemeValue ( path : string ) : string | undefined
3132
33+ trackUsedVariables ( raw : string ) : void
34+
3235 // Used by IntelliSense
3336 candidatesToCss ( classes : string [ ] ) : ( string | null ) [ ]
3437}
@@ -44,6 +47,21 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
4447 let compiledAstNodes = new DefaultMap < Candidate > ( ( candidate ) =>
4548 compileAstNodes ( candidate , designSystem ) ,
4649 )
50+ let trackUsedVariables = new DefaultMap ( ( raw ) => {
51+ ValueParser . walk ( ValueParser . parse ( raw ) , ( node ) => {
52+ if ( node . kind !== 'function' || node . value !== 'var' ) return
53+
54+ ValueParser . walk ( node . nodes , ( child ) => {
55+ if ( child . kind !== 'word' || child . value [ 0 ] !== '-' || child . value [ 1 ] !== '-' ) return
56+
57+ theme . markUsedVariable ( child . value )
58+ } )
59+
60+ return ValueParser . ValueWalkAction . Skip
61+ } )
62+
63+ return true
64+ } )
4765
4866 let designSystem : DesignSystem = {
4967 theme,
@@ -140,6 +158,10 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
140158
141159 return themeValue
142160 } ,
161+
162+ trackUsedVariables ( raw : string ) {
163+ trackUsedVariables . get ( raw )
164+ } ,
143165 }
144166
145167 return designSystem
0 commit comments