-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (33 loc) · 1.19 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
var annotationBlock = require('css-annotation-block')
var postcss = require('postcss')
module.exports = function plugin (css, options) {
options = options || {}
var blocks = annotationBlock(css)
var constantNodes = []
blocks.forEach(function (block) {
if (block.name === "constant") {
constantNodes.push(block.nodes)
}
})
var strings = []
constantNodes.forEach(function (constantNode) {
strings.push(constantNode.toString().split(',').join('').trim())
})
return function (root) {
strings.forEach(function (string) {
var ast = postcss.parse(string)
ast.walkRules(function (rule) {
var nextRule = rule.next()
while (nextRule) {
var selArray = nextRule.selector.split(' ')
var lastName = selArray[selArray.length - 1]
if (rule.selector === nextRule.selector || rule.selector === lastName) {
throw new Error('Cannot cascade any rule sets in constant block')
}
nextRule = nextRule.next()
}
})
})
return root
}
}