All files / dist/helpers jsdoc.js

94.74% Statements 54/57
85.29% Branches 29/34
100% Functions 11/11
94.44% Lines 51/54
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125    1x     1x 1x 1x   1x   1x   1x   1x   1x   2x   1x 1x     51x 39x 33x       33x 33x   33x 99x   99x 28x       33x 99x   99x 4x       33x     12x 7x   5x                   38x 35x     3x 3x       3x       3x   3x       3x   3x 3x 3x 3x 3x     3x             99x 99x       223x       33x       61x 34x     27x 25x          
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getJsDocClassInfo = getJsDocClassInfo;
exports.getTags = getTags;
exports.hasJsdocGlobalExportFlag = hasJsdocGlobalExportFlag;
 
require("source-map-support/register");
 
var _core = require("@babel/core");
 
var _doctrine = _interopRequireDefault(require("doctrine"));
 
var _ignoreCase = _interopRequireDefault(require("ignore-case"));
 
var _ast = require("./ast");
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
const classInfoValueTags = ["alias", "name", "namespace"];
const classInfoBoolTags = ["nonUI5", "controller", "keepConstructor"];
 
function getJsDocClassInfo(node, parent) {
  if (node.leadingComments) {
    return node.leadingComments.filter(_ast.isCommentBlock).map(comment => {
      const docAST = _doctrine.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, tagName);
 
        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 (_core.types.isClassExpression(node) && _core.types.isReturnStatement(parent)) {
      return getJsDocClassInfo(parent);
    } else {
      return {};
    }
}
/**
 * Returns a map of tags by name.
 * Converts empty to bool. Also converts bool value
 */
 
 
function getTags(comments) {
  if (!comments) {
    return {};
  }
 
  for (const comment of comments) {
    Iif (!(0, _ast.isCommentBlock)(comment)) {
      continue;
    }
 
    const docAST = _doctrine.default.parse(comment.value, {
      unwrap: true
    });
 
    const tags = docAST.tags;
 
    Iif (!tags || !tags.length) {
      continue;
    }
 
    const map = {};
 
    for (const tag of tags) {
      const title = tag.title;
      let value = tag.name || tag.description || true;
      if (value === "false") value = false;
      map[title] = value;
    }
 
    return map;
  }
 
  return {};
}
 
function getJsDocTagValue(tags, name) {
  const tag = getJsDocTag(tags, name);
  return tag && (tag.name || tag.description);
}
 
function getJsDocTag(tags, name) {
  return tags.find(t => _ignoreCase.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 _doctrine.default.parse(comment.value, {
      unwrap: true,
      tags: ["global"]
    }).tags.length > 0;
  });
}