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 #83: Merge keywords and default values for aliases #84

Merged
merged 3 commits into from
Sep 24, 2021
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
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) {
alexprey marked this conversation as resolved.
Show resolved Hide resolved
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