-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ignore props/events with @ignore JSDoc tag
- Loading branch information
Showing
6 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Filter descriptors with given function. | ||
* @param {Object[] | {[name: string]: Object}} descriptors | ||
* A list of descriptors. | ||
* - vue-docgen-api < v4 ... descriptors is key-values | ||
* - vue-docgen-api >= v4 ... descriptors is an array of objects | ||
* @param {(descriptor: Object) => boolean} filterFn | ||
* Same as Array.prototype.filter but no index and self arguments. | ||
*/ | ||
function filterDescriptors(descriptors, filterFn) { | ||
if (!descriptors) { | ||
// return falsy values as-is | ||
return descriptors | ||
} | ||
|
||
if (descriptors instanceof Array) { | ||
return descriptors.filter(filterFn) | ||
} | ||
|
||
const entries = Object.entries(descriptors).filter(([, descriptor]) => | ||
filterFn(descriptor) | ||
) | ||
|
||
return entries.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {}) | ||
} | ||
|
||
exports.filterDescriptors = filterDescriptors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
describe('#filterDescriptors', () => { | ||
const { filterDescriptors } = require('./utils') | ||
|
||
it('Should apply filter function to an array of descriptors', () => { | ||
const input = [ | ||
{ | ||
name: 'foo', | ||
required: true | ||
}, | ||
{ | ||
name: 'bar', | ||
required: false | ||
} | ||
] | ||
|
||
const expected = [ | ||
{ | ||
name: 'foo', | ||
required: true | ||
} | ||
] | ||
|
||
expect(filterDescriptors(input, d => d.required)).toEqual(expected) | ||
}) | ||
|
||
it('Should apply filter function to key-value pairs', () => { | ||
const input = { | ||
foo: { | ||
name: 'foo', | ||
required: true | ||
}, | ||
bar: { | ||
name: 'bar', | ||
required: false | ||
} | ||
} | ||
|
||
const expected = { | ||
foo: { | ||
name: 'foo', | ||
required: true | ||
} | ||
} | ||
|
||
expect(filterDescriptors(input, d => d.required)).toEqual(expected) | ||
}) | ||
|
||
it('Should return falsy values as-is', () => { | ||
expect(filterDescriptors(null, d => d.required)).toBeNull() | ||
expect(filterDescriptors(void 0, d => d.required)).toBeUndefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script> | ||
export default { | ||
props: { | ||
/** | ||
* This must be ignored. | ||
* @ignore | ||
*/ | ||
foo: { | ||
type: String, | ||
default: 'foo' | ||
}, | ||
/** | ||
* Not ignored. | ||
*/ | ||
bar: { | ||
type: Number, | ||
default: Infinity | ||
} | ||
}, | ||
methods: { | ||
baz() { | ||
/** | ||
* This must be ignored. | ||
* @ignore | ||
*/ | ||
this.$emit('baz') | ||
/** | ||
* Not ignored. | ||
*/ | ||
this.$emit('qux') | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<!-- | ||
@slot Slots can't be ignored for now. | ||
@ignore | ||
--> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters