Allow braces for @extends values (e.g. {Type})

Fixes#96.  Includes test
This commit is contained in:
Jannon 2012-03-21 01:58:41 -07:00
parent 60730696c7
commit 64ae4c013b
4 changed files with 39 additions and 24 deletions

View File

@ -49,7 +49,7 @@ exports.Tag = function(tagTitle, tagBody, meta) {
if (tagDef.canHaveType) {
/** The value propertiy represents the result of parsing the tag text. */
/** The value property represents the result of parsing the tag text. */
this.value = {};
var [
@ -59,7 +59,7 @@ exports.Tag = function(tagTitle, tagBody, meta) {
/*?boolean*/ nullable,
/*?boolean*/ variable
] = jsdoc.tag.type.parse(this.text);
if (typeNames.length) {
this.value.type = {
names: typeNames,

View File

@ -51,6 +51,12 @@ exports.defineTags = function(dictionary) {
// I add on to that
dictionary.defineTag('augments', {
mustHaveValue: true,
// Allow augments value to be specified as a normal type, e.g. {Type}
onTagText: function(text) {
var type = require('jsdoc/tag/type'),
[tp, tx] = type.getTagType(text);
return tp || text;
},
onTagged: function(doclet, tag) {
doclet.augment( firstWordOf(tag.value) );
}

View File

@ -19,27 +19,7 @@ exports.parse = function(tagValue) {
nullable,
variable;
// type expressions start with '{'
if (tagValue[0] === '{') {
count++;
// find matching closer '}'
for (var i = 1, leni = tagValue.length; i < leni; i++) {
if (tagValue[i] === '\\') { i++; continue; } // backslash escapes the next character
if (tagValue[i] === '{') { count++; }
else if (tagValue[i] === '}') { count--; }
if (count === 0) {
type = trim(tagValue.slice(1, i))
.replace(/\\\{/g, '{') // unescape escaped curly braces
.replace(/\\\}/g, '}');
text = trim(tagValue.slice(i+1));
break;
}
}
}
[type, text] = getTagType(tagValue);
if (type === '') { text = tagValue; }
[type, optional] = parseOptional(type);
@ -105,6 +85,35 @@ function parseTypes(type) {
return types;
}
function getTagType(tagValue) {
var type = '',
text = '',
count = 0;
// type expressions start with '{'
if (tagValue[0] === '{') {
count++;
// find matching closer '}'
for (var i = 1, leni = tagValue.length; i < leni; i++) {
if (tagValue[i] === '\\') { i++; continue; } // backslash escapes the next character
if (tagValue[i] === '{') { count++; }
else if (tagValue[i] === '}') { count--; }
if (count === 0) {
type = trim(tagValue.slice(1, i))
.replace(/\\\{/g, '{') // unescape escaped curly braces
.replace(/\\\}/g, '}');
text = trim(tagValue.slice(i+1));
break;
}
}
}
return [type, text];
}
exports.getTagType = getTagType;
/** @private */
function trim(text) {
return text.trim();

View File

@ -39,7 +39,7 @@ Bar.prototype.method2 = function() {};
/**
* @constructor
* @extends Bar
* @extends {Bar}
*/
function Baz() {
/** Override prop1 */