-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclosure.js
41 lines (35 loc) · 996 Bytes
/
closure.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
/*jslint node: true, indent: 2 */
'use strict';
var doBody = require('./helper/body');
var args = require('./helper/arguments');
var identifier = require('./helper/identifier');
// params, isRef, use, returnType
module.exports = function (node, indent) {
var codegen, str, useArgs;
codegen = this.process.bind(this);
// function header
str = 'function' + this.ws;
if (node.byref) {
str += '&';
}
str += args(node.arguments, indent, this);
// use statement
if (node.uses && node.uses.length > 0) {
useArgs = node.uses.map(function (arg) {
return '$' + arg.name;
});
str += this.ws + 'use' + this.ws + '(' + useArgs.join(',' + this.ws) + ')';
}
// php7 / return type
if (node.type) {
str += this.ws + ':' + this.ws;
if (node.nullable) {
str += '?';
}
str += identifier(node.type);
}
str += this.ws + '{' + this.nl;
str += doBody.call(this, codegen, indent, node.body.children);
str += indent + '}';
return str;
};