This commit is contained in:
Jeff Williams 2014-12-16 10:33:45 -08:00
parent d1d05687f1
commit 1cb337c90a
2 changed files with 20 additions and 16 deletions

View File

@ -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);

View File

@ -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();