From 237df707ad4344434a08e713438424484befb4fd Mon Sep 17 00:00:00 2001 From: atanasster Date: Mon, 17 May 2021 15:30:05 +0300 Subject: [PATCH] fix: react-docgen clean quotes on default value --- props-info/react-docgen/src/transform-props.ts | 3 +++ .../react-docgen/test/__snapshots__/prop-types.test.ts.snap | 1 + props-info/react-docgen/test/fixtures/prop-types/prop-types.js | 1 + 3 files changed, 5 insertions(+) diff --git a/props-info/react-docgen/src/transform-props.ts b/props-info/react-docgen/src/transform-props.ts index 8e6847db9..7dd4ae0c9 100644 --- a/props-info/react-docgen/src/transform-props.ts +++ b/props-info/react-docgen/src/transform-props.ts @@ -19,6 +19,9 @@ const rdPropToCCProp = (rdProp: RdPropInfo): PropType => { } if (rdProp.defaultValue !== null && rdProp.defaultValue !== undefined) { prop.defaultValue = rdProp.defaultValue.value ?? rdProp.defaultValue; + if (typeof prop.defaultValue === 'string') { + prop.defaultValue = cleanQuotes(prop.defaultValue); + } } let type: Partial = {}; if (rdProp.type) { diff --git a/props-info/react-docgen/test/__snapshots__/prop-types.test.ts.snap b/props-info/react-docgen/test/__snapshots__/prop-types.test.ts.snap index 6899c7bd9..39414be74 100644 --- a/props-info/react-docgen/test/__snapshots__/prop-types.test.ts.snap +++ b/props-info/react-docgen/test/__snapshots__/prop-types.test.ts.snap @@ -44,6 +44,7 @@ are all optional.", }, }, "optionalEnum": Object { + "defaultValue": "News", "description": "You can ensure that your prop is limited to specific values by treating it as an enum.", "type": Object { diff --git a/props-info/react-docgen/test/fixtures/prop-types/prop-types.js b/props-info/react-docgen/test/fixtures/prop-types/prop-types.js index 665c8f2d9..40dec5458 100644 --- a/props-info/react-docgen/test/fixtures/prop-types/prop-types.js +++ b/props-info/react-docgen/test/fixtures/prop-types/prop-types.js @@ -104,6 +104,7 @@ MyComponent.propTypes = { MyComponent.defaultProps = { optionalNumber: 21, + optionalEnum: 'News', }; export default MyComponent;