123456789101112131415161718192021222324252627282930313233343536373839 |
- const DOCLET_PATTERN = /^@(\w+)(?:$|\s((?:[^](?!^@\w))*))/gim;
- function parseDocblock(str) {
-
-
- return str.replace(/^[ \t]*\*[ \t]?/gm, '').trim();
- }
- const DOCBLOCK_HEADER = /^\*\s/;
- export function getDocblock(path, trailing = false) {
- let comments = [];
- if (trailing && path.node.trailingComments) {
- comments = path.node.trailingComments.filter((comment) => comment.type === 'CommentBlock' && DOCBLOCK_HEADER.test(comment.value));
- }
- else if (path.node.leadingComments) {
- comments = path.node.leadingComments.filter((comment) => comment.type === 'CommentBlock' && DOCBLOCK_HEADER.test(comment.value));
- }
- if (comments.length > 0) {
- return parseDocblock(comments[comments.length - 1].value);
- }
- return null;
- }
- export function getDoclets(str) {
- const doclets = Object.create(null);
- let match;
- while ((match = DOCLET_PATTERN.exec(str))) {
- doclets[match[1]] = match[2] || true;
- }
- return doclets;
- }
|