Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description
"
/**
* This is a thing
* @default myDefaultValue
* @deprecated Use the other field instead
* @default myDefaultValue
* @deprecated Use the other field instead
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description with 1 json tag 1`] = `
"
/**
* This is a thing
* @default {\\"myDefault\\":\\"Value\\"}
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description with 1 tag 1`] = `
"
/**
* This is a thing
* @default myDefaultValue
* @default myDefaultValue
*/"
`;

Expand All @@ -28,7 +36,14 @@ exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR without a descripti
"
/**
* @default myDefaultValue
* @deprecated Use the other field instead
* @deprecated Use the other field instead
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR without a description with 1 json tag 1`] = `
"
/**
* @default {\\"myDefault\\":\\"Value\\"}
*/"
`;

Expand All @@ -46,7 +61,7 @@ exports[`language-typescript DEFAULT_ENUM_FORMATTER w/ deprecated value 1`] = `

/**
* value A
* @deprecated Bad
* @deprecated Bad
*/
a = 'a',

Expand Down
11 changes: 11 additions & 0 deletions packages/language-typescript/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ describe('language-typescript', () => {
tags: [{ tag: 'default', value: 'myDefaultValue' }]
})).toMatchSnapshot();
});
it('with 1 json tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
description: 'This is a thing',
tags: [{ tag: 'default', value: { myDefault: 'Value' } }]
})).toMatchSnapshot();
});
it('with >1 tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
description: 'This is a thing',
Expand All @@ -141,6 +147,11 @@ describe('language-typescript', () => {
tags: [{ tag: 'default', value: 'myDefaultValue' }]
})).toMatchSnapshot();
});
it('with 1 json tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
tags: [{ tag: 'default', value: { myDefault: 'Value' } }]
})).toMatchSnapshot();
});
it('with >1 tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
tags: [
Expand Down
16 changes: 13 additions & 3 deletions packages/language-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ ${interfaces}
const fixDescriptionDocblock: (description?: string) => string | undefined = description =>
description ? description.replace(/\n/g, '\n* ') : description;

export const DEFAULT_DOCUMENTATION_GENERATOR: GenerateDocumentation = ({ description, tags = [] }) => (description || tags.length) ? `
export const DEFAULT_DOCUMENTATION_GENERATOR: GenerateDocumentation = ({ description, tags = [] }) => {
if (!description && !tags.length) {
return '';
}
const arr: Array<string | undefined> = [
fixDescriptionDocblock(description),
...tags.map(({ tag, value }) =>
`@${tag} ${typeof value === 'object' ? JSON.stringify(value) : value}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should just JSON.stringify everything, that way strings are quoted as well. What do you think?

@miafoo miafoo Jun 2, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty indifferent about it. I guess the main disadvantage with it is that it all looks like strings now, even numbers (not counting objects which looks like objects).

];
return `
/**
* ${filterAndJoinArray([fixDescriptionDocblock(description), ...tags.map(({ tag, value }) => `@${tag} ${value}`)], '\n* ')}
*/` : '';
* ${filterAndJoinArray(arr, '\n * ')}
*/`;
};

export const DEFAULT_OPTIONS: IFromQueryOptions = {
wrapList: DEFAULT_WRAP_LIST,
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

export interface IJSDocTag {
tag: string;
value: string;
value: string | Object;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use lowercase object?

}

export interface IFieldDocumentation {
Expand Down