From 2dec7bd4e07a579cabc21d0f13c6ee14d449ca3d Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Wed, 30 Jul 2014 10:53:10 -0700 Subject: [PATCH] expose parsed type in doclets (#576) Author: Alexey Malutin (https://github.com/Alexey-Malutin) --- lib/jsdoc/schema.js | 56 ++++++++++++++++++++++++++++++++++ lib/jsdoc/tag.js | 3 +- lib/jsdoc/tag/type.js | 1 + test/fixtures/type.js | 13 ++++++++ test/specs/jsdoc/typeParser.js | 4 +++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/type.js create mode 100644 test/specs/jsdoc/typeParser.js diff --git a/lib/jsdoc/schema.js b/lib/jsdoc/schema.js index 0444c6f5..70e4b80f 100644 --- a/lib/jsdoc/schema.js +++ b/lib/jsdoc/schema.js @@ -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 + } + } + } + } } } }; diff --git a/lib/jsdoc/tag.js b/lib/jsdoc/tag.js index 142592a1..d0d267cb 100644 --- a/lib/jsdoc/tag.js +++ b/lib/jsdoc/tag.js @@ -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; diff --git a/lib/jsdoc/tag/type.js b/lib/jsdoc/tag/type.js index 1720d804..82bae38b 100644 --- a/lib/jsdoc/tag/type.js +++ b/lib/jsdoc/tag/type.js @@ -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) { diff --git a/test/fixtures/type.js b/test/fixtures/type.js new file mode 100644 index 00000000..e82ea86a --- /dev/null +++ b/test/fixtures/type.js @@ -0,0 +1,13 @@ +/** + * @param {number=} Optional + * @param {...number} Variable (repeatable) + * @param {*} All + * @param {?number} Nullable + * @param {!number} Non nullable + * @param {Array.} + * @param {Object.} + * @param {{a: string, b}} Record + * @param {Object.} + */ +function testFunction() { +} diff --git a/test/specs/jsdoc/typeParser.js b/test/specs/jsdoc/typeParser.js new file mode 100644 index 00000000..17da0b05 --- /dev/null +++ b/test/specs/jsdoc/typeParser.js @@ -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'); +}) \ No newline at end of file