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

Replace Babel w/ estree #1399

Merged
merged 1 commit into from
Dec 20, 2020
Merged

Replace Babel w/ estree #1399

merged 1 commit into from
Dec 20, 2020

Commits on Dec 20, 2020

  1. Replace Babel w/ estree

    This removes the last three custom Babel plugins we had and replaces
    them with estree versions.
    Furthermore, it removes `@babel/generator`.
    
    For the plugins, we were only looking at ESM import/exports, but right
    now we’re delegating work to `periscopic` to look at which things are
    defined in the top-level scope.
    It’s a bit more complex, but this matches better with intentions,
    fixes some bugs, and prepares for a potential future where other ES
    constructs are allowed, so all in all should be a nice improvement.
    
    For serializing, we’re switching to `astring`, and handling JSX for now
    internally (could be externalized later).
    `astring` seems fast and is incredibly small, but is not very popular.
    We might perhaps see bugs is serialization in the future because of that,
    but all our tests seem fine, so I’m not too worried about that.
    
    Estree remains a somewhat fragmented ecosystem, such as that the tree
    walkers in `periscopic` and `astring` are different, so we might also
    consider writing our own serializer in the future.
    Or, when we implement Babel’s React JSX transform ourselves, could switch
    to another generator, or at least drop the JSX serialization code here.
    
    Because of these changes, we can drop `@babel/core` and
    `@babel/generator` from `@mdx-js/mdx`, which drops the bundle size of
    from 349kb to 111kb.
    That’s 68%.
    Pretty nice.
    This should improve downloading and parsing time of bundles
    significantly.
    Of course, we currently still have JSX in the output, so folks will
    have to resort to Babel (or `buble-jsx-only`) in another step.
    
    For performance, v2 (micromark) was already an improvement over v1.
    On 1000 simple files totalling about 1mb of MDX:
    
    * v1: 3739ms
    * v2: 2734ms (26% faster)
    * v2 (w/o babel): 1392ms (63% faster).
    
    Of course, this all really depends on what type of stuff is in your MDX.
    But it looks pretty sweet!
    
    ✨
    
    Related to GH-1046.
    Related to GH-1152.
    Related to GH-1338.
    Closes GH-704.
    Closes GH-1384.
    wooorm committed Dec 20, 2020
    Configuration menu
    Copy the full SHA
    eed6cf4 View commit details
    Browse the repository at this point in the history