From 64ae4c013bf5456ca90180aeb8f5a7b1f4b3cd4c Mon Sep 17 00:00:00 2001 From: Jannon Date: Wed, 21 Mar 2012 01:58:41 -0700 Subject: [PATCH] Allow braces for @extends values (e.g. {Type}) Fixes#96. Includes test --- rhino_modules/jsdoc/tag.js | 4 +- .../jsdoc/tag/dictionary/definitions.js | 6 +++ rhino_modules/jsdoc/tag/type.js | 51 +++++++++++-------- test/cases/augmentstag.js | 2 +- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/rhino_modules/jsdoc/tag.js b/rhino_modules/jsdoc/tag.js index c68f6a2f..3c672aac 100644 --- a/rhino_modules/jsdoc/tag.js +++ b/rhino_modules/jsdoc/tag.js @@ -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, diff --git a/rhino_modules/jsdoc/tag/dictionary/definitions.js b/rhino_modules/jsdoc/tag/dictionary/definitions.js index 8841b624..9d833938 100644 --- a/rhino_modules/jsdoc/tag/dictionary/definitions.js +++ b/rhino_modules/jsdoc/tag/dictionary/definitions.js @@ -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) ); } diff --git a/rhino_modules/jsdoc/tag/type.js b/rhino_modules/jsdoc/tag/type.js index 812d7fbd..d243c4b1 100644 --- a/rhino_modules/jsdoc/tag/type.js +++ b/rhino_modules/jsdoc/tag/type.js @@ -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(); diff --git a/test/cases/augmentstag.js b/test/cases/augmentstag.js index 15e6c514..a30a1e22 100644 --- a/test/cases/augmentstag.js +++ b/test/cases/augmentstag.js @@ -39,7 +39,7 @@ Bar.prototype.method2 = function() {}; /** * @constructor - * @extends Bar + * @extends {Bar} */ function Baz() { /** Override prop1 */