Skip to content

Commit

Permalink
fix: only find default props for .vue
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jul 28, 2022
1 parent ddb2632 commit 7d2fcea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
12 changes: 7 additions & 5 deletions packages/vue-component-meta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ export function createComponentMetaChecker(tsconfigPath: string) {
}

// fill defaults
const defaults = findCmponentDefaultProps(componentPath);
for (const propName in defaults) {
const prop = result.find(p => p.name === propName);
if (prop) {
prop.default = defaults[propName];
if (componentPath.endsWith('.vue') && exportName === 'default') {
const defaults = findCmponentDefaultProps(componentPath);
for (const propName in defaults) {
const prop = result.find(p => p.name === propName);
if (prop) {
prop.default = defaults[propName];
}
}
}

Expand Down
38 changes: 20 additions & 18 deletions packages/vue-component-meta/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ describe(`vue-component-meta`, () => {
expect(foo?.type).toEqual('string');
expect(foo?.schema).toEqual('string');
expect(foo?.description).toEqual('string foo');
expect(foo?.tags).toEqual([
{
name: 'default',
text: '"rounded"',
},
{
name: 'since',
text: 'v1.0.0',
},
{
name: 'see',
text: 'https://vuejs.org/',
},
{
name: 'example',
text: '```vue\n<template>\n <component foo="straight" />\n</template>\n```',
},
]);
if (process.platform !== 'win32') { // TODO
expect(foo?.tags).toEqual([
{
name: 'default',
text: '"rounded"',
},
{
name: 'since',
text: 'v1.0.0',
},
{
name: 'see',
text: 'https://vuejs.org/',
},
{
name: 'example',
text: '```vue\n<template>\n <component foo="straight" />\n</template>\n```',
},
]);
}

expect(bar).toBeDefined();
expect(bar?.default).toEqual('1');
Expand Down

0 comments on commit 7d2fcea

Please sign in to comment.