@@ -7,6 +7,7 @@ import { getClassOrder } from './sort'
7
7
import type { Theme , ThemeKey } from './theme'
8
8
import { Utilities , createUtilities , withAlpha } from './utilities'
9
9
import { DefaultMap } from './utils/default-map'
10
+ import * as ValueParser from './value-parser'
10
11
import { Variants , createVariants } from './variants'
11
12
12
13
export type DesignSystem = {
@@ -30,6 +31,8 @@ export type DesignSystem = {
30
31
getVariantOrder ( ) : Map < Variant , number >
31
32
resolveThemeValue ( path : string ) : string | undefined
32
33
34
+ trackUsedVariables ( raw : string ) : void
35
+
33
36
// Used by IntelliSense
34
37
candidatesToCss ( classes : string [ ] ) : ( string | null ) [ ]
35
38
}
@@ -42,6 +45,7 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
42
45
let parsedCandidates = new DefaultMap ( ( candidate ) =>
43
46
Array . from ( parseCandidate ( candidate , designSystem ) ) ,
44
47
)
48
+
45
49
let compiledAstNodes = new DefaultMap < Candidate > ( ( candidate ) => {
46
50
let ast = compileAstNodes ( candidate , designSystem )
47
51
@@ -64,6 +68,22 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
64
68
return ast
65
69
} )
66
70
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
+
67
87
let designSystem : DesignSystem = {
68
88
theme,
69
89
utilities,
@@ -159,6 +179,10 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
159
179
160
180
return themeValue
161
181
} ,
182
+
183
+ trackUsedVariables ( raw : string ) {
184
+ trackUsedVariables . get ( raw )
185
+ } ,
162
186
}
163
187
164
188
return designSystem
0 commit comments