From c21668e93a4b92a9681717b219c43b0698183821 Mon Sep 17 00:00:00 2001 From: "Alexey Mulyukin (alexprey)" Date: Fri, 19 Feb 2021 16:18:47 +0300 Subject: [PATCH] fix(#61): Parse slot parameters description from comment --- lib/jsdoc.js | 1 + lib/v3/template.js | 12 ++++++--- lib/v3/v3-utils.js | 7 ++++-- .../integration/slots/slot.parameters.svelte | 4 +++ test/svelte3/integration/slots/slots.spec.js | 17 +++++++++++-- typings.d.ts | 25 ++++++++++++++++++- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/lib/jsdoc.js b/lib/jsdoc.js index 41434e9..9268203 100644 --- a/lib/jsdoc.js +++ b/lib/jsdoc.js @@ -254,6 +254,7 @@ module.exports = { parseJSTypeFromValueNode, convertToJsDocComment, + getDefaultJSDocType, DEFAULT_TYPE }; diff --git a/lib/v3/template.js b/lib/v3/template.js index 359ffb9..e8781ab 100644 --- a/lib/v3/template.js +++ b/lib/v3/template.js @@ -151,20 +151,24 @@ class TemplateParser extends EventEmitter { .filter(name => name.length > 0 && name !== 'name') .map(name => ({ name: name, - visibility: 'public' + type: jsdoc.getDefaultJSDocType() })); const parsedComment = parseAndConsumeLastComment('public'); - // TODO parse parameters description and types for slot - + /** @type {import('../../typings').SvelteSlotItem} */ const slot = { ...parsedComment, name: attrs.name || 'default', visibility: 'public', - parameters: exposedParameters + params: exposedParameters }; + parseAndMergeKeywords(parsedComment.keywords, slot, false); + + // TODO 5.* | Backward compatilibity + slot.parameters = slot.params; + if (this.includeSourceLocations && parser.startIndex >= 0 && parser.endIndex >= parser.startIndex) { slot.loc = { start: parser.startIndex, diff --git a/lib/v3/v3-utils.js b/lib/v3/v3-utils.js index 8add384..37b4c5e 100644 --- a/lib/v3/v3-utils.js +++ b/lib/v3/v3-utils.js @@ -157,8 +157,9 @@ function updateType(item) { * * @param {{ name: string; description: string}[]} keywords * @param {{ params?: any[]; return?: any }} event + * @param {string} [allowToParseReturn=true] */ -function parseAndMergeKeywords(keywords = [], event) { +function parseAndMergeKeywords(keywords = [], event, allowToParseReturn = true) { if (!event.params) { event.params = []; } @@ -187,7 +188,9 @@ function parseAndMergeKeywords(keywords = [], event) { event.params.push(parsedParam); } } else if (name in RETURN_ALIASES) { - event.return = parseReturnKeyword(description); + if (allowToParseReturn) { + event.return = parseReturnKeyword(description); + } } }); diff --git a/test/svelte3/integration/slots/slot.parameters.svelte b/test/svelte3/integration/slots/slot.parameters.svelte index 176c6b1..edbe081 100644 --- a/test/svelte3/integration/slots/slot.parameters.svelte +++ b/test/svelte3/integration/slots/slot.parameters.svelte @@ -1,6 +1,10 @@