fkling / astexplorer

A web tool to explore the ASTs generated by various parsers.
https://astexplorer.net/
MIT License
6.21k stars 739 forks source link

Update MDX, support version 1 and 2, as well as the multiple ASTs generated #689

Open ChristianMurphy opened 1 year ago

ChristianMurphy commented 1 year ago

mdx version 1 and version 2 have different syntax trees, this PR allows both versions' syntax trees to be previewed.

In addition, mdx internally uses multiple syntax trees.

Version 1 has:

Version 2 has:

This updates AST Explorer to have a preview for all version 1 and version 2 ASTs. As well as updates transformers to allow for transforms on both version 1 and version 2.

This also adds support for syntax extensions, supported in MDX version 2; including GFM, Math, Directives, and more.

/cc @silvenon, @remcohaszing, @wooorm


Screenshots

mdx 2 preview with mdx 2 transformer mdx ast preview

parser list for mdx parser list

mdx 2 settings/plugins mdx settings view

wooorm commented 1 year ago

Any reason the old AST is still around? Why not drop it?

remcohaszing commented 1 year ago

I also wouldn't mind dropping the old AST

ChristianMurphy commented 1 year ago

Any reason the old AST is still around? Why not drop it?

A couple reasons.

  1. there are still plugins out there for mdx 1, which could benefit from having a tool to help inspect ASTs
  2. ASTExplorer has some precedence with keeping multiple major versions of parsers. For example:

I'd also be fine with dropping it, but defaulted to keeping it.

wooorm commented 1 year ago

Re 2: Old versions seems to be around to support old snippet links, they seem to be hidden: https://github.com/fkling/astexplorer/commit/fad47c2a66c302f3a10361b11aad1a36703cd72d

Re 1: MDX 0 and 1 ASTs, IMO, are more the “absence” of an AST. It’s mdast, but replaces a html node with a jsx node, with a slightly different regex. And it adds import/export nodes, which are similarly strings, with different regexes. I don’t think it’s very interesting to look at this AST. Now that there are nodes for things in v2, I do think it gets interesting, and we could start versioning to keep snippet links alive?

remcohaszing commented 11 months ago

I suppose MDX 3 should be added by now too.