All files / dist/helpers jsdoc.js

96.77% Statements 30/31
83.33% Branches 15/18
100% Functions 12/12
96.3% Lines 26/27
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67    1x     1x 1x 1x 1x   1x   1x   1x   1x   1x   2x     75x 75x       109x       22x 19x 15x     15x 15x               53x     3x 3x             39x 26x   13x 13x          
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getJsDocTagValue = getJsDocTagValue;
exports.getJsDocTag = getJsDocTag;
exports.getJsDocClassInfo = getJsDocClassInfo;
exports.hasJsdocExportFlag = hasJsdocExportFlag;
 
require('source-map-support/register');
 
var _doctrine = require('doctrine');
 
var _doctrine2 = _interopRequireDefault(_doctrine);
 
var _ignoreCase = require('ignore-case');
 
var _ignoreCase2 = _interopRequireDefault(_ignoreCase);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function getJsDocTagValue(tags, name) {
  const tag = getJsDocTag(tags, name);
  return tag && (tag.name || tag.description);
}
 
function getJsDocTag(tags, name) {
  return tags.find(t => _ignoreCase2.default.equals(name, t.title));
}
 
function getJsDocClassInfo(node, parent) {
  if (node.leadingComments) {
    return node.leadingComments.filter(comment => comment.type === 'CommentBlock').map(comment => {
      const docAST = _doctrine2.default.parse(comment.value, {
        unwrap: true
      });
      const tags = docAST.tags || [];
      return {
        alias: getJsDocTagValue(tags, 'alias'),
        name: getJsDocTagValue(tags, 'name'),
        namespace: getJsDocTagValue(tags, 'namespace'),
        nonUI5: !!getJsDocTag(tags, 'nonui5'),
        metadata: getJsDocTagValue(tags, 'metadata'),
        renderer: getJsDocTagValue(tags, 'renderer')
      };
    }).filter(classInfo => Object.values(classInfo).some(value => value))[0];
  }
  // Else see if the JSDoc are on the return statement (i..e return class X extends SAPClass)
  else Eif (node.type === 'ClassExpression' && parent && parent.type === 'ReturnStatement') {
      return getJsDocClassInfo(parent);
    } else {
      return {};
    }
}
 
function hasJsdocExportFlag(node) {
  if (!node.leadingComments) {
    return false;
  }
  return node.leadingComments.filter(comment => comment.type === 'CommentBlock').some(comment => {
    return _doctrine2.default.parse(comment.value, {
      unwrap: true,
      tags: ['export']
    }).tags.length > 0;
  });
}