Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit 97808d2

Browse files
authored
fix: make sure every prop is rendered even if no type (#120)
vue-styleguidist/vue-styleguidist#222
1 parent f1be657 commit 97808d2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/script-handlers/__tests__/propHandler.ts

+15
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ describe('propHandler', () => {
198198
},
199199
})
200200
})
201+
202+
it('should still return props with delegated types', () => {
203+
const src = [
204+
'export default {',
205+
' props: {',
206+
" toto",
207+
' }',
208+
'}',
209+
].join('\n')
210+
tester(src, {
211+
type: {
212+
name: "undefined",
213+
},
214+
})
215+
})
201216
})
202217

203218
describe('required', () => {

src/script-handlers/propHandler.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ export function describeType(
108108
}
109109
}
110110

111+
const VALID_VUE_TYPES = ["string", "number", "boolean", "array", "object", "date", "function", "symbol"]
112+
111113
function getTypeFromTypePath(typePath: NodePath): { name: string; func?: boolean } {
112114
const typeNode = typePath.node
113115
const typeName = bt.isArrayExpression(typeNode)
114-
? typeNode.elements
115-
.map(t => (t && bt.isIdentifier(t) ? t.name.toLowerCase() : 'undefined'))
116+
? typePath.get("elements")
117+
.map((t: NodePath) => getTypeFromTypePath(t).name)
116118
.join('|')
117-
: typeNode && bt.isIdentifier(typeNode)
119+
: typeNode && bt.isIdentifier(typeNode) && VALID_VUE_TYPES.indexOf(typeNode.name.toLowerCase()) > -1
118120
? typeNode.name.toLowerCase()
119121
: 'undefined'
120122
return {

0 commit comments

Comments
 (0)