From 17fb5be0644cecc97b7b51c7e27c0eda0481add7 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Wed, 13 Aug 2014 21:53:11 -0700 Subject: [PATCH] for Closure, allow the `type` tag to have a description (#732) --- lib/jsdoc/tag/dictionary/definitions.js | 6 ++- test/fixtures/typetag2.js | 4 ++ test/specs/tags/typetag.js | 55 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/typetag2.js diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index d2573886..be09226e 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -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) }; diff --git a/test/fixtures/typetag2.js b/test/fixtures/typetag2.js new file mode 100644 index 00000000..25790895 --- /dev/null +++ b/test/fixtures/typetag2.js @@ -0,0 +1,4 @@ +/** + * @type {(string|number)} A string or a number. + */ +var stringOrNumber; diff --git a/test/specs/tags/typetag.js b/test/specs/tags/typetag.js index 0c4246eb..2a863d81 100644 --- a/test/specs/tags/typetag.js +++ b/test/specs/tags/typetag.js @@ -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.'); + }); + }); });