mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
more improvements to error handling for type expressions
This commit is contained in:
parent
f4e814ba87
commit
2ccd9c4f39
@ -17,6 +17,7 @@ function getNewDoclet(parser, comment, e) {
|
||||
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);
|
||||
return new jsdoc.doclet.Doclet('', {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,20 @@ var tutorialLinkMap = {
|
||||
|
||||
var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl;
|
||||
|
||||
function parseType(longname) {
|
||||
var catharsis = require('catharsis');
|
||||
var err;
|
||||
|
||||
try {
|
||||
return catharsis.parse(longname, {jsdoc: true});
|
||||
}
|
||||
catch (e) {
|
||||
err = new Error('unable to parse ' + longname + ': ' + e.message);
|
||||
require('jsdoc/util/error').handle(err);
|
||||
return longname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an HTML link to the member with the specified longname. If the longname is not
|
||||
* associated with a URL, this method returns the link text, if provided, or the longname.
|
||||
@ -123,19 +137,16 @@ var linkto = exports.linkto = function(longname, linktext, cssClass) {
|
||||
var url = hasOwnProp.call(longnameToUrl, longname) && longnameToUrl[longname];
|
||||
var parsedType;
|
||||
|
||||
// type applications require special treatment
|
||||
var typeAppInfo = /(\S+)<(\S+)>/.exec(longname);
|
||||
if (typeAppInfo) {
|
||||
typeAppInfo[1] = linkto(typeAppInfo[1], null, cssClass);
|
||||
parsedType = catharsis.parse(typeAppInfo[2], {jsdoc: true});
|
||||
typeAppInfo[2] = catharsis.stringify(parsedType, {
|
||||
// handle complex type expressions that may require multiple links
|
||||
if (text.search(/[<{(]/) !== -1) {
|
||||
parsedType = parseType(longname);
|
||||
return catharsis.stringify(parsedType, {
|
||||
cssClass: cssClass,
|
||||
htmlSafe: true,
|
||||
links: longnameToUrl
|
||||
});
|
||||
return typeAppInfo[1] + '<' + typeAppInfo[2] + '>';
|
||||
}
|
||||
|
||||
|
||||
if (!url) {
|
||||
return text;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user