when creating links, do not treat <anonymous> types as type applications, and handle union types without parentheses (#654)

This commit is contained in:
Jeff Williams 2014-06-15 20:57:08 -07:00
parent eeb9c94c66
commit be60e811eb
2 changed files with 22 additions and 1 deletions

View File

@ -141,6 +141,11 @@ function hasUrlPrefix(text) {
return (/^(http|ftp)s?:\/\//).test(text);
}
function isComplexTypeExpression(expr) {
// record types, type unions, and type applications all count as "complex"
return expr.search(/[{(|]/) !== -1 || expr.search(/</) > 0;
}
/**
* Build an HTML link to the symbol with the specified longname. If the longname is not
* associated with a URL, this method simply returns the link text, if provided, or the longname.
@ -185,7 +190,7 @@ function buildLink(longname, linkText, options) {
}
// handle complex type expressions that may require multiple links
// (but skip anything that looks like an inline tag)
else if (longname && longname.search(/[<{(]/) !== -1 && /\{\@.+\}/.test(longname) === false) {
else if (longname && isComplexTypeExpression(longname) && /\{\@.+\}/.test(longname) === false) {
parsedType = parseType(longname);
return stringifyType(parsedType, options.cssClass, options.linkMap);
}

View File

@ -1,4 +1,6 @@
/*global afterEach, beforeEach, describe, expect, env, it, jasmine, spyOn */
'use strict';
var hasOwnProp = Object.prototype.hasOwnProperty;
describe("jsdoc/util/templateHelper", function() {
@ -293,6 +295,20 @@ describe("jsdoc/util/templateHelper", function() {
'<a href="fakeclass.html">LinktoFakeClass</a>)>');
});
it('works correctly with type unions that are not enclosed in parentheses', function() {
var link = helper.linkto('linktoTest|LinktoFakeClass', 'link text');
expect(link).toBe('(<a href="test.html">linktoTest</a>|' +
'<a href="fakeclass.html">LinktoFakeClass</a>)');
});
it('does not try to parse a longname starting with <anonymous> as a type application',
function() {
spyOn(logger, 'error');
helper.linkto('<anonymous>~foo');
expect(logger.error).not.toHaveBeenCalled();
});
it('returns a link when a URL is specified', function() {
var link = helper.linkto('http://example.com');
expect(link).toBe('<a href="http://example.com">http://example.com</a>');