Skip to content

Commit 043b3bd

Browse files
committed
1 parent 71e0baf commit 043b3bd

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

scripts/build/cssToTs/classNames.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
import { getRulesByBreakpoint } from "./breakpoints";
21
import 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

56
export 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(/\.fr-[a-zA-Z0-9_-]+(?:@[a-zA-Z0-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

Comments
 (0)