Skip to content

Commit

Permalink
always parse keywords and description from comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Pontus Lundin committed Dec 9, 2019
1 parent d142e59 commit 15003a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
18 changes: 4 additions & 14 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getVisibility = (keywords, defaultVisibility) => {
return defaultVisibility;
};

const parseComment = (text, defaultVisibility = DEFAULT_VISIBILITY, features = ['description', 'keywords']) => {
const parseComment = (text, defaultVisibility = DEFAULT_VISIBILITY) => {
const result = {
keywords: [],
visibility: defaultVisibility,
Expand Down Expand Up @@ -47,29 +47,19 @@ const parseComment = (text, defaultVisibility = DEFAULT_VISIBILITY, features = [
index = matches.index;

const name = matches[1];
const description = features.includes('description')
? (matches[4] || '').trim()
: '';
const description = (matches[4] || '').trim();

result.keywords.push({ name, description });
}

if (features.includes('description')) {
result.description = parsedText.substring(0, indexDescription).trim();
}

result.description = parsedText.substring(0, indexDescription).trim();
result.visibility = getVisibility(result.keywords, result.visibility);

if (!features.includes('keywords')) {
result.keywords = [];
}

return result;
};

const getComment = (property, {
defaultVisibility = DEFAULT_VISIBILITY,
features,
useFirst = false,
useLeading = true,
useTrailing = true
Expand All @@ -91,7 +81,7 @@ const getComment = (property, {
}

if (lastComment) {
return parseComment(lastComment, defaultVisibility, features);
return parseComment(lastComment, defaultVisibility);
}

return {
Expand Down
2 changes: 1 addition & 1 deletion lib/v3/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class Parser extends EventEmitter {
const declaration = node.declaration;

if (declaration) {
const exportNodeComment = utils.getComment(node, { defaultVisibility: 'public', features: this.features, useLeading: true, useTrailing: false });
const exportNodeComment = utils.getComment(node, { defaultVisibility: 'public', useLeading: true, useTrailing: false });

if (declaration.type === 'VariableDeclaration') {
const variables = this.parseVariableDeclaration(declaration);
Expand Down
2 changes: 1 addition & 1 deletion test/svelte3/integration/data/data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('SvelteDoc v3 - Props', () => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'data.public.svelte'),
features: ['data', 'description', 'keywords'],
features: ['data'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
Expand Down

0 comments on commit 15003a3

Please sign in to comment.