'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.availableDocStyleParsers = undefined;exports.




captureDoc = captureDoc;var _doctrine = require('doctrine');var _doctrine2 = _interopRequireDefault(_doctrine);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} /**
                                                                                                                                                                                                                * parse docs from the first node that has leading comments
                                                                                                                                                                                                                */function captureDoc(source, docStyleParsers) {var metadata = {};
  // 'some' short-circuits on first 'true'
  for (var _len = arguments.length, nodes = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {nodes[_key - 2] = arguments[_key];}nodes.some(function (n) {
    try {

      var leadingComments = void 0;

      // n.leadingComments is legacy `attachComments` behavior
      if ('leadingComments' in n) {
        leadingComments = n.leadingComments;
      } else if (n.range) {
        leadingComments = source.getCommentsBefore(n);
      }

      if (!leadingComments || leadingComments.length === 0) {return false;}

      for (var name in docStyleParsers) {
        var doc = docStyleParsers[name](leadingComments);
        if (doc) {
          metadata.doc = doc;
        }
      }

      return true;
    } catch (err) {
      return false;
    }
  });

  return metadata;
}

/**
   * parse JSDoc from leading comments
   * @param {object[]} comments
   * @return {{ doc: object }}
   */
function captureJsDoc(comments) {
  var doc = void 0;

  // capture XSDoc
  comments.forEach(function (comment) {
    // skip non-block comments
    if (comment.type !== 'Block') {return;}
    try {
      doc = _doctrine2['default'].parse(comment.value, { unwrap: true });
    } catch (err) {
      /* don't care, for now? maybe add to `errors?` */
    }
  });

  return doc;
}

/**
    * parse TomDoc section from comments
    */
function captureTomDoc(comments) {
  // collect lines up to first paragraph break
  var lines = [];
  for (var i = 0; i < comments.length; i++) {
    var comment = comments[i];
    if (comment.value.match(/^\s*$/)) {break;}
    lines.push(comment.value.trim());
  }

  // return doctrine-like object
  var statusMatch = lines.join(' ').match(/^(Public|Internal|Deprecated):\s*(.+)/);
  if (statusMatch) {
    return {
      description: statusMatch[2],
      tags: [{
        title: statusMatch[1].toLowerCase(),
        description: statusMatch[2] }] };


  }
}

var availableDocStyleParsers = exports.availableDocStyleParsers = {
  jsdoc: captureJsDoc,
  tomdoc: captureTomDoc };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5712 characters]