-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfor.js
55 lines (47 loc) · 1.06 KB
/
for.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
/*jslint node: true, indent: 2 */
'use strict';
var doBody = require('./helper/body');
module.exports = function (node, indent) {
var codegen, str;
codegen = this.process.bind(this);
str = 'for' + this.ws + '(';
if (node.init) {
str += node.init.map(function (x) {
if (x) {
return codegen(x, indent);
}
return '';
}).join(',' + this.ws);
}
str += ';' + this.ws;
if (node.test) {
str += node.test.map(function (x) {
if (x) {
return codegen(x, indent);
}
return '';
}).join(',' + this.ws);
}
str += ';' + this.ws;
if (node.increment) {
str += node.increment.map(function (x) {
if (x) {
return codegen(x, indent);
}
return '';
}).join(',' + this.ws);
}
str += ')';
if (this.shortForm) {
str += ':' + this.nl;
} else {
str += this.ws + '{' + this.nl;
}
str += doBody.call(this, codegen, indent, node.body.children || [node.body]);
if (this.shortForm) {
str += indent + 'endfor;';
} else {
str += indent + '}';
}
return str;
};