-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy patharray.js
33 lines (28 loc) · 874 Bytes
/
array.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
/*jslint node: true, indent: 2 */
'use strict';
module.exports = function (node, indent) {
var codegen, elements, that, body, space;
codegen = this.process.bind(this);
that = this;
function processElement(indent) {
return function (ele) {
var value = codegen(ele.value, indent);
if (ele.key) {
return codegen(ele.key, indent) + that.ws + '=>' + that.ws + value;
}
return value;
};
}
elements = node.items.map(processElement(indent));
if (elements.join().length > 80) {
space = that.nl + indent + this.indent;
elements = node.items.map(processElement(indent + this.indent));
body = space + elements.join(',' + space) + that.nl + indent;
} else {
body = elements.join(',' + that.ws);
}
if (node.shortForm || this.shortArray) {
return '[' + body + ']';
}
return 'array(' + body + ')';
};