Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export functions for each phase #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

devongovett
Copy link

@devongovett devongovett commented Dec 29, 2024

Similar to #27 but with updated function names based on PR comments. In Parcel, we're looking to implement native support for MDX in Rust, and we'd like to avoid re-parsing since we already use SWC. See parcel-bundler/parcel#10064

Second commit may be more controversial. Basically I need a way to embed JSX expressions into Hast element nodes. In Parcel, we want to collect dependencies in MDX, e.g. image references and links. To do this, we need to transform <img src="foo.png" /> into <img src={new URL('foo.png', import.meta.url).toString()} />. The URL constructor creates a dependency in later stages.

I tried converting the Node::Element into a Node::MdxJsxElement in order to do this, but this gets treated as an "explicit" JSX element and no longer uses the injected _components.img. Simplest way to implement this was to add a JSX expression variant to PropertyValue but I could change it if there's a better way.

@wooorm
Copy link
Owner

wooorm commented Jan 1, 2025

Hi!

Why do that second part in hast, here, and not in swc when you get that later?
You already do things in swc land right?

It would probably be good to land mdx-js/mdx@e12f307 plus mdx-js/mdx@2c511a4 here.

Would be easier to split this PR up into 2? I’m 👍 on half, but not sure about changing hast like this

@devongovett
Copy link
Author

Yeah I can do that. I had to split out mdx_plugin_recma_document and mdx_plugin_recma_jsx_rewrite as well so that my SWC pass can run before rewriting to use injected _components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants