-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement a codemod for syntax changes we can detect #1043
Comments
This could be done by parsing with the old remark-mdx, and compiling with the new one, although the old JSX tags would need to be parsed to the new one (or ignored and injected raw, which will then result in errors that people will manually fix, but incorrect JSX is unlikely as if it doesn’t work now then it probably didn’t work already) var before = unified()
.use(remarkParse)
.use(remarkOldMdx)
var after = unified()
.use(remarkStringify)
.use(remarkNewMdx)
.use(remarkNewMdxJs)
var oldTree = before.runSync(before.parse(doc))
var newTree = changeOldToNewTree(oldTree)
var output = after.stringify(after.runSync(newTree)) Finally, unified will reformat code. So alternatively, you could use the old tree to inspect if those constructs were used, and then use their positional information to replace in the document. |
For my last paragraph, magic-string would help with that! https://github.com/Rich-Harris/magic-string |
I opted not to. I’ve thought about how it’d work a couple times but it’s complex. It’d be a lot of work and wouldn’t work in some cases. |
Is there currently a codemod to convert MDX v1 code to v2? We have a lot of content written in MDX v1 and would like to avoid rewriting manually by hand if possible. I saw https://github.com/mdx-js/codemods, but it seems a bit old... |
Last comment still holds. A proper code mod is really complex.
It’ll throw errors with pretty descriptive messages. With that, and some regex kung-fu, you should be able to get far. Hashicorp had something somewhat working for this, but it was still missing things. Let me know if you‘re interested in getting your hands dirty and improving that project and I’ll ping folks! |
<https://mdxjs.com>
=>[https://mdxjs.com](https://mdxjs.com)
<3
=><3
The text was updated successfully, but these errors were encountered: