-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
22 lines (22 loc) · 796 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
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-current-selector', function (opts) {
if (!opts) opts = {};
opts.symbol = opts.symbol || '%@';
return function (css) {
function processNode(parent) {
parent.walk(function (node) {
if (node.type === 'atrule') {
processNode(node);
} else if (node.type === 'rule') {
processNode(node);
} else if (node.type === 'decl') {
if (node.value.indexOf(opts.symbol) !== -1) {
node.value =
node.value.replace(opts.symbol, parent.selector);
}
}
});
}
processNode(css);
};
});