/
function-caller.js
55 lines (47 loc) · 1.66 KB
/
function-caller.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
import Expression from '../tree/expression';
class functionCaller {
constructor(name, context, index, currentFileInfo) {
this.name = name.toLowerCase();
this.index = index;
this.context = context;
this.currentFileInfo = currentFileInfo;
this.func = context.frames[0].functionRegistry.get(this.name);
}
isValid() {
return Boolean(this.func);
}
call(args) {
if (!(Array.isArray(args))) {
args = [args];
}
const evalArgs = this.func.evalArgs;
if (evalArgs !== false) {
args = args.map(a => a.eval(this.context));
}
const commentFilter = item => !(item.type === 'Comment');
// This code is terrible and should be replaced as per this issue...
// https://github.com/less/less.js/issues/2477
args = args
.filter(commentFilter)
.map(item => {
if (item.type === 'Expression') {
const subNodes = item.value.filter(commentFilter);
if (subNodes.length === 1) {
// https://github.com/less/less.js/issues/3616
if (item.parens && subNodes[0].op === '/') {
return item;
}
return subNodes[0];
} else {
return new Expression(subNodes);
}
}
return item;
});
if (evalArgs === false) {
return this.func(this.context, ...args);
}
return this.func(...args);
}
}
export default functionCaller;