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

Transcode replace Babel with sucrase #1

Open
jaywcjlove opened this issue Jun 30, 2022 · 0 comments
Open

Transcode replace Babel with sucrase #1

jaywcjlove opened this issue Jun 30, 2022 · 0 comments

Comments

@jaywcjlove
Copy link
Member

jaywcjlove commented Jun 30, 2022

import { transform } from '@babel/standalone';
import { PluginItem } from '@babel/core';
import removeImports from 'babel-plugin-transform-remove-imports';
import replaceExportDefault from 'babel-plugin-transform-replace-export-default';
import { Options } from '../';
export const getTransformValue = (str: string, filename: string, opts: Options) => {
const plugins: PluginItem[] = [...(opts.babelPlugins || [])];
if (opts.removeImports) {
plugins.push([removeImports, opts.removeImports]);
}
const result = transform(str, {
filename,
presets: ['env', 'es2015', 'react', 'typescript'],
plugins: [...plugins, replaceExportDefault],
});
return result.code;
};

Website: https://sucrase.io/#selectedTransforms=jsx,flow,imports,react-hot-loader,jest
Github: https://github.com/alangpierce/sucrase

import {transform} from "sucrase";
const compiledCode = transform(code, {transforms: ["typescript", "imports"]}).code;

uiwjs/react-code-preview#70 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant