Added support for @global tag.

This commit is contained in:
Michael Mathews 2011-01-14 21:21:45 +00:00
parent 080ac73d49
commit fc5319020f
6 changed files with 66 additions and 3 deletions

View File

@ -1,9 +1,10 @@
/**
* @overview JSDoc/main.js
* @copyright 2010, 2011 (c) Michael Mathews <micmath@gmail.com>
* @project JSDoc
* @author Michael Mathews <micmath@gmail.com>
* @license See LICENSE.md file included in this distribution.
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

View File

@ -23,6 +23,7 @@
@param {Doclet} doclet
*/
exports.resolve = function(doclet) {
var name = doclet.name,
memberof = doclet.memberof || '',
about = {},
@ -65,7 +66,11 @@
doclet.longname = about.longname;
}
if (about.scope) {
if (doclet.scope === 'global') { // via @global tag?
doclet.longname = doclet.name;
delete doclet.memberof;
}
else if (about.scope) {
doclet.scope = puncToScope[about.scope];
}
else {
@ -74,6 +79,8 @@
doclet.longname = doclet.memberof + scopeToPunc[doclet.scope] + doclet.name;
}
}
}
function quoteUnsafe(name, kind) { // docspaced names may have unsafe characters which need to be quoted by us

View File

@ -108,6 +108,15 @@
})
.synonym('method');
dictionary.defineTag('global', {
mustNotHaveValue: true,
onTagged: function(doclet, tag) {
doclet.scope = 'global';
return true;
}
});
dictionary.defineTag('inner', {
onTagged: function(doclet, tag) {
setDocletScopeToTitle(doclet, tag);

16
test/cases/globaltag.js Normal file
View File

@ -0,0 +1,16 @@
/**
@global
@constructor
*/
window.Bar = new Function('', a, b, c);
(function() {
/** @global */
var foo;
foo = 'hello foo';
this.foo = foo;
}).apply(window);

View File

@ -89,5 +89,7 @@ testFile('test/t/cases/modules/data/mod-2.js');
testFile('test/t/cases/alias.js');
testFile('test/t/cases/alias2.js');
testFile('test/t/cases/globaltag.js');
report();

28
test/t/cases/globaltag.js Normal file
View File

@ -0,0 +1,28 @@
(function() {
var docSet = testhelpers.getDocSetFromFile('test/cases/globaltag.js'),
found = docSet.getByLongname('foo').filter(function($) {
return ! $.undocumented;
});
//dump(docSet.doclets);
test('When an inner symbol has a @global tag it is documented as if it were global.', function() {
assert.equal(found[0].name, 'foo');
assert.equal(found[0].longname, 'foo');
assert.equal(found[0].memberof, undefined);
assert.equal(found[0].scope, 'global');
});
found = docSet.getByLongname('Bar').filter(function($) {
return ! $.undocumented;
});
test('When an nested symbol has a @global tag it is documented as if it were global.', function() {
assert.equal(found[0].name, 'Bar');
assert.equal(found[0].longname, 'Bar');
assert.equal(found[0].memberof, undefined);
assert.equal(found[0].scope, 'global');
});
})();