(
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 | class="cm">// Declaration |
| 246 | if (node.kind === class="st">'declaration') { |
| 247 | if (node.property === class="st">'--tw-sort' || node.value === undefined || node.value === null) { |
| 248 | return |
| 249 | } |
| 250 | |
| 251 | class="cm">// Track variables defined in `@theme` |
| 252 | if (context.theme && node.property[0] === class="st">'-' && node.property[1] === class="st">'-') { |
| 253 | class="cm">// Variables that resolve to `initial` should never be emitted. This can happen because of |
| 254 | class="cm">// the `--theme(…)` being used and evaluated lazily |
| 255 | if (node.value === class="st">'initial') { |
| 256 | node.value = undefined |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | if (!context.keyframes) { |
| 261 | cssThemeVariables.get(parent).add(node) |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | class="cm">// Track used CSS variables |
| 266 | if (node.value.includes(class="st">'var(')) { |
| 267 | class="cm">// Declaring another variable does not count as usage. Instead, we mark |
| 268 | class="cm">// the relationship |
| 269 | if (context.theme && node.property[0] === class="st">'-' && node.property[1] === class="st">'-') { |
| 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 | class="cm">// Track used animation names |
| 279 | if (node.property === class="st">'animation') { |
| 280 | for (let keyframeName of extractKeyframeNames(node.value)) { |
| 281 | usedKeyframeNames.add(keyframeName) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | class="cm">// Create fallback values for usages of the `color-mix(…)` function that reference variables |
| 286 | class="cm">// found in the theme config. |
| 287 | if ( |
| 288 | polyfills & Polyfills.ColorMix && |
| 289 | node.value.includes(class="st">'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