Open wooorm opened 3 years ago
I think it’s very doable. The problem aren’t the exports, but the declared variables. In case of MDX these are imports and exports. Since they are always top-level, we just need to iterate over all MDX ESM nodes and find all imports and exports of their estree program body.
The same issue exists for remark-mdx-frontmatter
, so I’ll create a reusable mdast utility for this.
Some custom plugins might expose “normal” variables in the blocks btw. So it might be more complex, assuming that use case is covered
Do you mean something like this?
export const { foo: { bar: baz } } = whatever
I think this could handled by concatenating the program data of all mdxEsm
nodes and processing the resulting body using periscopic.
No, I mean without the export
, so adding:
const a = 1;
var b = 2;
let c = 3;
function d() {}
Indeed, periscopic
I’m not entirely sure, but I think the only way to add such variables would be through mdxEsm
nodes, right?
Yep, correct!
Finding out which names are already exported is a bit complex, so this might be too much work. However, it could be nice to have a better error message than what would be given when the resulting file is imported: