forked from brikou/CSS-in-JS-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetNodeScopes.ts
More file actions
32 lines (27 loc) · 860 Bytes
/
getNodeScopes.ts
File metadata and controls
32 lines (27 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type {Node} from "postcss";
import { getSelectorScope } from "./getSelectorScope";
export function getNodeScopes(node: Node): Set<string> {
const nodeScopes: Set<string> = new Set();
if (
node.type === "rule" &&
(node.parent.type !== "atrule" ||
/keyframes/.test(node.parent.name) === false)
) {
(node.selectors || []).forEach((selector) => {
nodeScopes.add(getSelectorScope(selector));
});
} else if (
node.type === "atrule" &&
/keyframes$/.test(node.name) === false
) {
node.walkRules((rule) => {
(rule.selectors || []).forEach((selector) => {
nodeScopes.add(getSelectorScope(selector));
});
});
}
if (nodeScopes.size === 0) {
nodeScopes.add("root");
}
return nodeScopes;
}