-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
26 lines (24 loc) · 968 Bytes
/
index.js
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
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-parent-selector', function (opts) {
opts = opts || {};
// Work with options here
return function (root /* , result*/ ) {
root.walkRules(rule => {
if (rule.parent && rule.parent.type === 'atrule' &&
rule.parent.name.indexOf('keyframes') !== -1) {
return;
}
rule.selectors = rule.selectors.map(selectors => {
return selectors.split(/,[\s]* /g).map( selector => {
// don't add the parent class to a rule that is
// exactly equal to the one defined by the user
if ( selector === opts.selector ) {
return selector;
}
var newsSelector = `${opts.selector} ${selector}`;
return newsSelector;
});
});
});
};
});