diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index 5a113412..a908e381 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -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); } diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index a0cdf676..a5e75f79 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -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() { 'LinktoFakeClass)>'); }); + it('works correctly with type unions that are not enclosed in parentheses', function() { + var link = helper.linkto('linktoTest|LinktoFakeClass', 'link text'); + expect(link).toBe('(linktoTest|' + + 'LinktoFakeClass)'); + }); + + it('does not try to parse a longname starting with as a type application', + function() { + spyOn(logger, 'error'); + + helper.linkto('~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('http://example.com');