All files / utils jsDocUtils.ts

86.96% Statements 20/23
80% Branches 16/20
100% Functions 5/5
89.47% Lines 17/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35    1x 2x 2x   1x     1x 2x 2x 2x         1x 2x 2x 2x           4x 4x   2x 2x   2x    
import * as ts from 'typescript';
 
export function getJSDocDescription(node: ts.Node) {
    const jsDocs = (node as any).jsDoc as ts.JSDoc[];
    if (!jsDocs || !jsDocs.length) { return ''; }
 
    return jsDocs[0].comment || '';
}
 
export function getJSDocTag(node: ts.Node, tagName: string) {
    const tags = getJSDocTags(node, tagName);
    Eif (!tags || !tags.length) {
        return;
    }
    return tags[0].comment;
}
 
export function isExistJSDocTag(node: ts.Node, tagName: string) {
    const tags = getJSDocTags(node, tagName);
    Eif (!tags || !tags.length) {
        return false;
    }
    return true;
}
 
function getJSDocTags(node: ts.Node, tagName: string) {
    const jsDocs = (node as any).jsDoc as ts.JSDoc[];
    if (!jsDocs || !jsDocs.length) { return; }
 
    const jsDoc = jsDocs[0];
    Iif (!jsDoc.tags) { return; }
 
    return jsDoc.tags.filter(t => t.tagName.text === tagName);
}