allow symbol names that contain whitespace to be borrowed (#818)

This commit is contained in:
Jeff Williams 2015-03-10 17:37:48 -07:00
parent be77aa4344
commit 7ca432d587
3 changed files with 39 additions and 4 deletions

View File

@ -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] };

22
test/fixtures/borrowstag3.js vendored Normal file
View File

@ -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
};

View File

@ -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');
});
});