From 1cb337c90a7914b6cbb8dbbc949632cce62ced4a Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Tue, 16 Dec 2014 10:33:45 -0800 Subject: [PATCH] cleanup --- lib/jsdoc/tag.js | 34 +++++++++++++++++++--------------- test/specs/jsdoc/tag.js | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/jsdoc/tag.js b/lib/jsdoc/tag.js index 6f2bfe44..963c9555 100644 --- a/lib/jsdoc/tag.js +++ b/lib/jsdoc/tag.js @@ -69,7 +69,23 @@ function addHiddenProperty(obj, propName, propValue) { }); } -function processTagText(tag, tagDef) { +function parseType(tag, tagDef, meta) { + try { + return jsdoc.tag.type.parse(tag.text, tagDef.canHaveName, tagDef.canHaveType); + } + catch (e) { + jsdoc.util.logger.error( + 'Unable to parse a tag\'s type expression%s with tag title "%s" and text "%s": %s', + meta.filename ? ( ' for source file ' + path.join(meta.path, meta.filename) ) : '', + tag.originalTitle, + tag.text, + e.message + ); + return {}; + } +} + +function processTagText(tag, tagDef, meta) { var tagType; if (tagDef.onTagText) { @@ -80,7 +96,7 @@ function processTagText(tag, tagDef) { /** The value property represents the result of parsing the tag text. */ tag.value = {}; - tagType = jsdoc.tag.type.parse(tag.text, tagDef.canHaveName, tagDef.canHaveType); + tagType = parseType(tag, tagDef, meta); // It is possible for a tag to *not* have a type but still have // optional or defaultvalue, e.g. '@param [foo]'. @@ -173,19 +189,7 @@ var Tag = exports.Tag = function(tagTitle, tagBody, meta) { this.text = trim(tagBody, trimOpts, meta); if (this.text) { - try { - processTagText(this, tagDef); - } - catch (e) { - // probably a type-parsing error - jsdoc.util.logger.error( - 'Unable to create a Tag object%s with title "%s" and body "%s": %s', - meta.filename ? ( ' for source file ' + path.join(meta.path, meta.filename) ) : '', - tagTitle, - tagBody, - e.message - ); - } + processTagText(this, tagDef, meta); } jsdoc.tag.validator.validate(this, tagDef, meta); diff --git a/test/specs/jsdoc/tag.js b/test/specs/jsdoc/tag.js index f3dfea2d..36bbd802 100644 --- a/test/specs/jsdoc/tag.js +++ b/test/specs/jsdoc/tag.js @@ -221,7 +221,7 @@ describe('jsdoc/tag', function() { spyOn(logger, 'error'); }); - it('logs an error for bad tags', function() { + it('logs an error for tags with bad type expressions', function() { var tag = new jsdoc.tag.Tag('param', '{!*!*!*!} foo'); expect(logger.error).toHaveBeenCalled();