@@ -24,6 +24,7 @@ import { Utilities, createUtilities, withAlpha } from './utilities'
2424import { DefaultMap } from './utils/default-map'
2525import { extractUsedVariables } from './utils/variables'
2626import { Variants , createVariants , substituteAtVariant } from './variants'
27+ import { WalkAction , walk } from './walk'
2728
2829export const enum CompileAstFlags {
2930 None = 0 ,
@@ -65,7 +66,7 @@ export type DesignSystem = {
6566 storage : Record < symbol , unknown >
6667}
6768
68- export function buildDesignSystem ( theme : Theme ) : DesignSystem {
69+ export function buildDesignSystem ( theme : Theme , utilitiesNode ?: AstNode | null ) : DesignSystem {
6970 let utilities = createUtilities ( theme )
7071 let variants = createVariants ( theme )
7172
@@ -122,6 +123,17 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
122123 } ,
123124 } )
124125
126+ if ( utilitiesNode ) {
127+ walk ( astNodes , ( node ) => {
128+ // We do this conditionally to preserve source locations from both
129+ // `@utility` and `@custom-variant`. Even though generated nodes are
130+ // cached this should be fine because `utilitiesNode.src` should not
131+ // change without a full rebuild which destroys the cache.
132+ node . src ??= utilitiesNode . src
133+ return WalkAction . Continue
134+ } )
135+ }
136+
125137 // Disable all polyfills to not unnecessarily pollute IntelliSense output
126138 astNodes = optimizeAst ( astNodes , designSystem , Polyfills . None )
127139
0 commit comments