-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
49 lines (32 loc) · 952 Bytes
/
parser.js
File metadata and controls
49 lines (32 loc) · 952 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
module.exports = parser
var forEach = require('lodash.foreach')
function parser(str, cb) {
var css = require('css')
var data = require('./data/chromium')
var parsed = css.parse(str)
if ( parsed.stylesheet && !parsed.stylesheet.rules.length ) return
findTriggers(parsed.stylesheet, data, cb)
}
function findTriggers(tree, data, cb) {
var props = []
forEach(tree.rules, function(rule) {
findProperty(rule, data, props)
})
cb(props)
}
function findProperty(rule, data, props) {
forEach(rule.declarations, function(declarations) {
var propName = declarations.property + "-initial"
if ( data[propName] ) {
props.push([
declarations.property,
declarations.position.start.line,
data[propName].layout,
data[propName].paint,
data[propName].composite,
"Chromium" // for now it's hard-coded because there's no other data :(
])
}
})
return props
}