|
1 | 1 | import { parseAtRule } from './css-parser'
|
2 | 2 | import type { DesignSystem } from './design-system'
|
3 |
| -import { enableRemoveUnusedThemeVariables } from './feature-flags' |
4 | 3 | import { Theme, ThemeOptions } from './theme'
|
5 | 4 | import { DefaultMap } from './utils/default-map'
|
6 | 5 | import { extractUsedVariables } from './utils/variables'
|
@@ -435,62 +434,60 @@ export function optimizeAst(
|
435 | 434 | for (let node of ast) {
|
436 | 435 | transform(node, newAst, {}, 0)
|
437 | 436 | }
|
438 |
| - // Remove unused theme variables |
439 |
| - if (enableRemoveUnusedThemeVariables) { |
440 |
| - // Remove unused theme variables |
441 |
| - next: for (let [parent, declarations] of cssThemeVariables) { |
442 |
| - for (let declaration of declarations) { |
443 |
| - // Find out if a variable is either used directly or if any of the |
444 |
| - // variables referencing it is used. |
445 |
| - let variableUsed = isVariableUsed( |
446 |
| - declaration.property, |
447 |
| - designSystem.theme, |
448 |
| - variableDependencies, |
449 |
| - ) |
450 |
| - if (variableUsed) { |
451 |
| - if (declaration.property.startsWith('--animate-')) { |
452 |
| - let parts = declaration.value!.split(/\s+/) |
453 |
| - for (let part of parts) usedKeyframeNames.add(part) |
454 |
| - } |
455 | 437 |
|
456 |
| - continue |
| 438 | + // Remove unused theme variables |
| 439 | + next: for (let [parent, declarations] of cssThemeVariables) { |
| 440 | + for (let declaration of declarations) { |
| 441 | + // Find out if a variable is either used directly or if any of the |
| 442 | + // variables referencing it is used. |
| 443 | + let variableUsed = isVariableUsed( |
| 444 | + declaration.property, |
| 445 | + designSystem.theme, |
| 446 | + variableDependencies, |
| 447 | + ) |
| 448 | + if (variableUsed) { |
| 449 | + if (declaration.property.startsWith('--animate-')) { |
| 450 | + let parts = declaration.value!.split(/\s+/) |
| 451 | + for (let part of parts) usedKeyframeNames.add(part) |
457 | 452 | }
|
458 | 453 |
|
459 |
| - // Remove the declaration (from its parent) |
460 |
| - let idx = parent.indexOf(declaration) |
461 |
| - parent.splice(idx, 1) |
| 454 | + continue |
| 455 | + } |
462 | 456 |
|
463 |
| - // If the parent is now empty, remove it and any `@layer` rules above it |
464 |
| - // from the AST |
465 |
| - if (parent.length === 0) { |
466 |
| - let path = findNode(newAst, (node) => node.kind === 'rule' && node.nodes === parent) |
| 457 | + // Remove the declaration (from its parent) |
| 458 | + let idx = parent.indexOf(declaration) |
| 459 | + parent.splice(idx, 1) |
467 | 460 |
|
468 |
| - if (!path || path.length === 0) continue next |
| 461 | + // If the parent is now empty, remove it and any `@layer` rules above it |
| 462 | + // from the AST |
| 463 | + if (parent.length === 0) { |
| 464 | + let path = findNode(newAst, (node) => node.kind === 'rule' && node.nodes === parent) |
469 | 465 |
|
470 |
| - // Add the root of the AST so we can delete from the top-level |
471 |
| - path.unshift({ |
472 |
| - kind: 'at-root', |
473 |
| - nodes: newAst, |
474 |
| - }) |
| 466 | + if (!path || path.length === 0) continue next |
475 | 467 |
|
476 |
| - // Remove nodes from the parent as long as the parent is empty |
477 |
| - // otherwise and consist of only @layer rules |
478 |
| - do { |
479 |
| - let nodeToRemove = path.pop() |
480 |
| - if (!nodeToRemove) break |
| 468 | + // Add the root of the AST so we can delete from the top-level |
| 469 | + path.unshift({ |
| 470 | + kind: 'at-root', |
| 471 | + nodes: newAst, |
| 472 | + }) |
481 | 473 |
|
482 |
| - let removeFrom = path[path.length - 1] |
483 |
| - if (!removeFrom) break |
484 |
| - if (removeFrom.kind !== 'at-root' && removeFrom.kind !== 'at-rule') break |
| 474 | + // Remove nodes from the parent as long as the parent is empty |
| 475 | + // otherwise and consist of only @layer rules |
| 476 | + do { |
| 477 | + let nodeToRemove = path.pop() |
| 478 | + if (!nodeToRemove) break |
485 | 479 |
|
486 |
| - let idx = removeFrom.nodes.indexOf(nodeToRemove) |
487 |
| - if (idx === -1) break |
| 480 | + let removeFrom = path[path.length - 1] |
| 481 | + if (!removeFrom) break |
| 482 | + if (removeFrom.kind !== 'at-root' && removeFrom.kind !== 'at-rule') break |
488 | 483 |
|
489 |
| - removeFrom.nodes.splice(idx, 1) |
490 |
| - } while (true) |
| 484 | + let idx = removeFrom.nodes.indexOf(nodeToRemove) |
| 485 | + if (idx === -1) break |
491 | 486 |
|
492 |
| - continue next |
493 |
| - } |
| 487 | + removeFrom.nodes.splice(idx, 1) |
| 488 | + } while (true) |
| 489 | + |
| 490 | + continue next |
494 | 491 | }
|
495 | 492 | }
|
496 | 493 |
|
|
0 commit comments