mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
allow the Closure version of the protected tag to specify a type (#731)
Also adds tests for the `protected` tag.
This commit is contained in:
parent
21e0dbad25
commit
e8b692b334
@ -783,7 +783,16 @@ var closureTags = exports.closureTags = {
|
||||
}
|
||||
}
|
||||
},
|
||||
protected: cloneTagDef(baseTags.protected),
|
||||
protected: {
|
||||
canHaveType: true,
|
||||
onTagged: function(doclet, tag) {
|
||||
doclet.access = 'protected';
|
||||
|
||||
if (tag.value && tag.value.type) {
|
||||
setDocletTypeToValueType(doclet, tag);
|
||||
}
|
||||
}
|
||||
},
|
||||
return: cloneTagDef(baseTags.returns),
|
||||
'this': cloneTagDef(baseTags['this']),
|
||||
throws: cloneTagDef(baseTags.throws),
|
||||
|
||||
20
test/fixtures/protectedtag.js
vendored
Normal file
20
test/fixtures/protectedtag.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/** @module uid */
|
||||
|
||||
/** @protected */
|
||||
var uidCounter = 1;
|
||||
|
||||
/** @protected */
|
||||
var uidObjects = {
|
||||
/** Root object. */
|
||||
root: {}
|
||||
};
|
||||
|
||||
/** Obtain a unique ID. */
|
||||
exports.getUid = function getUid() {
|
||||
return uidCounter++;
|
||||
};
|
||||
|
||||
/** Associate an object with a unique ID. */
|
||||
exports.setObjectForUid = function setObjectForUid(obj, uid) {
|
||||
uidObjects[uid] = obj;
|
||||
};
|
||||
13
test/fixtures/protectedtag2.js
vendored
Normal file
13
test/fixtures/protectedtag2.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/** @protected {number} */
|
||||
var uidCounter = 1;
|
||||
|
||||
/**
|
||||
* Unique ID generator.
|
||||
* @constructor
|
||||
*/
|
||||
function UidGenerator() {}
|
||||
|
||||
/** Generate a unique ID. */
|
||||
UidGenerator.prototype.generate = function generate() {
|
||||
return uidCounter++;
|
||||
};
|
||||
75
test/specs/tags/protected.js
Normal file
75
test/specs/tags/protected.js
Normal file
@ -0,0 +1,75 @@
|
||||
/*global afterEach, describe, expect, it, jasmine, spyOn */
|
||||
'use strict';
|
||||
|
||||
var definitions = require('jsdoc/tag/dictionary/definitions');
|
||||
var dictionary = require('jsdoc/tag/dictionary');
|
||||
var Dictionary = dictionary.Dictionary;
|
||||
var doclet = require('jsdoc/doclet');
|
||||
var logger = require('jsdoc/util/logger');
|
||||
|
||||
var originalDictionary = dictionary;
|
||||
|
||||
describe('@protected tag', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/protectedtag.js');
|
||||
var uidCounter = docSet.getByLongname('module:uid~uidCounter')[0];
|
||||
var uidRoot = docSet.getByLongname('module:uid~uidObjects.root')[0];
|
||||
|
||||
it('When a symbol has a @protected tag, the doclet has an `access` property set to ' +
|
||||
'`protected`.', function() {
|
||||
expect(uidCounter.access).toBe('protected');
|
||||
});
|
||||
|
||||
it('When a symbol tagged with @protected has members, the members do not inherit the ' +
|
||||
'@protected tag.', function() {
|
||||
expect(uidRoot.access).not.toBeDefined();
|
||||
});
|
||||
|
||||
describe('JSDoc tags', function() {
|
||||
afterEach(function() {
|
||||
doclet._replaceDictionary(originalDictionary);
|
||||
});
|
||||
|
||||
it('When JSDoc tags are enabled, the @protected tag does not accept a value.', function() {
|
||||
var dict = new Dictionary();
|
||||
var protectedDocs;
|
||||
|
||||
definitions.defineTags(dict, definitions.jsdocTags);
|
||||
doclet._replaceDictionary(dict);
|
||||
spyOn(logger, 'warn');
|
||||
|
||||
protectedDocs = jasmine.getDocSetFromFile('test/fixtures/protectedtag2.js');
|
||||
|
||||
expect(logger.warn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Closure Compiler tags', function() {
|
||||
afterEach(function() {
|
||||
doclet._replaceDictionary(originalDictionary);
|
||||
});
|
||||
|
||||
it('When Closure Compiler tags are enabled, the @private tag accepts a type expression.',
|
||||
function() {
|
||||
var dict = new Dictionary();
|
||||
var protectedDocs;
|
||||
var uidCounter;
|
||||
|
||||
definitions.defineTags(dict, definitions.closureTags);
|
||||
doclet._replaceDictionary(dict);
|
||||
spyOn(logger, 'warn');
|
||||
|
||||
protectedDocs = jasmine.getDocSetFromFile('test/fixtures/protectedtag2.js');
|
||||
uidCounter = protectedDocs.getByLongname('uidCounter')[0];
|
||||
|
||||
expect(logger.warn).not.toHaveBeenCalled();
|
||||
|
||||
expect(uidCounter).toBeDefined();
|
||||
expect(uidCounter.access).toBe('protected');
|
||||
|
||||
expect(uidCounter.type).toBeDefined();
|
||||
expect(uidCounter.type.names).toBeDefined();
|
||||
expect(uidCounter.type.names.length).toBe(1);
|
||||
expect(uidCounter.type.names[0]).toBe('number');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user