don't use destructuring assignment

this fixes a JSHint error that cannot be suppressed.
This commit is contained in:
Jeff Williams 2012-07-04 14:34:46 -07:00
parent f7aacfd80c
commit 77f505f2a1
4 changed files with 49 additions and 38 deletions

View File

@ -312,7 +312,9 @@ function split(docletSrc) {
var parsedTag = $.match(/^(\S+)(:?\s+(\S[\s\S]*))?/);
if (parsedTag) {
var [, tagTitle, tagText] = parsedTag;
// we don't need parsedTag[0]
tagTitle = parsedTag[1];
tagText = parsedTag[2];
if (tagTitle) {
tagSrcs.push({

View File

@ -52,34 +52,29 @@ exports.Tag = function(tagTitle, tagBody, meta) {
/** The value property represents the result of parsing the tag text. */
this.value = {};
var [
/*Array.<string>*/ typeNames,
/*any*/ remainingText,
/*?boolean*/ optional,
/*?boolean*/ nullable,
/*?boolean*/ variable
] = jsdoc.tag.type.parse(this.text);
var tagType = jsdoc.tag.type.parse(this.text);
if (typeNames.length) {
if (tagType.type && tagType.type.length) {
this.value.type = {
names: typeNames,
optional: optional,
nullable: nullable,
variable: variable
names: tagType.type,
optional: tagType.optional,
nullable: tagType.nullable,
variable: tagType.variable
};
}
var remainingText = tagType.text;
if (remainingText) {
if (tagDef.canHaveName) {
var [paramName, paramDesc, paramOptional, paramDefault]
= parseParamText(remainingText);
var paramInfo = parseParamText(remainingText);
// note the dash is a special case: as a param name it means "no name"
if (paramName && paramName !== '-') { this.value.name = paramName; }
if (paramInfo.name && paramInfo.name !== '-') { this.value.name = paramInfo.name; }
if (paramDesc) { this.value.description = paramDesc; }
if (paramOptional) { this.value.optional = paramOptional; }
if (paramDefault) { this.value.defaultvalue = paramDefault; }
if (paramInfo.desc) { this.value.description = paramInfo.desc; }
if (paramInfo.optional) { this.value.optional = paramInfo.optional; }
if (paramInfo.default) { this.value.defaultvalue = paramInfo.default; }
}
else {
this.value.description = remainingText;
@ -140,5 +135,5 @@ function parseParamText(tagText) {
pdefault = RegExp.$2;
}
}
return [pname, pdesc, poptional, pdefault];
return { name: pname, desc: pdesc, optional: poptional, default: pdefault };
}

View File

@ -54,8 +54,8 @@ exports.defineTags = function(dictionary) {
// 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;
tagType = type.getTagType(text);
return tagType.type || text;
},
onTagged: function(doclet, tag) {
doclet.augment( firstWordOf(tag.value) );
@ -67,8 +67,8 @@ exports.defineTags = function(dictionary) {
dictionary.defineTag('borrows', {
mustHaveValue: true,
onTagged: function(doclet, tag) {
var [target, source] = parseBorrows(doclet, tag);
doclet.borrow(target, source);
var borrows = parseBorrows(doclet, tag);
doclet.borrow(borrows.target, borrows.source);
}
});
@ -625,11 +625,13 @@ function parseBorrows(doclet, tag) {
var m = /^(\S+)(?:\s+as\s+(\S+))?$/.exec(tag.text);
if (m) {
if (m[1] && m[2]) {
return [ m[1], m[2] ];
return { target: m[1], source: m[2] };
}
else if (m[1]) {
return [ m[1] ];
return { target: m[1] };
}
} else {
return {};
}
}

View File

@ -8,27 +8,39 @@
/**
@param {string} tagValue
@returns {Array.<string>}
@returns {object} Hash with type, text, optional, nullable, and variable properties
*/
exports.parse = function(tagValue) {
if (typeof tagValue !== 'string') { tagValue = ''; }
var type = '',
text = '',
count = 0,
tagType,
optional,
nullable,
variable;
[type, text] = getTagType(tagValue);
if (type === '') { text = tagValue; }
tagType = getTagType(tagValue);
type = tagType.type;
if (tagType.type === '') {
text = tagValue;
} else {
text = tagType.text;
}
[type, optional] = parseOptional(type);
[type, nullable] = parseNullable(type);
[type, variable] = parseVariable(type);
optional = parseOptional(type);
nullable = parseNullable(type);
variable = parseVariable(type);
type = variable.type || nullable.type || optional.type;
type = parseTypes(type); // make it into an array
return [type, text, optional, nullable, variable];
return {
type: type,
text: text,
optional: optional.optional,
nullable: nullable.nullable,
variable: variable.variable
};
}
function parseOptional(type) {
@ -40,7 +52,7 @@ function parseOptional(type) {
optional = true;
}
return [type, optional];
return { type: type, optional: optional };
}
function parseNullable(type) {
@ -52,7 +64,7 @@ function parseNullable(type) {
nullable = (RegExp.$1 === '?')? true : false;
}
return [type, nullable];
return { type: type, nullable: nullable };
}
function parseVariable(type) {
@ -64,7 +76,7 @@ function parseVariable(type) {
variable = true;
}
return [type, variable];
return { type: type, variable: variable };
}
function parseTypes(type) {
@ -110,7 +122,7 @@ function getTagType(tagValue) {
}
}
}
return [type, text];
return { type: type, text: text };
}
exports.getTagType = getTagType;