From 37fff4b02273915848e45745d1635b74b177f3c3 Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Mon, 28 Jan 2019 10:23:57 -0600 Subject: [PATCH] fix: allow documenting of propTypes and vueTypes props --- src/script-handlers/__tests__/propHandler.ts | 33 ++++++++++++++++++++ src/script-handlers/propHandler.ts | 5 +++ 2 files changed, 38 insertions(+) diff --git a/src/script-handlers/__tests__/propHandler.ts b/src/script-handlers/__tests__/propHandler.ts index 7f33f65..e0e715b 100644 --- a/src/script-handlers/__tests__/propHandler.ts +++ b/src/script-handlers/__tests__/propHandler.ts @@ -152,6 +152,39 @@ describe('propHandler', () => { type: { name: 'boolean' }, }) }) + + it('should still return props with vue-types', () => { + const src = [ + 'export default {', + ' props:{', + ' test: VueTypes.shape({', + ' line1: String,', + ' line2: String,', + ' })', + ' }', + '}', + ].join('\n') + tester(src, { + type: { + func: true, + }, + }) + }) + + it('should still return props with prop-types', () => { + const src = [ + 'export default {', + ' props:{', + " test: PropTypes.oneOf(['News', 'Photos'])", + ' }', + '}', + ].join('\n') + tester(src, { + type: { + func: true, + }, + }) + }) }) describe('required', () => { diff --git a/src/script-handlers/propHandler.ts b/src/script-handlers/propHandler.ts index ee690ef..bc0f0b7 100644 --- a/src/script-handlers/propHandler.ts +++ b/src/script-handlers/propHandler.ts @@ -70,6 +70,11 @@ export default function propHandler(documentation: Documentation, path: NodePath } else if (bt.isIdentifier(propValuePath.node)) { // contents of the prop is it's type propDescriptor.type = getTypeFromTypePath(propValuePath) + } else { + propDescriptor.type = { + name: recast.print(prop.get('value')).code, + func: true, + } } }) } else if (bt.isArrayExpression(propsValuePath.node)) {