Skip to content

Commit f9c665a

Browse files
S@lazarzignd
S@lazar
authored andcommitted
add autocompletion from media queries class
Signed-off-by: Zignd <zignd.igor@gmail.com>
1 parent 518c5d8 commit f9c665a

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/parse-engines/common/css-class-extractor.ts

+20-12
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@ export default class CssClassExtractor {
1010

1111
const definitions: CssClassDefinition[] = [];
1212

13-
// go through each of the rules...
14-
ast.stylesheet.rules.forEach((rule: css.Rule) => {
13+
// go through each of the selectors of the current rule
14+
const addRule = (rule: css.Rule) => {
15+
rule.selectors.forEach((selector: string) => {
16+
let item: RegExpExecArray = classNameRegex.exec(selector);
17+
while (item) {
18+
definitions.push(new CssClassDefinition(item[1]));
19+
item = classNameRegex.exec(selector);
20+
}
21+
});
22+
};
23+
24+
// go through each of the rules or media query...
25+
ast.stylesheet.rules.forEach((rule: css.Rule & css.Media) => {
1526
// ...of type rule
1627
if (rule.type === "rule") {
17-
// go through each of the selectors of the current rule
18-
rule.selectors.forEach((selector: string) => {
19-
let item: RegExpExecArray = classNameRegex.exec(selector);
20-
while (item) {
21-
definitions.push(new CssClassDefinition(item[1]));
22-
item = classNameRegex.exec(selector);
23-
}
24-
});
28+
addRule(rule);
29+
}
30+
// of type media queries
31+
if (rule.type === "media") {
32+
// go through rules inside media queries
33+
rule.rules.forEach((rule: css.Rule) => addRule(rule));
2534
}
2635
});
27-
2836
return definitions;
2937
}
30-
}
38+
}

0 commit comments

Comments
 (0)