-
Notifications
You must be signed in to change notification settings - Fork 124
/
references.js
51 lines (44 loc) · 936 Bytes
/
references.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
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Provide property reference support.
*
* button {
* width: 50px;
* height: @width;
* line-height: @height;
* }
*
* yields:
*
* button {
* width: 50px;
* height: 50px;
* line-height: 50px;
* }
*
*/
module.exports = function() {
return function(style, rework){
style.rules.forEach(function(rule){
if (!rule.declarations) return;
substitute(rule.declarations);
});
}
};
/**
* Substitute easing functions.
*
* @api private
*/
function substitute(declarations) {
var map = {};
for (var i = 0, len = declarations.length; i < len; ++i) {
var decl = declarations[i];
var key = decl.property;
var val = decl.value;
decl.value = val.replace(/@(\w+)/g, function(_, name){
if (null == map[name]) throw new Error('@' + name + ' is not defined in this scope');
return map[name];
});
map[key] = decl.value;
}
}