support the public tag for Closure Compiler (#605)

This commit is contained in:
Jeff Williams 2017-07-16 19:51:50 -07:00
parent a9a68f3442
commit b13bb67fbb
4 changed files with 65 additions and 0 deletions

View File

@ -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: {

7
test/fixtures/publictag.js vendored Normal file
View File

@ -0,0 +1,7 @@
/**
* Public class.
*
* @class
* @public
*/
function Foo() {}

6
test/fixtures/publictag2.js vendored Normal file
View File

@ -0,0 +1,6 @@
/**
* Public variable.
*
* @public {string}
*/
var bar = 'baz';

View File

@ -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');
});
});
});