mdast-util-to-hast: Circular dependencies break rollup build

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)

Affected packages and versions: 11.1.0

Steps to reproduce

  1. Use rollup for bundle project with some lib that use mdast-util-to-hast
  2. Build project

Link to code example:

I’ve extracted mdast-util-to-hast into separate chunk to easy inspection. The produced code (in build directory) unable to be bunded in correct direction in reason of circular deps

https://github.com/SQReder/cautious-pancake/blob/main/build/hast-ea6dff5f.js#L334-L384

var one$5 = one_1; // ❗ capture one$5 as undefined

function all$g(h, parent) {
  var nodes = parent.children || [];
  var length = nodes.length;
  var values = [];
  var index = -1;
  var result;
  var head;

  while (++index < length) {
    result = one$5(h, nodes[index], parent); // ❗❗ TypeError: one$5 is not a function

    if (result) {
      if (index && nodes[index - 1].type === 'break') {
        if (result.value) {
          result.value = result.value.replace(/^\s+/, '');
        }

        head = result.children && result.children[0];

        if (head && head.value) {
          head.value = head.value.replace(/^\s+/, '');
        }
      }

      values = values.concat(result);
    }
  }

  return values
}

var one_1 = one$4; // ❗ declaration hoists, but initialization not

var u$b = unistBuilder;
var all$f = all_1$1;

var own$6 = {}.hasOwnProperty;

// Transform an unknown node.
function unknown(h, node) {
  if (text$3(node)) {
    return h.augment(node, u$b('text', node.value))
  }

  return h(node, 'div', all$f(h, node))
}

// Visit a node.
function one$4(h, node, parent) { // ❗ function declaration will hoist 
...

Also code from current project (non-minified) image

Expected behavior

Expect code to be working

Actual behavior

Circular deps prevent code to be correctly bundled

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (12 by maintainers)

Commits related to this issue

Most upvoted comments

@wooorm I wasn’t intending to be snarky; my question was based on your above statement from June 8th

In a couple of weeks I’ll update remark-rehype

Based on your assurance, it was a reasonable question to ask. Also, based on your response, I suspect the answer is that your earlier statement was optimistic and there is unlikely to be a change to the status quo any time soon. I’m not sure what money has to do with it.

I’ve published a patched version of 10.2.1 with custom name and aliased it in the bundler configuration

Can we also backport same patch for 10.2 version? remark-rehype rely on it

@wooorm “we” — as in the downstream users affected by this bug…You are projecting your own personal issues/grievances into this thread…and it was really just a simple question.

This exact issue is causing issues for us; It’s now been about 8 weeks since it was first reported…can we expect any progress soon?