@@ -6,6 +6,7 @@ import { getClassOrder } from './sort'
6
6
import type { Theme , ThemeKey } from './theme'
7
7
import { Utilities , createUtilities , withAlpha } from './utilities'
8
8
import { DefaultMap } from './utils/default-map'
9
+ import * as ValueParser from './value-parser'
9
10
import { Variants , createVariants } from './variants'
10
11
11
12
export type DesignSystem = {
@@ -29,6 +30,8 @@ export type DesignSystem = {
29
30
getVariantOrder ( ) : Map < Variant , number >
30
31
resolveThemeValue ( path : string ) : string | undefined
31
32
33
+ trackUsedVariables ( raw : string ) : void
34
+
32
35
// Used by IntelliSense
33
36
candidatesToCss ( classes : string [ ] ) : ( string | null ) [ ]
34
37
}
@@ -44,6 +47,21 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
44
47
let compiledAstNodes = new DefaultMap < Candidate > ( ( candidate ) =>
45
48
compileAstNodes ( candidate , designSystem ) ,
46
49
)
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
+ } )
47
65
48
66
let designSystem : DesignSystem = {
49
67
theme,
@@ -140,6 +158,10 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
140
158
141
159
return themeValue
142
160
} ,
161
+
162
+ trackUsedVariables ( raw : string ) {
163
+ trackUsedVariables . get ( raw )
164
+ } ,
143
165
}
144
166
145
167
return designSystem
0 commit comments