diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index 79c4d3f2..372af001 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -953,6 +953,16 @@ exports.closureTags = { } } }, + public: { + canHaveType: true, + onTagged: function(doclet, tag) { + doclet.access = 'public'; + + if (tag.value && tag.value.type) { + setDocletTypeToValueType(doclet, tag); + } + } + }, return: cloneTagDef(baseTags.returns), // Closure Compiler only struct: { diff --git a/test/fixtures/publictag.js b/test/fixtures/publictag.js new file mode 100644 index 00000000..38a80f90 --- /dev/null +++ b/test/fixtures/publictag.js @@ -0,0 +1,7 @@ +/** + * Public class. + * + * @class + * @public + */ +function Foo() {} diff --git a/test/fixtures/publictag2.js b/test/fixtures/publictag2.js new file mode 100644 index 00000000..f23d3532 --- /dev/null +++ b/test/fixtures/publictag2.js @@ -0,0 +1,6 @@ +/** + * Public variable. + * + * @public {string} + */ +var bar = 'baz'; diff --git a/test/specs/tags/publictag.js b/test/specs/tags/publictag.js new file mode 100644 index 00000000..df179fdb --- /dev/null +++ b/test/specs/tags/publictag.js @@ -0,0 +1,42 @@ +'use strict'; + +describe('@public tag', function() { + afterEach(function() { + jasmine.restoreTagDictionary(); + }); + + describe('JSDoc tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('jsdoc'); + }); + + it('should set the doclet\'s `access` property to `public`', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/publictag.js'); + var foo = docSet.getByLongname('Foo')[0]; + + expect(foo.access).toBe('public'); + }); + }); + + describe('Closure Compiler tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('closure'); + }); + + it('should set the doclet\'s `access` property to `public`', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/publictag2.js'); + var bar = docSet.getByLongname('bar')[0]; + + expect(bar.access).toBe('public'); + }); + + it('should include the type if one is provided', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/publictag2.js'); + var bar = docSet.getByLongname('bar')[0]; + + expect(bar.type).toBeDefined(); + expect(bar.type.names.length).toBe(1); + expect(bar.type.names[0]).toBe('string'); + }); + }); +});