Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/utils/__tests__/parseJsDoc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ describe('parseJsDoc', () => {
});
});

it('extracts jsdoc union type param', () => {
const docblock = `
@param {string|Object} bar
`;
expect(parseJsDoc(docblock)).toEqual({
description: null,
returns: null,
params: [{
name: 'bar',
type: {name: 'union', value: ['string', 'Object']},
description: null,
}],
});
});

it('extracts jsdoc optional', () => {
const docblock = `
@param {string=} bar
Expand Down Expand Up @@ -107,6 +122,20 @@ describe('parseJsDoc', () => {
});
});

it('extracts jsdoc mixed types', () => {
const docblock = `
@returns {*}
`;
expect(parseJsDoc(docblock)).toEqual({
description: null,
returns: {
type: {name: 'mixed'},
description: null,
},
params: [],
});
});

it('extracts description from jsdoc', () => {
const docblock = `
@returns The number
Expand Down
8 changes: 8 additions & 0 deletions src/utils/parseJsDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ type JsDoc = {
function getType(tag) {
if (!tag.type) {
return null;
} else if (tag.type.type === 'UnionType') {
// union type
return {name: 'union', value: tag.type.elements.map(function (element) {
return element.name;
})};
} else if (tag.type.type === 'AllLiteral') {
// return {*}
return {name: 'mixed'};
}
return {name: tag.type.name ? tag.type.name : tag.type.expression.name};
}
Expand Down