Skip to content

Commit a9d1646

Browse files
committed
refactor: move syntax related utils to a separate module
1 parent e32b16f commit a9d1646

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/Syntax.js

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ export function isComponent(node) {
1313
node.parent.type === 'root'
1414
);
1515
}
16+
17+
export function isVariant(node) {
18+
return (
19+
node.type === 'rule' &&
20+
node.selector.charAt(0) === ':'
21+
);
22+
}

src/transformVariants.js

+4-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @flow
44
*/
55

6+
import * as Syntax from './Syntax';
7+
68
/**
79
* Variant names we want to see compiled as CSS pseudo classes.
810
*/
@@ -36,7 +38,7 @@ const _SUPPORTED_PSEUDO_CLASSES = {
3638
export default function transformVariants(root) {
3739
let toAppend = [];
3840
root.each(rule => {
39-
if (isComponent(rule)) {
41+
if (Syntax.isComponent(rule)) {
4042
toAppend = toAppend.concat(flattenVariants(rule));
4143
}
4244
});
@@ -48,7 +50,7 @@ function flattenVariants(rule) {
4850
let toRemove = [];
4951
let toAppend = [];
5052
rule.each(variant => {
51-
if (!isVariant(variant)) {
53+
if (!Syntax.isVariant(variant)) {
5254
return;
5355
}
5456
toRemove.push(variant);
@@ -59,19 +61,3 @@ function flattenVariants(rule) {
5961
toRemove.forEach(variant => variant.remove());
6062
return toAppend;
6163
}
62-
63-
export function isVariant(node) {
64-
return (
65-
node.type === 'rule' &&
66-
node.selector.charAt(0) === ':'
67-
);
68-
}
69-
70-
export function isComponent(node) {
71-
return (
72-
node.type === 'rule' &&
73-
node.selector.charAt(0) !== ':' &&
74-
node.parent &&
75-
node.parent.type === 'root'
76-
);
77-
}

0 commit comments

Comments
 (0)