mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
improve error reporting for type expressions that cannot be parsed
This commit is contained in:
parent
cf89e494ec
commit
f4e814ba87
@ -5,6 +5,21 @@
|
||||
|
||||
var currentModule = null;
|
||||
|
||||
function getNewDoclet(parser, comment, e) {
|
||||
var jsdoc = {doclet: require('jsdoc/doclet')};
|
||||
var util = require('util');
|
||||
var err;
|
||||
|
||||
try {
|
||||
return new jsdoc.doclet.Doclet(e.comment, e);
|
||||
}
|
||||
catch (error) {
|
||||
err = new Error( util.format('cannot create a doclet in the file %s for the comment ' +
|
||||
'"%s": %s', parser._currentSourceName, comment.replace(/[\r\n]/g, ''), error.message) );
|
||||
require('jsdoc/util/error').handle(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Attach these event handlers to a particular instance of a parser.
|
||||
@param parser
|
||||
@ -14,7 +29,7 @@ exports.attachTo = function(parser) {
|
||||
|
||||
// handles JSDoc comments that include a @name tag -- the code is ignored in such a case
|
||||
parser.on('jsdocCommentFound', function(e) {
|
||||
var newDoclet = new jsdoc.doclet.Doclet(e.comment, e);
|
||||
var newDoclet = getNewDoclet(parser, e.comment, e);
|
||||
|
||||
if (!newDoclet.name) {
|
||||
return false; // only interested in virtual comments (with a @name) here
|
||||
@ -40,13 +55,13 @@ exports.attachTo = function(parser) {
|
||||
|
||||
function newSymbolDoclet(docletSrc, e) {
|
||||
var memberofName = null,
|
||||
newDoclet = new jsdoc.doclet.Doclet(docletSrc, e);
|
||||
newDoclet = getNewDoclet(parser, docletSrc, e);
|
||||
|
||||
// an undocumented symbol right after a virtual comment? rhino mistakenly connected the two
|
||||
if (newDoclet.name) { // there was a @name in comment
|
||||
// try again, without the comment
|
||||
e.comment = '@undocumented';
|
||||
newDoclet = new jsdoc.doclet.Doclet(e.comment, e);
|
||||
newDoclet = getNewDoclet(parser, e.comment, e);
|
||||
}
|
||||
|
||||
if (newDoclet.alias) {
|
||||
|
||||
@ -154,14 +154,14 @@ function parseTypeExpression(tagInfo) {
|
||||
if (!tagInfo.typeExpression) {
|
||||
return tagInfo;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
parsedType = catharsis.parse(tagInfo.typeExpression, {jsdoc: true});
|
||||
}
|
||||
catch (e) {
|
||||
errorMessage = util.format('unable to parse the type expression "%s": %s',
|
||||
tagInfo.typeExpression, e.message);
|
||||
require('jsdoc/util/error').handle( new Error(errorMessage) );
|
||||
// always re-throw so the caller has a chance to report which file was bad
|
||||
throw new Error( util.format('unable to parse the type expression "%s": %s',
|
||||
tagInfo.typeExpression, e.message) );
|
||||
}
|
||||
|
||||
if (parsedType) {
|
||||
@ -189,6 +189,7 @@ var typeParsers = [parseName, parseTypeExpression];
|
||||
* @param {boolean} canHaveType - Indicates whether the value can include a type expression that
|
||||
* describes the member.
|
||||
* @return {module:jsdoc/tag/type.TagInfo} Information obtained from the tag.
|
||||
* @throws {Error} Thrown if a type expression cannot be parsed.
|
||||
*/
|
||||
exports.parse = function(tagValue, canHaveName, canHaveType) {
|
||||
if (typeof tagValue !== 'string') { tagValue = ''; }
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/*global describe: true, expect: true, it: true, jasmine: true */
|
||||
describe("@ignore tag", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/ignoretag.js'),
|
||||
foo = docSet.getByLongname('foo')[0];
|
||||
@ -11,7 +12,7 @@ describe("@ignore tag", function() {
|
||||
docSet = jasmine.getDocSetFromFile('test/fixtures/ignoretag2.js');
|
||||
foo = docSet.getByLongname('foo')[0];
|
||||
} catch (e) {
|
||||
expect(e.name).toBe('TagValueNotPermittedError');
|
||||
};
|
||||
expect(e instanceof Error).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user