index.js 899 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @typedef {import('micromark-util-types').Event} Event
  3. * @typedef {import('micromark-util-types').Resolver} Resolver
  4. * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
  5. */
  6. /**
  7. * Call all `resolveAll`s.
  8. *
  9. * @param {Array<{resolveAll?: Resolver | undefined}>} constructs
  10. * List of constructs, optionally with `resolveAll`s.
  11. * @param {Array<Event>} events
  12. * List of events.
  13. * @param {TokenizeContext} context
  14. * Context used by `tokenize`.
  15. * @returns {Array<Event>}
  16. * Changed events.
  17. */
  18. export function resolveAll(constructs, events, context) {
  19. /** @type {Array<Resolver>} */
  20. const called = []
  21. let index = -1
  22. while (++index < constructs.length) {
  23. const resolve = constructs[index].resolveAll
  24. if (resolve && !called.includes(resolve)) {
  25. events = resolve(events, context)
  26. called.push(resolve)
  27. }
  28. }
  29. return events
  30. }