Skip to content

Commit

Permalink
Merge pull request #84 from ekhaled/alias-default-value
Browse files Browse the repository at this point in the history
fix #83: Merge keywords and default values for aliases
  • Loading branch information
alexprey authored Sep 24, 2021
2 parents 4abe1ac + edc2739 commit 8afe9e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ function mergeItems(itemType, currentItem, newItem, ignoreLocations) {
currentItem.description = newItem.description;
}

if (!currentItem.defaultValue && typeof newItem.defaultValue != 'undefined') {
currentItem.defaultValue = newItem.defaultValue;
}

if (!currentItem.type || currentItem.type.type === 'any') {
if (newItem.type && newItem.type.type !== 'any') {
currentItem.type = newItem.type;
}
}

if (!currentItem.keywords && newItem.keywords) {
if ((!currentItem.keywords || currentItem.keywords.length == 0) && newItem.keywords) {
currentItem.keywords = newItem.keywords;
}

Expand Down
15 changes: 12 additions & 3 deletions test/svelte3/integration/data/data.export.aliace.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<script>
/**
* Description for variable that must be exported later
/**
* Description for variable that must be exported later
* @type {Array<string>}
*/
const classes = [ 'btn' ];
export {
export {
classes as class
};
/**
* Switch parameter
* @type {'main' | 'sidebar'}
*
*/
let switchValue = "main";
export {switchValue as switch}
</script>
17 changes: 15 additions & 2 deletions test/svelte3/integration/data/data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ describe('SvelteDoc v3 - Props', () => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.data, 'Document data should be parsed').to.exist;

expect(doc.data.length).to.equal(2);
expect(doc.data.length).to.equal(4);

const prop = doc.data.find(d => d.name === 'class');

Expand All @@ -429,12 +429,25 @@ describe('SvelteDoc v3 - Props', () => {
expect(prop.type).to.eql({ kind: 'type', type: 'Array<string>', text: 'Array<string>' });

expect(prop.locations, 'Code location should be parsed').to.be.exist;
expect(prop.locations[0]).is.deep.equals({ start: 181, end: 186 });
expect(prop.locations[0]).is.deep.equals({ start: 178, end: 183 });

const localProp = doc.data.find(d => d.name === 'classes');

expect(localProp, 'Local prop definition also must be provided').to.exist;

const prop2 = doc.data.find(d => d.name === 'switch');
expect(prop2).to.exist;
expect(prop2.name, 'Aliace name must be exposed instead of original name').to.equal('switch');
expect(prop2.localName, 'Local name must be stored').to.equal('switchValue');
expect(prop2.defaultValue).to.equal("main");
expect(prop2.keywords).to.exist;
expect(prop2.keywords.length).to.equal(1);

const keyword = prop2.keywords[0];

expect(keyword.name).to.equal('type');
expect(keyword.description).to.equal("{'main' | 'sidebar'}");

done();
}).catch(e => {
done(e);
Expand Down

0 comments on commit 8afe9e7

Please sign in to comment.