File tree 1 file changed +20
-12
lines changed
1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -10,21 +10,29 @@ export default class CssClassExtractor {
10
10
11
11
const definitions : CssClassDefinition [ ] = [ ] ;
12
12
13
- // go through each of the rules...
14
- ast . stylesheet . rules . forEach ( ( rule : css . Rule ) => {
13
+ // go through each of the selectors of the current rule
14
+ const addRule = ( rule : css . Rule ) => {
15
+ rule . selectors . forEach ( ( selector : string ) => {
16
+ let item : RegExpExecArray = classNameRegex . exec ( selector ) ;
17
+ while ( item ) {
18
+ definitions . push ( new CssClassDefinition ( item [ 1 ] ) ) ;
19
+ item = classNameRegex . exec ( selector ) ;
20
+ }
21
+ } ) ;
22
+ } ;
23
+
24
+ // go through each of the rules or media query...
25
+ ast . stylesheet . rules . forEach ( ( rule : css . Rule & css . Media ) => {
15
26
// ...of type rule
16
27
if ( rule . type === "rule" ) {
17
- // go through each of the selectors of the current rule
18
- rule . selectors . forEach ( ( selector : string ) => {
19
- let item : RegExpExecArray = classNameRegex . exec ( selector ) ;
20
- while ( item ) {
21
- definitions . push ( new CssClassDefinition ( item [ 1 ] ) ) ;
22
- item = classNameRegex . exec ( selector ) ;
23
- }
24
- } ) ;
28
+ addRule ( rule ) ;
29
+ }
30
+ // of type media queries
31
+ if ( rule . type === "media" ) {
32
+ // go through rules inside media queries
33
+ rule . rules . forEach ( ( rule : css . Rule ) => addRule ( rule ) ) ;
25
34
}
26
35
} ) ;
27
-
28
36
return definitions ;
29
37
}
30
- }
38
+ }
You can’t perform that action at this time.
0 commit comments