-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (47 loc) · 1.87 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
module.exports = function(less) {
// ............................................................
var tree = less.tree,
Anonymous = tree.Anonymous,
Value = tree.Value;
// ............................................................
var functions = {
// ....................................................
'current-selector': function() {
var context = this.context,
frames = context.frames,
level = [],
selectors, list, i, j;
// extract selectors array(s) from frames:
for (i = 0; i < (frames.length - 1); i++) {
selectors = frames[i].selectors;
if ((frames[i].type === 'Ruleset') && selectors) {
level.push(list = []);
for (j = 0; j < selectors.length; j++)
list.push(selectors[j].toCSS(context)); // note: this won't handle proper scope of variable interpolation (if any)
}
}
// build combinatorial list:
list = explode(level, 0);
for (i = 0; i < list.length; i++)
list[i] = new Anonymous(list[i].trim());
return new Value(list);
}
// ....................................................
};
return functions;
// ............................................................
// helpers:
function explode(list, i) {
if (!list[i + 1])
return list[i];
var r = [],
tail = explode(list, i + 1);
list = list[i];
for (var j = 0; j < list.length; j++)
for (var k = 0; k < tail.length; k++)
r.push(tail[k] + list[j]);
return r;
}
// ............................................................
}; // ~ end of module.exports