From 4e1a4a7b3dac00a7a4b3fe31473c25194e35456f Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 11 Mar 2021 16:06:24 +1100 Subject: [PATCH 1/2] Fix issue introduced into vue docgen w/ strings --- addons/docs/src/lib/docgen/createPropDef.ts | 10 ++++++++-- .../src/lib/docgen/extractDocgenProps.test.ts | 19 +++++++++++++++++++ addons/docs/src/lib/docgen/types.ts | 1 + examples/vue-3-cli/src/stories/Button.vue | 8 +++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/addons/docs/src/lib/docgen/createPropDef.ts b/addons/docs/src/lib/docgen/createPropDef.ts index 08baf92b7bc8..13678c1cda72 100644 --- a/addons/docs/src/lib/docgen/createPropDef.ts +++ b/addons/docs/src/lib/docgen/createPropDef.ts @@ -23,12 +23,18 @@ function createDefaultValue( type: DocgenType ): PropDefaultValue { if (defaultValue != null) { - const { value, computed } = defaultValue; + const { value, computed, func } = defaultValue; + + console.log(defaultValue); if (!isDefaultValueBlacklisted(value)) { // Work around a bug in `react-docgen-typescript-loader`, which returns 'string' for a string // default, instead of "'string'" -- which is incorrect (PR to RDT to follow) - if (typeof computed === 'undefined' && type.name === 'string') { + if ( + typeof computed === 'undefined' && + typeof func === 'undefined' && + type.name === 'string' + ) { return createSummaryValue(JSON.stringify(value)); } diff --git a/addons/docs/src/lib/docgen/extractDocgenProps.test.ts b/addons/docs/src/lib/docgen/extractDocgenProps.test.ts index cd47f290068d..8d76693dabb2 100644 --- a/addons/docs/src/lib/docgen/extractDocgenProps.test.ts +++ b/addons/docs/src/lib/docgen/extractDocgenProps.test.ts @@ -93,6 +93,25 @@ TypeSystems.forEach((x) => { expect(propDef.required).toBe(false); expect(propDef.defaultValue.summary).toBe('"Default"'); }); + + it('should map defaults docgen info properly, vue', () => { + const component = createComponent({ + ...createStringType(x), + description: 'Hey! Hey!', + defaultValue: { + value: "'Default'", + func: false, + }, + }); + + const { propDef } = extractComponentProps(component, DOCGEN_SECTION)[0]; + + expect(propDef.name).toBe(PROP_NAME); + expect(propDef.type.summary).toBe('string'); + expect(propDef.description).toBe('Hey! Hey!'); + expect(propDef.required).toBe(false); + expect(propDef.defaultValue.summary).toBe("'Default'"); + }); } it('should remove JSDoc tags from the description', () => { diff --git a/addons/docs/src/lib/docgen/types.ts b/addons/docs/src/lib/docgen/types.ts index bfddccd66425..0a46b8376ba3 100644 --- a/addons/docs/src/lib/docgen/types.ts +++ b/addons/docs/src/lib/docgen/types.ts @@ -33,6 +33,7 @@ export interface DocgenTypeScriptType extends DocgenType {} export interface DocgenPropDefaultValue { value: string; computed?: boolean; + func?: boolean; } export interface DocgenInfo { diff --git a/examples/vue-3-cli/src/stories/Button.vue b/examples/vue-3-cli/src/stories/Button.vue index 9f844977c19e..bb795d041af9 100644 --- a/examples/vue-3-cli/src/stories/Button.vue +++ b/examples/vue-3-cli/src/stories/Button.vue @@ -1,5 +1,7 @@