Inline object literals from olx.js

This commit is contained in:
Andreas Hocevar
2014-04-15 19:02:30 +02:00
committed by Tim Schaub
parent cdd1922350
commit 29b643c7b0
2 changed files with 37 additions and 48 deletions

View File

@@ -2,7 +2,26 @@
* Converts olx.js @type annotations into properties of the previous @typedef.
*/
var olxTypedef = null;
var lastOlxTypedef = null;
var olxTypes = {};
function addSubparams(params) {
for (var j = 0, jj = params.length; j < jj; ++j) {
var param = params[j];
var types = param.type.names;
for (var k = 0, kk = types.length; k < kk; ++k) {
var name = types[k];
if (name in olxTypes) {
param.subparams = olxTypes[name];
addSubparams(param.subparams);
types[k] = 'Object';
// TODO Do we need to support multiple object literal types per
// param?
break;
}
}
}
}
exports.handlers = {
@@ -10,12 +29,25 @@ exports.handlers = {
var doclet = e.doclet;
if (doclet.meta.filename == 'olx.js') {
if (doclet.kind == 'typedef') {
olxTypedef = doclet;
lastOlxTypedef = doclet;
olxTypes[doclet.longname] = [];
doclet.properties = [];
} else if (olxTypedef && doclet.memberof == olxTypedef.longname) {
olxTypedef.properties.push(doclet);
} else if (lastOlxTypedef && doclet.memberof == lastOlxTypedef.longname) {
lastOlxTypedef.properties.push(doclet);
olxTypes[lastOlxTypedef.longname].push(doclet);
} else {
olxTypedef = null;
lastOlxTypedef = null;
}
}
},
parseComplete: function(e) {
var doclets = e.doclets;
for (var i = doclets.length - 1; i >= 0; --i) {
var doclet = doclets[i];
var params = doclet.params;
if (params) {
addSubparams(params);
}
}
}