JReinhold / mdx-deck-live-code

A component for mdx-deck to live code in your slides. 🤯
https://reinhold.is/live-coding-in-slides
Other
202 stars 18 forks source link

FEATURE REQUEST: Support newer syntax such as class properties using Babel #1

Closed JReinhold closed 3 years ago

JReinhold commented 5 years ago

Currently react-live uses Bublé under the hood to transpile the code. Bublé doesn't support everything mdx-deck does, which creates an unexpected experience for the developer, such as class properties not being supported.

We could try to use @babel/standalone to transpile the code before it enters the <LiveProvider />, but it would still go through Bublé, and had some difficulties making Babel and Bublé play nice together, so this needs further investigation. This method is discussed here: https://github.com/FormidableLabs/react-live/issues/67

Code snippets for further usage:

import { transform } from '@babel/standalone';

...

<LiveProvider
  code={code}
  transformCode={transpileWithBabel}
  {...providerProps}
>

...

const transpileWithBabel = (input: string) =>
    transform(input, {
        presets: ['es2017', 'react'],
        plugins:['proposal-class-properties']
    }).code;

For presets and plugins supported by @babel/standalone see https://github.com/babel/babel/blob/master/packages/babel-standalone/src/index.js