-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtraituse.js
46 lines (44 loc) · 1.13 KB
/
traituse.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
/*jslint node: true, indent: 2 */
'use strict';
var identifier = require('./helper/identifier');
/**
* Usage declaration
*/
module.exports = function (node, indent) {
var str = 'use' + this.ws, items = [], glue, codegen;
codegen = this.process.bind(this);
node.traits.forEach(function (item) {
items.push(
codegen(item, indent)
);
});
str += items.join(',' + this.ws);
if (node.adaptations) {
glue = this.nl + indent + this.indent;
str += this.ws + '{' + glue;
str += node.adaptations.map(function (item) {
var out = '';
if (item.trait) {
out += codegen(item.trait, indent) + '::';
}
if (item.method) {
out += item.method;
}
if (item.kind === 'traitprecedence') {
out += ' insteadof ';// + codegen(item.insteadof);
out += item.instead.map(identifier).join(', ');
} else {
out += ' as ';
if (item.visibility) {
out += item.visibility + ' ';
}
out += item.as;
}
return out + ';';
}).join(glue) + this.nl;
str += indent + '}';
} else {
str += ';';
}
return str + this.nl;
};