for Closure, allow the type tag to have a description (#732)

This commit is contained in:
Jeff Williams 2014-08-13 21:53:11 -07:00
parent 180454c3a8
commit 17fb5be064
3 changed files with 63 additions and 2 deletions

View File

@ -796,7 +796,11 @@ var closureTags = exports.closureTags = {
return: cloneTagDef(baseTags.returns),
'this': cloneTagDef(baseTags['this']),
throws: cloneTagDef(baseTags.throws),
type: cloneTagDef(baseTags.type),
type: (function() {
var tagDef = cloneTagDef(baseTags.type);
tagDef.mustNotHaveDescription = false;
return tagDef;
})(),
typedef: cloneTagDef(baseTags.typedef)
};

4
test/fixtures/typetag2.js vendored Normal file
View File

@ -0,0 +1,4 @@
/**
* @type {(string|number)} A string or a number.
*/
var stringOrNumber;

View File

@ -1,4 +1,14 @@
/*global describe, expect, it, jasmine */
/*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('@type tag', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/typetag.js');
@ -21,4 +31,47 @@ describe('@type tag', function() {
expect(baz.nullable).toBe(false);
});
describe('JSDoc tags', function() {
afterEach(function() {
doclet._replaceDictionary(originalDictionary);
});
it('When JSDoc tags are enabled, the @type tag does not accept a description.', function() {
var dict = new Dictionary();
var typeDocs;
definitions.defineTags(dict, definitions.jsdocTags);
doclet._replaceDictionary(dict);
spyOn(logger, 'warn');
typeDocs = jasmine.getDocSetFromFile('test/fixtures/typetag2.js');
expect(logger.warn).toHaveBeenCalled();
});
});
describe('Closure tags', function() {
afterEach(function() {
doclet._replaceDictionary(originalDictionary);
});
it('When Closure tags are enabled, the @type tag accepts a description.', function() {
var dict = new Dictionary();
var stringOrNumber;
var typeDocs;
definitions.defineTags(dict, definitions.closureTags);
doclet._replaceDictionary(dict);
spyOn(logger, 'warn');
typeDocs = jasmine.getDocSetFromFile('test/fixtures/typetag2.js');
stringOrNumber = typeDocs.getByLongname('stringOrNumber')[0];
expect(logger.warn).not.toHaveBeenCalled();
expect(stringOrNumber).toBeDefined();
expect(stringOrNumber.description).toBe('A string or a number.');
});
});
});