All files / dist/helpers jsdoc.js

86% Statements 43/50
72.41% Branches 21/29
100% Functions 11/11
100% Lines 40/40
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87    1x     1x 1x   1x   1x   1x   1x   1x   1x   1x   1x   2x   1x   1x   1x     32x 24x 19x     19x 19x 19x 57x 57x 14x     19x 19x 19x 3x     19x       8x 7x   1x         57x 57x       88x       19x       42x 30x   12x 12x          
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getJsDocClassInfo = getJsDocClassInfo;
exports.hasJsdocGlobalExportFlag = hasJsdocGlobalExportFlag;
 
require('source-map-support/register');
 
var _babelTypes = require('babel-types');
 
var t = _interopRequireWildcard(_babelTypes);
 
var _doctrine = require('doctrine');
 
var _doctrine2 = _interopRequireDefault(_doctrine);
 
var _ignoreCase = require('ignore-case');
 
var _ignoreCase2 = _interopRequireDefault(_ignoreCase);
 
var _ast = require('./ast');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function _interopRequireWildcard(obj) { Eif (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
 
const classInfoValueTags = ['alias', 'name', 'namespace'];
 
const classinfoBoolTags = ['nonUI5'];
 
function getJsDocClassInfo(node, parent) {
  if (node.leadingComments) {
    return node.leadingComments.filter(_ast.isCommentBlock).map(comment => {
      const docAST = _doctrine2.default.parse(comment.value, {
        unwrap: true
      });
      const tags = docAST.tags || [];
      const info = {};
      for (const tagName of classInfoValueTags) {
        const value = getJsDocTagValue(tags, tagName);
        if (value) {
          info[tagName] = value;
        }
      }
      for (const tagName of classinfoBoolTags) {
        const value = !!getJsDocTag(tags, 'nonui5');
        if (value) {
          info[tagName] = value;
        }
      }
      return info;
    }).filter(notEmpty)[0];
  }
  // Else see if the JSDoc are on the return statement (i..e return class X extends SAPClass)
  else if (t.isClassExpression(node) && t.isReturnStatement(parent)) {
      return getJsDocClassInfo(parent);
    } else {
      return {};
    }
}
 
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 notEmpty(obj) {
  return Object.values(obj).some(value => value);
}
 
function hasJsdocGlobalExportFlag(node) {
  if (!node.leadingComments) {
    return false;
  }
  return node.leadingComments.filter(_ast.isCommentBlock).some(comment => {
    return _doctrine2.default.parse(comment.value, {
      unwrap: true,
      tags: ['global']
    }).tags.length > 0;
  });
}