Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: resolve typescript component that extend as VueCosntructor #474

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ describe('resolveExportedComponent', () => {
)
expect(resolveExportedComponent(ast).size).toBe(1)
})

it('should return exported typescript extend style components', () => {
const ast = babylon({ plugins: ['typescript'] }).parse(
['export default Vue.extend({})'].join('\n')
)
expect(resolveExportedComponent(ast).size).toBe(1)
})

it('should return exported typescript extend custom VueConstructor', () => {
const ast = babylon({ plugins: ['typescript'] }).parse(
['export default (Vue as VueConstructor<Vue & SomeInterface>).extend({})'].join('\n')
)
expect(resolveExportedComponent(ast).size).toBe(1)
})
})
11 changes: 7 additions & 4 deletions packages/vue-docgen-api/src/utils/resolveExportedComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ function isComponentDefinition(path: NodePath): boolean {
(bt.isVariableDeclarator(path.node) &&
path.node.init &&
bt.isObjectExpression(path.node.init)) ||
// export default Vue.extends({})
// export default Vue.extend({})
(bt.isCallExpression(path.node) &&
bt.isMemberExpression(path.node.callee) &&
bt.isIdentifier(path.node.callee.object) &&
path.node.callee.object.name === 'Vue' &&
path.node.callee.property.name === 'extend') ||
path.node.callee.property.name === 'extend' &&
((bt.isIdentifier(path.node.callee.object) && path.node.callee.object.name === 'Vue') ||
// or export default (Vue as VueConstructor<Vue>).extend({})
(bt.isTSAsExpression(path.node.callee.object) &&
bt.isIdentifier(path.node.callee.object.expression) &&
path.node.callee.object.expression.name === 'Vue'))) ||
// export default class MyComp extends VueComp
bt.isClassDeclaration(path.node)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function renderShape(props) {
return rows
}

const defaultValueBlacklist = ['null', 'undefined']
const defaultValueBlacklist = ['null', 'undefined', "''", '""']

function renderDefault(prop) {
// Workaround for issue https://github.com/reactjs/react-docgen/issues/221
Expand All @@ -111,7 +111,7 @@ function renderDefault(prop) {
const propName = prop.type.name

if (defaultValueBlacklist.indexOf(prop.defaultValue.value) > -1) {
return <Code>{showSpaces(unquote(prop.defaultValue.value))}</Code>
return <Code>{prop.defaultValue.value}</Code>
} else if (propName === 'func' || propName === 'function') {
return (
<Text
Expand Down