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

Commit 58f1318

Browse files
authored
fix: props typed immediately with array return composite (#109)
Fixes #108
1 parent a4e5bcb commit 58f1318

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/script-handlers/__tests__/propHandler.ts

+13
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ describe('propHandler', () => {
138138
})
139139
})
140140

141+
it('should return the right props composite string|number', () => {
142+
const src = `
143+
export default {
144+
props: {
145+
test: [String, Number]
146+
}
147+
}
148+
`
149+
tester(src, {
150+
type: { name: 'string|number' },
151+
})
152+
})
153+
141154
it('should deduce the prop type from the default value', () => {
142155
const src = `
143156
export default {

src/script-handlers/propHandler.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ export default function propHandler(documentation: Documentation, path: NodePath
4747
propDescriptor.description = jsDoc.description
4848
}
4949

50-
if (bt.isArrayExpression(propValuePath.node)) {
51-
// I am not sure this case is valid vuejs
52-
propDescriptor.type = { name: 'array' }
50+
if (bt.isArrayExpression(propValuePath.node) || bt.isIdentifier(propValuePath.node)) {
51+
// if it's an immediately typed property, resolve its type immediately
52+
propDescriptor.type = getTypeFromTypePath(propValuePath)
5353
} else if (bt.isObjectExpression(propValuePath.node)) {
54+
// standard default + type + required
5455
const propPropertiesPath = propValuePath
5556
.get('properties')
5657
.filter((p: NodePath) => bt.isObjectProperty(p.node)) as Array<
@@ -65,10 +66,8 @@ export default function propHandler(documentation: Documentation, path: NodePath
6566

6667
// default
6768
describeDefault(propPropertiesPath, propDescriptor)
68-
} else if (bt.isIdentifier(propValuePath.node)) {
69-
// contents of the prop is it's type
70-
propDescriptor.type = getTypeFromTypePath(propValuePath)
7169
} else {
70+
// in any other case, just display the code for the typing
7271
propDescriptor.type = {
7372
name: recast.print(prop.get('value')).code,
7473
func: true,

0 commit comments

Comments
 (0)