diff --git a/main.js b/main.js index 7a5ca359..9d981b42 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,10 @@ /** - * @overview JSDoc/main.js - * @copyright 2010, 2011 (c) Michael Mathews + * @project JSDoc + * @author Michael Mathews * @license See LICENSE.md file included in this distribution. */ + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// diff --git a/modules/jsdoc/name.js b/modules/jsdoc/name.js index 187d8d86..2c530913 100644 --- a/modules/jsdoc/name.js +++ b/modules/jsdoc/name.js @@ -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 diff --git a/modules/jsdoc/tag/dictionary/definitions.js b/modules/jsdoc/tag/dictionary/definitions.js index 50964503..54bbabd3 100644 --- a/modules/jsdoc/tag/dictionary/definitions.js +++ b/modules/jsdoc/tag/dictionary/definitions.js @@ -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); diff --git a/test/cases/globaltag.js b/test/cases/globaltag.js new file mode 100644 index 00000000..44f1d186 --- /dev/null +++ b/test/cases/globaltag.js @@ -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); \ No newline at end of file diff --git a/test/runner.js b/test/runner.js index 78efb83b..4e14cc8a 100644 --- a/test/runner.js +++ b/test/runner.js @@ -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(); diff --git a/test/t/cases/globaltag.js b/test/t/cases/globaltag.js new file mode 100644 index 00000000..efea4807 --- /dev/null +++ b/test/t/cases/globaltag.js @@ -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'); + }); + +})(); \ No newline at end of file