expose parsed type in doclets (#576)

Author: Alexey Malutin (https://github.com/Alexey-Malutin)
This commit is contained in:
Jeff Williams 2014-07-30 10:53:10 -07:00
parent cfd9743eaa
commit 2dec7bd4e0
5 changed files with 76 additions and 1 deletions

View File

@ -110,6 +110,62 @@ var TYPE_PROPERTY_SCHEMA = exports.TYPE_PROPERTY_SCHEMA = {
items: {
type: STRING
}
},
// type parser output
parsedType: {
id: '#parsedType',
type: OBJECT,
additionalProperties: false,
properties: {
type: {
type: STRING,
enum: [
'AllLiteral',
'FieldType',
'FunctionType',
'NameExpression',
'NullLiteral',
'RecordType',
'TypeApplication',
'TypeUnion',
'UndefinedLiteral',
'UnknownLiteral'
]
},
expression: {
'$ref': '#parsedType'
},
applications: {
type : ARRAY,
items: {
'$ref': '#parsedType'
}
},
name: STRING,
elements: {
type : ARRAY,
items: {
'$ref': '#parsedType'
}
},
params: ARRAY,
reservedWord: BOOLEAN,
nullable: BOOLEAN,
optional: BOOLEAN,
repeatable: BOOLEAN,
fields: {
type: ARRAY,
items: {
type: OBJECT,
additionalProperties: false,
properties: {
type: STRING,
key: STRING,
value: OBJECT
}
}
}
}
}
}
};

View File

@ -69,7 +69,8 @@ function processTagText(tag, tagDef) {
if (tagType.type) {
if (tagType.type.length) {
tag.value.type = {
names: tagType.type
names: tagType.type,
parsedType: tagType.parsedType
};
}
tag.value.optional = tagType.optional;

View File

@ -254,6 +254,7 @@ function parseTypeExpression(tagInfo) {
}
tagInfo.type = tagInfo.type.concat( getTypeStrings(parsedType, true) );
tagInfo.parsedType = parsedType;
// Catharsis and JSDoc use the same names for 'optional' and 'nullable'...
['optional', 'nullable'].forEach(function(key) {

13
test/fixtures/type.js vendored Normal file
View File

@ -0,0 +1,13 @@
/**
* @param {number=} Optional
* @param {...number} Variable (repeatable)
* @param {*} All
* @param {?number} Nullable
* @param {!number} Non nullable
* @param {Array.<string>}
* @param {Object.<string, *>}
* @param {{a: string, b}} Record
* @param {Object.<string, {a, b}}>}
*/
function testFunction() {
}

View File

@ -0,0 +1,4 @@
describe("@param tag", function() {
//To put doclets to jasmine.parseResults for jsdoc/schema test.
var docSet = jasmine.getDocSetFromFile('test/fixtures/type.js');
})