diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index fe3f1848..91f0d971 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -167,7 +167,7 @@ function parseTypeText(text) { } function parseBorrows(doclet, tag) { - var m = /^(\S+)(?:\s+as\s+(\S+))?$/.exec(tag.text); + var m = /^([\s\S]+?)(?:\s+as\s+([\s\S]+))?$/.exec(tag.text); if (m) { if (m[1] && m[2]) { return { target: m[1], source: m[2] }; diff --git a/test/fixtures/borrowstag3.js b/test/fixtures/borrowstag3.js new file mode 100644 index 00000000..63012427 --- /dev/null +++ b/test/fixtures/borrowstag3.js @@ -0,0 +1,22 @@ +'use strict'; + +/** + * Remove whitespace from around a string. + * @param {string} str + */ +function trstr(str) {} + +var _util = { + /** Hidden utility function. */ + 'hidden util': function() {} +}; + +/** + * @namespace + * @borrows trstr as trim string + * @borrows util.hidden util as hidden + */ +var util = { + hidden: _util['trim string'], + 'trim string': trstr +}; diff --git a/test/specs/tags/borrowstag.js b/test/specs/tags/borrowstag.js index 4addc338..c2b1e6aa 100644 --- a/test/specs/tags/borrowstag.js +++ b/test/specs/tags/borrowstag.js @@ -1,11 +1,13 @@ 'use strict'; +function filterUndocumented($) { + return !($.undocumented); +} + describe('@borrows tag', function() { it('When a symbol has a @borrows-as tag, that is added to the symbol\'s "borrowed" property.', function() { var docSet = jasmine.getDocSetFromFile('test/fixtures/borrowstag.js'); - var util = docSet.getByLongname('util').filter(function($) { - return !($.undocumented); - })[0]; + var util = docSet.getByLongname('util').filter(filterUndocumented)[0]; expect(util.borrowed.length).toBe(1); expect(util.borrowed[0].from).toBe('trstr'); @@ -24,4 +26,15 @@ describe('@borrows tag', function() { expect(typeof strRtrim).toBe('object'); }); + + it('When a symbol has a `@borrows X as Y` tag, X and Y may contain whitespace.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/borrowstag3.js'); + var util = docSet.getByLongname('util').filter(filterUndocumented)[0]; + + expect(util.borrowed.length).toBe(2); + expect(util.borrowed[0].from).toBe('trstr'); + expect(util.borrowed[0].as).toBe('trim string'); + expect(util.borrowed[1].from).toBe('util.hidden util'); + expect(util.borrowed[1].as).toBe('hidden'); + }); });