@@ -5,7 +5,7 @@ export function sortCompoundSelectorsInsideComplexSelector(node) {
5
5
return ;
6
6
}
7
7
8
- const compoundSelectors = [ ] ;
8
+ const compoundSelectors : Array < Array < parser . Node > > = [ ] ;
9
9
let currentCompoundSelector = [ ] ;
10
10
for ( let i = 0 ; i < node . nodes . length ; i ++ ) {
11
11
if ( node . nodes [ i ] . type === 'combinator' ) {
@@ -39,6 +39,7 @@ export function sortCompoundSelectorsInsideComplexSelector(node) {
39
39
const sortedCompoundSelectors = [ ] ;
40
40
for ( let i = 0 ; i < compoundSelectors . length ; i ++ ) {
41
41
const compoundSelector = compoundSelectors [ i ] ;
42
+
42
43
compoundSelector . sort ( ( a , b ) => {
43
44
if ( a . type === 'selector' && b . type === 'selector' && a . nodes . length && b . nodes . length ) {
44
45
return selectorTypeOrder ( a . nodes [ 0 ] , a . nodes [ 0 ] . type ) - selectorTypeOrder ( b . nodes [ 0 ] , b . nodes [ 0 ] . type ) ;
@@ -55,7 +56,20 @@ export function sortCompoundSelectorsInsideComplexSelector(node) {
55
56
return selectorTypeOrder ( a , a . type ) - selectorTypeOrder ( b , b . type ) ;
56
57
} ) ;
57
58
59
+ const compoundSelectorChildTypes = new Set ( compoundSelector . map ( x => x . type ) ) ;
60
+ const skipUniversals = compoundSelectorChildTypes . has ( 'universal' ) && (
61
+ compoundSelectorChildTypes . has ( 'tag' ) ||
62
+ compoundSelectorChildTypes . has ( 'attribute' ) ||
63
+ compoundSelectorChildTypes . has ( 'class' ) ||
64
+ compoundSelectorChildTypes . has ( 'id' ) ||
65
+ compoundSelectorChildTypes . has ( 'pseudo' ) ) ;
66
+
58
67
for ( let j = 0 ; j < compoundSelector . length ; j ++ ) {
68
+ if ( compoundSelector [ j ] . type === 'universal' && skipUniversals ) {
69
+ compoundSelector [ j ] . remove ( ) ;
70
+ continue ;
71
+ }
72
+
59
73
sortedCompoundSelectors . push ( compoundSelector [ j ] ) ;
60
74
}
61
75
}
0 commit comments