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
31 lines (27 loc) · 869 Bytes
/
getNodeScopes.ts
File metadata and controls
31 lines (27 loc) · 869 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
import type {AnyNode} from "postcss";
import { getSelectorScope } from "./getSelectorScope";
export function getNodeScopes(node: AnyNode): Set<string> {
const nodeScopes = new Set();
if (
node.type === "rule" &&
(node.parent && (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;
}