From 7c4bbe3426e39d5639f84a6388ab96b0ef78ea42 Mon Sep 17 00:00:00 2001 From: ekhaled Date: Wed, 8 Sep 2021 16:54:55 +0100 Subject: [PATCH 1/3] add failing test --- .../integration/data/data.export.aliace.svelte | 15 ++++++++++++--- test/svelte3/integration/data/data.spec.js | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/test/svelte3/integration/data/data.export.aliace.svelte b/test/svelte3/integration/data/data.export.aliace.svelte index 0e3fc1f..61b0078 100644 --- a/test/svelte3/integration/data/data.export.aliace.svelte +++ b/test/svelte3/integration/data/data.export.aliace.svelte @@ -1,11 +1,20 @@ \ No newline at end of file diff --git a/test/svelte3/integration/data/data.spec.js b/test/svelte3/integration/data/data.spec.js index 674be7c..3bac4ec 100644 --- a/test/svelte3/integration/data/data.spec.js +++ b/test/svelte3/integration/data/data.spec.js @@ -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'); @@ -429,12 +429,25 @@ describe('SvelteDoc v3 - Props', () => { expect(prop.type).to.eql({ kind: 'type', type: 'Array', text: 'Array' }); 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); From 6fd4ab88c0bcdb0544fcac8f2320ac1649b6d0d2 Mon Sep 17 00:00:00 2001 From: ekhaled Date: Wed, 8 Sep 2021 16:57:57 +0100 Subject: [PATCH 2/3] merge default values --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 7b8d287..e4dff7c 100644 --- a/index.js +++ b/index.js @@ -77,6 +77,10 @@ function mergeItems(itemType, currentItem, newItem, ignoreLocations) { currentItem.description = newItem.description; } + if (!currentItem.defaultValue && newItem.defaultValue) { + currentItem.defaultValue = newItem.defaultValue; + } + if (!currentItem.type || currentItem.type.type === 'any') { if (newItem.type && newItem.type.type !== 'any') { currentItem.type = newItem.type; From edc2739627862f1cea123650672ac3483a0d3e9a Mon Sep 17 00:00:00 2001 From: ekhaled Date: Wed, 8 Sep 2021 17:08:07 +0100 Subject: [PATCH 3/3] update merge logic to merge keywords and defaultValue --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e4dff7c..4adffa3 100644 --- a/index.js +++ b/index.js @@ -77,7 +77,7 @@ function mergeItems(itemType, currentItem, newItem, ignoreLocations) { currentItem.description = newItem.description; } - if (!currentItem.defaultValue && newItem.defaultValue) { + if (!currentItem.defaultValue && typeof newItem.defaultValue != 'undefined') { currentItem.defaultValue = newItem.defaultValue; } @@ -87,7 +87,7 @@ function mergeItems(itemType, currentItem, newItem, ignoreLocations) { } } - if (!currentItem.keywords && newItem.keywords) { + if ((!currentItem.keywords || currentItem.keywords.length == 0) && newItem.keywords) { currentItem.keywords = newItem.keywords; }