@@ -649,16 +649,49 @@ function inKeyframes(rule) {
649
649
return rule . parent && rule . parent . type === 'atrule' && rule . parent . name === 'keyframes'
650
650
}
651
651
652
+ function getImportantStrategy ( important ) {
653
+ if ( important === true ) {
654
+ return ( rule ) => {
655
+ if ( inKeyframes ( rule ) ) {
656
+ return
657
+ }
658
+
659
+ rule . walkDecls ( ( d ) => {
660
+ if ( d . parent . type === 'rule' && ! inKeyframes ( d . parent ) ) {
661
+ d . important = true
662
+ }
663
+ } )
664
+ }
665
+ }
666
+
667
+ if ( typeof important === 'string' ) {
668
+ return ( rule ) => {
669
+ if ( inKeyframes ( rule ) ) {
670
+ return
671
+ }
672
+
673
+ rule . selectors = rule . selectors . map ( ( selector ) => {
674
+ return `${ important } ${ selector } `
675
+ } )
676
+ }
677
+ }
678
+ }
679
+
652
680
function generateRules ( candidates , context ) {
653
681
let allRules = [ ]
682
+ let strategy = getImportantStrategy ( context . tailwindConfig . important )
654
683
655
684
for ( let candidate of candidates ) {
656
685
if ( context . notClassCache . has ( candidate ) ) {
657
686
continue
658
687
}
659
688
660
689
if ( context . classCache . has ( candidate ) ) {
661
- allRules . push ( context . classCache . get ( candidate ) )
690
+ continue
691
+ }
692
+
693
+ if ( context . candidateRuleCache . has ( candidate ) ) {
694
+ allRules = allRules . concat ( Array . from ( context . candidateRuleCache . get ( candidate ) ) )
662
695
continue
663
696
}
664
697
@@ -670,47 +703,27 @@ function generateRules(candidates, context) {
670
703
}
671
704
672
705
context . classCache . set ( candidate , matches )
673
- allRules . push ( matches )
674
- }
675
706
676
- // Strategy based on `tailwindConfig.important`
677
- let strategy = ( ( important ) => {
678
- if ( important === true ) {
679
- return ( rule ) => {
680
- rule . walkDecls ( ( d ) => {
681
- if ( d . parent . type === 'rule' && ! inKeyframes ( d . parent ) ) {
682
- d . important = true
683
- }
684
- } )
685
- }
686
- }
707
+ let rules = context . candidateRuleCache . get ( candidate ) ?? new Set ( )
708
+ context . candidateRuleCache . set ( candidate , rules )
687
709
688
- if ( typeof important === 'string' ) {
689
- return ( rule ) => {
690
- rule . selectors = rule . selectors . map ( ( selector ) => {
691
- return `${ important } ${ selector } `
692
- } )
693
- }
694
- }
695
- } ) ( context . tailwindConfig . important )
710
+ for ( const match of matches ) {
711
+ let [ { sort, layer, options } , rule ] = match
696
712
697
- return allRules . flat ( 1 ) . map ( ( [ { sort, layer, options } , rule ] ) => {
698
- if ( options . respectImportant ) {
699
- if ( strategy ) {
713
+ if ( options . respectImportant && strategy ) {
700
714
let container = postcss . root ( { nodes : [ rule . clone ( ) ] } )
701
- container . walkRules ( ( r ) => {
702
- if ( inKeyframes ( r ) ) {
703
- return
704
- }
705
-
706
- strategy ( r )
707
- } )
715
+ container . walkRules ( strategy )
708
716
rule = container . nodes [ 0 ]
709
717
}
718
+
719
+ let newEntry = [ sort | context . layerOrder [ layer ] , rule ]
720
+ rules . add ( newEntry )
721
+ context . ruleCache . add ( newEntry )
722
+ allRules . push ( newEntry )
710
723
}
724
+ }
711
725
712
- return [ sort | context . layerOrder [ layer ] , rule ]
713
- } )
726
+ return allRules
714
727
}
715
728
716
729
function isArbitraryValue ( input ) {
0 commit comments