Support nullable params and returns in generated externs

This commit is contained in:
Andreas Hocevar
2014-08-27 18:18:49 +02:00
parent 4e8abb62f9
commit 663fef3dfd
2 changed files with 13 additions and 3 deletions

View File

@@ -103,11 +103,19 @@ exports.publish = function(data, opts) {
if (typeof param.optional == 'boolean') {
paramInfo.optional = param.optional;
}
if (typeof param.nullable == 'boolean') {
paramInfo.nullable = param.nullable;
}
});
symbol.params = params;
}
if (doc.returns) {
symbol.returns = getTypes(doc.returns[0].type.names);
symbol.returns = {
types: getTypes(doc.returns[0].type.names)
};
if (typeof doc.returns[0].nullable == 'boolean') {
symbol.returns.nullable = doc.returns[0].nullable;
}
}
if (doc.tags) {
doc.tags.every(function(tag) {

View File

@@ -105,12 +105,14 @@ function generateExterns(typedefs, symbols, externs) {
lines.push(' * @param {' +
(param.variable ? '...' : '') +
noGoogTypes(param.types).join('|') +
(param.optional ? '=' : '') +
(param.optional ? '=' : '') + (param.nullable ? '!' : '') +
'} ' + param.name);
});
}
if (symbol.returns) {
lines.push(' * @return {' + noGoogTypes(symbol.returns).join('|') + '}');
lines.push(' * @return {' +
(symbol.returns.nullable ? '!' : '') +
noGoogTypes(symbol.returns.types).join('|') + '}');
}
if (symbol.template) {
lines.push(' * @template ' + symbol.template);