diff --git a/lib/jsdoc/tag.js b/lib/jsdoc/tag.js index 90893717..27abc51f 100644 --- a/lib/jsdoc/tag.js +++ b/lib/jsdoc/tag.js @@ -92,10 +92,12 @@ function processTagText(tag, tagDef) { }; addHiddenProperty(tag.value.type, 'parsedType', tagType.parsedType); } - tag.value.optional = tagType.optional; - tag.value.nullable = tagType.nullable; - tag.value.variable = tagType.variable; - tag.value.defaultvalue = tagType.defaultvalue; + + ['optional', 'nullable', 'variable', 'defaultvalue'].forEach(function(prop) { + if (typeof tagType[prop] !== 'undefined') { + tag.value[prop] = tagType[prop]; + } + }); } if (tagType.text && tagType.text.length) { diff --git a/test/specs/jsdoc/tag.js b/test/specs/jsdoc/tag.js index 028e6f6f..f3dfea2d 100644 --- a/test/specs/jsdoc/tag.js +++ b/test/specs/jsdoc/tag.js @@ -1,4 +1,3 @@ -/*global afterEach, beforeEach, describe, env, expect, it, spyOn */ 'use strict'; var hasOwnProp = Object.prototype.hasOwnProperty; @@ -43,6 +42,7 @@ describe('jsdoc/tag', function() { var tagExample; var tagExampleIndented; var tagParam; + var tagParamWithType; var tagType; // allow each test to recreate the tags (for example, after enabling debug mode) @@ -51,8 +51,10 @@ describe('jsdoc/tag', function() { tagArg = new jsdoc.tag.Tag('arg ', text, meta); // @param with no type, but with optional and defaultvalue tagParam = new jsdoc.tag.Tag('param', '[foo=1]', meta); + // @param with type and no type modifiers (such as optional) + tagParamWithType = new jsdoc.tag.Tag('param', '{string} foo', meta); // @example that does not need indentation to be removed - tagExample = new jsdoc.tag.Tag('example', textExample, meta); + tagExample = new jsdoc.tag.Tag('example', textExample, meta); // @example that needs indentation to be removed tagExampleIndented = new jsdoc.tag.Tag('example', textExampleIndented, meta); // for testing that onTagText is run when necessary @@ -205,6 +207,12 @@ describe('jsdoc/tag', function() { expect(tagType.value.name).not.toBeDefined(); }); + + it('if the tag has a type without modifiers, tag.value should not include properties for the modifiers', function() { + ['optional', 'nullable', 'variable', 'defaultvalue'].forEach(function(modifier) { + expect( hasOwnProp.call(tagParamWithType.value, modifier) ).toBe(false); + }); + }); }); // further tests for this sort of thing are in jsdoc/tag/validator.js tests.