Use symbols.json for determining the API

Also to get rid of regular expression parsing, instead of
collecting exports for observables from the source files, we use
the 'observable' annotations.
This commit is contained in:
Andreas Hocevar
2014-04-11 14:32:18 +02:00
committed by Tim Schaub
parent 758eed357e
commit b758d92790

View File

@@ -8,25 +8,12 @@
var api = [];
var unexported = [];
var observablesByClass = {};
function collectExports(source) {
var i, ii, symbol, property;
var syms = source.match(/goog\.exportSymbol\([^\)]*\)/g);
if (syms) {
i = 0; ii = syms.length;
for (; i < ii; ++i) {
symbol = syms[i].match(/'([^']*)'/)[1];
api.push(symbol);
}
}
var props = source.match(/goog\.exportProperty\([^\)]*\)/g);
if (props) {
i = 0; ii = props.length;
for (; i < ii; ++i) {
property = props[i].match(/[^,]*,[^,]*,\r?\n? *([^\)]*)\)/)[1]
.replace('.prototype.', '#');
api.push(property);
}
var symbols = JSON.parse(source).symbols;
for (var i = 0, ii = symbols.length; i < ii; ++i) {
api.push(symbols[i].name);
}
}
@@ -44,18 +31,12 @@ function collectOliExports(source) {
var encoding = env.conf.encoding || 'utf8';
var fs = require('jsdoc/fs');
collectExports(fs.readFileSync('build/exports.js', encoding));
collectExports(fs.readFileSync('build/symbols.json', encoding));
collectOliExports(fs.readFileSync('externs/oli.js', encoding));
exports.handlers = {
beforeParse: function(e) {
if (/\.js$/.test(e.filename)) {
collectExports(e.source);
}
},
newDoclet: function(e) {
var i, ii, j, jj;
if (e.doclet.meta.filename == "olx.js" && e.doclet.longname != 'olx') {
@@ -87,6 +68,12 @@ exports.handlers = {
}
}
}
if (e.doclet.observables) {
var observables = observablesByClass[e.doclet.longname] = [];
for (i = e.doclet.observables.length - 1; i >= 0; --i) {
observables.push(e.doclet.observables[i].name);
}
}
},
parseComplete: function(e) {
@@ -109,6 +96,14 @@ exports.handlers = {
}
var fqn = doclet.longname;
if (fqn) {
var getterOrSetter = fqn.match(/([^#]*)#[gs]et(.*)/);
if (getterOrSetter) {
var observables = observablesByClass[getterOrSetter[1]];
if (observables && observables.indexOf(getterOrSetter[2].toLowerCase()) > -1) {
// Always document getters/setters of observables
continue;
}
}
doclet.unexported = (api.indexOf(fqn) === -1 && unexported.indexOf(fqn) !== -1);
if (api.indexOf(fqn) === -1 && unexported.indexOf(fqn) === -1) {
e.doclets.splice(j, 1);