@@ -7,6 +7,7 @@ import { getClassOrder } from './sort'
77import type { Theme , ThemeKey } from './theme'
88import { Utilities , createUtilities , withAlpha } from './utilities'
99import { DefaultMap } from './utils/default-map'
10+ import * as ValueParser from './value-parser'
1011import { Variants , createVariants } from './variants'
1112
1213export type DesignSystem = {
@@ -30,6 +31,8 @@ export type DesignSystem = {
3031 getVariantOrder ( ) : Map < Variant , number >
3132 resolveThemeValue ( path : string ) : string | undefined
3233
34+ trackUsedVariables ( raw : string ) : void
35+
3336 // Used by IntelliSense
3437 candidatesToCss ( classes : string [ ] ) : ( string | null ) [ ]
3538}
@@ -42,6 +45,7 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
4245 let parsedCandidates = new DefaultMap ( ( candidate ) =>
4346 Array . from ( parseCandidate ( candidate , designSystem ) ) ,
4447 )
48+
4549 let compiledAstNodes = new DefaultMap < Candidate > ( ( candidate ) => {
4650 let ast = compileAstNodes ( candidate , designSystem )
4751
@@ -64,6 +68,22 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
6468 return ast
6569 } )
6670
71+ let trackUsedVariables = new DefaultMap ( ( raw ) => {
72+ ValueParser . walk ( ValueParser . parse ( raw ) , ( node ) => {
73+ if ( node . kind !== 'function' || node . value !== 'var' ) return
74+
75+ ValueParser . walk ( node . nodes , ( child ) => {
76+ if ( child . kind !== 'word' || child . value [ 0 ] !== '-' || child . value [ 1 ] !== '-' ) return
77+
78+ theme . markUsedVariable ( child . value )
79+ } )
80+
81+ return ValueParser . ValueWalkAction . Skip
82+ } )
83+
84+ return true
85+ } )
86+
6787 let designSystem : DesignSystem = {
6888 theme,
6989 utilities,
@@ -159,6 +179,10 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
159179
160180 return themeValue
161181 } ,
182+
183+ trackUsedVariables ( raw : string ) {
184+ trackUsedVariables . get ( raw )
185+ } ,
162186 }
163187
164188 return designSystem
0 commit comments