diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 62d4cc9b..f76d697d 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -111,7 +111,7 @@ exports.resolve = function(doclet) { doclet.setMemberof(about.memberof); } - if (about.longname && !doclet.longname) { + if (about.longname && (!doclet.longname || doclet.longname === doclet.name)) { doclet.setLongname(about.longname); } diff --git a/lib/jsdoc/src/handlers.js b/lib/jsdoc/src/handlers.js index 8842cd96..1f126a9b 100644 --- a/lib/jsdoc/src/handlers.js +++ b/lib/jsdoc/src/handlers.js @@ -33,6 +33,20 @@ function setCurrentModule(doclet) { } } +function setDefaultScopeMemberOf(doclet) { + // add @inner and @memberof tags unless the current module exports only this symbol + if (currentModule && currentModule !== doclet.name) { + // add @inner unless the current module exports only this symbol + if (!doclet.scope) { + doclet.addTag('inner'); + } + + if (!doclet.memberof && doclet.scope !== 'global') { + doclet.addTag('memberof', currentModule); + } + } +} + /** * Attach these event handlers to a particular instance of a parser. * @param parser @@ -48,6 +62,8 @@ exports.attachTo = function(parser) { return false; // only interested in virtual comments (with a @name) here } + setDefaultScopeMemberOf(newDoclet); + newDoclet.postProcess(); addDoclet.call(parser, newDoclet); e.doclet = newDoclet; @@ -149,17 +165,7 @@ exports.attachTo = function(parser) { } } else { - // add @inner and @memberof tags unless the current module exports only this symbol - if (currentModule && currentModule !== newDoclet.name) { - // add @inner unless the current module exports only this symbol - if (!newDoclet.scope) { - newDoclet.addTag('inner'); - } - - if (!newDoclet.memberof && newDoclet.scope !== 'global') { - newDoclet.addTag('memberof', currentModule); - } - } + setDefaultScopeMemberOf(newDoclet); } } diff --git a/test/fixtures/moduletag4.js b/test/fixtures/moduletag4.js new file mode 100644 index 00000000..cbca4746 --- /dev/null +++ b/test/fixtures/moduletag4.js @@ -0,0 +1,37 @@ +/** @module M1 */ + +/** + * The differnet kind of mouse buttons. + * + * @summary Blah blah + * @readonly + * @enum {string} + */ +exports.MouseButtons = { + Left: "Left", + Middle: "Middle", + Right: "Right" +}; + +/** + * @typedef ClickProperties + * @type {object} + * @property {MouseButtons} Button - Which mouse button is clicking. + */ + +/** + * Virtual comment function + * + * @function VirtualComment + * @static + * @param {string} comment - comment + * + */ + +/** + * Virtual comment function 2 + * @function VirtualComment2 + * @instance + * @param {string} comment - comment + */ + diff --git a/test/specs/tags/moduletag.js b/test/specs/tags/moduletag.js index e2b44e30..25620b41 100644 --- a/test/specs/tags/moduletag.js +++ b/test/specs/tags/moduletag.js @@ -38,4 +38,36 @@ describe("@module tag", function() { expect(darken.kind).toBe('function'); }); }); + + describe("virtual comments", function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag4.js'), + m1 = docSet.getByLongname('module:M1').filter(function($) { + return ! $.undocumented; + })[0], + clickProperties = docSet.getByLongname('module:M1~ClickProperties')[0], + virtFunc = docSet.getByLongname('module:M1.VirtualComment')[0], + virtFunc2 = docSet.getByLongname('module:M1#VirtualComment2')[0]; + + it('When a virtual comment typedef is inside a module, the typedef is a memberof the module', function () { + expect(clickProperties.memberof).toBe('module:M1'); + }); + + it('When a virtual comment typedef is inside a module, the typedef longname contains the module name', function() { + expect(clickProperties.longname).toBe('module:M1~ClickProperties'); + }); + + it('When a virtual comment typedef is inside a module, the typedef scope is "inner"', function() { + expect(clickProperties.scope).toBe('inner'); + }); + + it('When a virtual comment function is inside a module with a static scope, the function has the correct memberof and longname', function () { + expect(virtFunc.longname).toBe('module:M1.VirtualComment'); + expect(virtFunc.memberof).toBe('module:M1'); + }); + + it('When a virtual comment function is inside a module with an instance scope, the function has the correct memberof and longname', function() { + expect(virtFunc2.longname).toBe('module:M1#VirtualComment2'); + expect(virtFunc2.memberof).toBe('module:M1'); + }); + }); }); \ No newline at end of file