Description
Subject of the discussion
With #1382, we now have a JavaScript syntax tree.
The tree starts out in estree: as markdown + mdx.js is parsed simultaneously, I needed a JavaScript parser in micromark-extension-mdxjs
, and I chose a small and fast one: acorn. Which comes with estree.
Acorn is small, 30kb minzipped. acorn-jsx is 4kb. astring
(a generator) is also 4kb.
Previously, in this project, we used Babel for plugins.
Babel is giant. @babel/core
, which has methods to run Babel plugins, is like 220kb minzipped. @babel/generator
is 63kb. @babel/parser
is 60kb.@babel/traverse
is 165kb (it includes both the parser and the generator).
Estree has the drawback of being a fragmented ecosystem: there are no nice parsers that support comments; there are no tree-wakers or compilers that support JSX. And importantly, as as we use JSX, we’d want to turn JSX into function calls (React/preact/vue), but those are all Babel plugins. We could use estree but then users would still need to run Babel afterwards.
Babel has the drawback of being giant and slow. But the good thing is that the JSX -> JS compilers all live there.
Problem
What should we go with?
We can’t turn JSX -> JS unless we’re using Babel (well, we could, the babel plugin to turn JSX -> _jsx()
/ React.createElement
is 800l). Most users probably want to use Babel plugins to turn their fancy features into whatever.
An estree-only system as a base for MDX would be ✨✨✨. @mdx-js/runtime
is now 350kb minzipped. That could go down to 100kb or less?