1- import { getRulesByBreakpoint } from "./breakpoints" ;
21import memoize from "memoizee" ;
3- import { objectKeys } from "tsafe/objectKeys" ;
2+ import { parseCss } from "../parseCss" ;
3+ import { assert } from "tsafe/assert" ;
4+ import { typeGuard } from "tsafe/typeGuard" ;
45
56export const parseClassNames = memoize ( ( rawCssCode : string ) : string [ ] => {
6- const rulesByBreakpoint = getRulesByBreakpoint ( rawCssCode ) ;
7+ const parsedCss = parseCss ( rawCssCode ) ;
78
89 const classNames = new Set < string > ( ) ;
910
10- objectKeys ( rulesByBreakpoint ) . forEach ( breakpoint => {
11- const rules = rulesByBreakpoint [ breakpoint ] ;
12- rules . forEach ( ( { selectors } ) => {
11+ JSON . stringify ( parsedCss , ( key , value ) => {
12+ if ( key === "selectors" ) {
13+ const selectors = value as unknown ;
14+
15+ assert (
16+ typeGuard < string [ ] > (
17+ selectors ,
18+ selectors instanceof Array &&
19+ selectors . every ( selector => typeof selector === "string" )
20+ )
21+ ) ;
22+
1323 selectors . forEach ( selector => {
1424 const matchArr = selector . match ( / \. f r - [ a - z A - Z 0 - 9 _ - ] + (?: @ [ a - z A - Z 0 - 9 _ - ] + ) ? / g) ;
1525 if ( matchArr === null ) {
@@ -20,8 +30,10 @@ export const parseClassNames = memoize((rawCssCode: string): string[] => {
2030 . map ( matchedStr => matchedStr . replace ( / ^ \. / , "" ) )
2131 . forEach ( className => classNames . add ( className ) ) ;
2232 } ) ;
23- } ) ;
33+ }
34+ return value ;
2435 } ) ;
36+
2537 return Array . from ( classNames ) ;
2638} ) ;
2739
0 commit comments