Skip to content

fix: Correctly and recursively parse jsdoc types #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2018
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
5 changes: 4 additions & 1 deletion src/handlers/__tests__/componentMethodsJsDocHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import Documentation from '../../Documentation';
import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler';

describe('componentMethodsHandler', () => {
describe('componentMethodsJsDocHandler', () => {
let documentation;

beforeEach(() => {
Expand Down Expand Up @@ -76,6 +76,7 @@ describe('componentMethodsHandler', () => {
{
name: 'test',
description: null,
optional: false,
type: { name: 'string' },
},
],
Expand Down Expand Up @@ -121,6 +122,7 @@ describe('componentMethodsHandler', () => {
{
name: 'test',
description: null,
optional: false,
type: { name: 'number' },
},
],
Expand Down Expand Up @@ -166,6 +168,7 @@ describe('componentMethodsHandler', () => {
{
name: 'test',
description: 'The test',
optional: false,
type: null,
},
],
Expand Down
189 changes: 189 additions & 0 deletions src/utils/__tests__/__snapshots__/parseJsDoc-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parseJsDoc @param extracts jsdoc description 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": "test",
"name": "bar",
"optional": false,
"type": null,
},
],
"returns": null,
}
`;

exports[`parseJsDoc @param extracts jsdoc empty description 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": null,
"name": "bar",
"optional": false,
"type": Object {
"name": "string",
},
},
],
"returns": null,
}
`;

exports[`parseJsDoc @param extracts jsdoc optional 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": null,
"name": "bar",
"optional": true,
"type": Object {
"name": "string",
},
},
],
"returns": null,
}
`;

exports[`parseJsDoc @param extracts jsdoc typed array 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": null,
"name": "bar",
"optional": false,
"type": Object {
"elements": Array [
Object {
"name": "string",
},
Object {
"name": "number",
},
],
"name": "tuple",
},
},
],
"returns": null,
}
`;

exports[`parseJsDoc @param extracts jsdoc union type param 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": null,
"name": "bar",
"optional": false,
"type": Object {
"elements": Array [
Object {
"name": "string",
},
Object {
"name": "Object",
},
Object {
"elements": Array [
Object {
"name": "some",
},
],
"name": "Array",
},
],
"name": "union",
},
},
],
"returns": null,
}
`;

exports[`parseJsDoc @returns extracts description from jsdoc 1`] = `
Object {
"description": null,
"params": Array [],
"returns": Object {
"description": "The number",
"type": null,
},
}
`;

exports[`parseJsDoc @returns extracts jsdoc mixed types 1`] = `
Object {
"description": null,
"params": Array [],
"returns": Object {
"description": null,
"type": Object {
"name": "mixed",
},
},
}
`;

exports[`parseJsDoc @returns extracts jsdoc typed array 1`] = `
Object {
"description": null,
"params": Array [
Object {
"description": null,
"name": "bar",
"optional": false,
"type": Object {
"elements": Array [
Object {
"name": "string",
},
Object {
"name": "number",
},
],
"name": "tuple",
},
},
],
"returns": null,
}
`;

exports[`parseJsDoc @returns extracts jsdoc types 1`] = `
Object {
"description": null,
"params": Array [],
"returns": Object {
"description": null,
"type": Object {
"name": "string",
},
},
}
`;

exports[`parseJsDoc @returns works with @return 1`] = `
Object {
"description": null,
"params": Array [],
"returns": Object {
"description": "The number",
"type": null,
},
}
`;

exports[`parseJsDoc description extracts the method description in jsdoc 1`] = `
Object {
"description": "Don't use this!",
"params": Array [],
"returns": null,
}
`;
Loading