WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Transcode replace Babel with sucrase #1

@jaywcjlove

Description

@jaywcjlove

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions