From be60e811eb51f418ea3b8c1259a8893fa34c34bc Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 15 Jun 2014 20:57:08 -0700 Subject: [PATCH] when creating links, do not treat `` types as type applications, and handle union types without parentheses (#654) --- lib/jsdoc/util/templateHelper.js | 7 ++++++- test/specs/jsdoc/util/templateHelper.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index 5a1134129..a908e381e 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 a0cdf6763..a5e75f793 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');