"use strict";

var _regeneratorRuntime2 = require("@babel/runtime/regenerator");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = iterateLinkDefinitions;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _mdastUtilFromMarkdown = require("mdast-util-from-markdown");

var _marked = /*#__PURE__*/_regeneratorRuntime2.mark(iterateLinkDefinitions);

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function isDefinition(node) {
  return node.type === 'definition';
}

function iterateLinkDefinitions(markdown) {
  var _iterator, _step, topLevelNode;

  return _regenerator.default.wrap(function iterateLinkDefinitions$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _iterator = _createForOfIteratorHelper((0, _mdastUtilFromMarkdown.fromMarkdown)(markdown).children);
          _context.prev = 1;

          _iterator.s();

        case 3:
          if ((_step = _iterator.n()).done) {
            _context.next = 10;
            break;
          }

          topLevelNode = _step.value;

          if (!isDefinition(topLevelNode)) {
            _context.next = 8;
            break;
          }

          _context.next = 8;
          return topLevelNode;

        case 8:
          _context.next = 3;
          break;

        case 10:
          _context.next = 15;
          break;

        case 12:
          _context.prev = 12;
          _context.t0 = _context["catch"](1);

          _iterator.e(_context.t0);

        case 15:
          _context.prev = 15;

          _iterator.f();

          return _context.finish(15);

        case 18:
        case "end":
          return _context.stop();
      }
    }
  }, _marked, null, [[1, 12, 15, 18]]);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJpdGVyYXRlTGlua0RlZmluaXRpb25zIiwiaXNEZWZpbml0aW9uIiwibm9kZSIsInR5cGUiLCJtYXJrZG93biIsImZyb21NYXJrZG93biIsImNoaWxkcmVuIiwidG9wTGV2ZWxOb2RlIl0sInNvdXJjZVJvb3QiOiJidW5kbGU6Ly8vIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbWFya2Rvd24vcHJpdmF0ZS9pdGVyYXRlTGlua0RlZmluaXRpb25zLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGZyb21NYXJrZG93biB9IGZyb20gJ21kYXN0LXV0aWwtZnJvbS1tYXJrZG93bic7XG5pbXBvcnQgeyB0eXBlIERlZmluaXRpb24sIHR5cGUgTm9kZSB9IGZyb20gJ21kYXN0JztcblxuZnVuY3Rpb24gaXNEZWZpbml0aW9uKG5vZGU6IE5vZGUpOiBub2RlIGlzIERlZmluaXRpb24ge1xuICByZXR1cm4gbm9kZS50eXBlID09PSAnZGVmaW5pdGlvbic7XG59XG5cbmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uKiBpdGVyYXR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