(
node: AstNode,
parent: AstNode[],
context: Record<string, string | boolean> = {},
depth = 0,
)
| 237 | let variableDependencies = new DefaultMap<string, Set<string>>(() => new Set()) |
| 238 | |
| 239 | function transform( |
| 240 | node: AstNode, |
| 241 | parent: AstNode[], |
| 242 | context: Record<string, string | boolean> = {}, |
| 243 | depth = 0, |
| 244 | ) { |
| 245 | // Declaration |
| 246 | if (node.kind === 'declaration') { |
| 247 | if (node.property === '--tw-sort' || node.value === undefined || node.value === null) { |
| 248 | return |
| 249 | } |
| 250 | |
| 251 | // Track variables defined in `@theme` |
| 252 | if (context.theme && node.property[0] === '-' && node.property[1] === '-') { |
| 253 | // Variables that resolve to `initial` should never be emitted. This can happen because of |
| 254 | // the `--theme(…)` being used and evaluated lazily |
| 255 | if (node.value === 'initial') { |
| 256 | node.value = undefined |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | if (!context.keyframes) { |
| 261 | cssThemeVariables.get(parent).add(node) |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // Track used CSS variables |
| 266 | if (node.value.includes('var(')) { |
| 267 | // Declaring another variable does not count as usage. Instead, we mark |
| 268 | // the relationship |
| 269 | if (context.theme && node.property[0] === '-' && node.property[1] === '-') { |
| 270 | for (let variable of extractUsedVariables(node.value)) { |
| 271 | variableDependencies.get(variable).add(node.property) |
| 272 | } |
| 273 | } else { |
| 274 | designSystem.trackUsedVariables(node.value) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Track used animation names |
| 279 | if (node.property === 'animation') { |
| 280 | for (let keyframeName of extractKeyframeNames(node.value)) { |
| 281 | usedKeyframeNames.add(keyframeName) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // Create fallback values for usages of the `color-mix(…)` function that reference variables |
| 286 | // found in the theme config. |
| 287 | if ( |
| 288 | polyfills & Polyfills.ColorMix && |
| 289 | node.value.includes('color-mix(') && |
| 290 | !context.supportsColorMix && |
| 291 | !context.keyframes |
| 292 | ) { |
| 293 | colorMixDeclarations.get(parent).add(node) |
| 294 | } |
| 295 | |
| 296 | parent.push(node) |
no test coverage detected