• Version 3.35.0
  • Published
  • 1.14 MB
  • 7 dependencies
  • MIT license


npm i sucrase
yarn add sucrase
pnpm add sucrase


Super-fast alternative to Babel for when you can target modern JS runtimes



function getFormattedTokens

getFormattedTokens: (code: string, options: Options) => string;
  • Return a string representation of the sucrase tokens, mostly useful for diagnostic purposes.

function getVersion

getVersion: () => string;

    function transform

    transform: (code: string, options: Options) => TransformResult;


      interface Options

      interface Options {}

        property disableESTransforms

        disableESTransforms?: boolean;
        • Opts out of all ES syntax transformations: optional chaining, nullish coalescing, class fields, numeric separators, optional catch binding.

        property enableLegacyBabel5ModuleInterop

        enableLegacyBabel5ModuleInterop?: boolean;
        • If true, replicate the import behavior Babel 5 and babel-plugin-add-module-exports.

        property enableLegacyTypeScriptModuleInterop

        enableLegacyTypeScriptModuleInterop?: boolean;
        • If true, replicate the import behavior of TypeScript's esModuleInterop: false.

        property filePath

        filePath?: string;
        • File path to use in error messages, React display names, and source maps.

        property injectCreateRequireForImportRequire

        injectCreateRequireForImportRequire?: boolean;
        • Only relevant when targeting ESM (i.e. when the imports transform is *not* specified). This flag changes the behavior of TS require imports:

          import Foo = require("foo");

          to import createRequire, create a require function, and use that function. This is the TS behavior with module: nodenext and makes it easier for the same code to target ESM and CJS.

        property jsxFragmentPragma

        jsxFragmentPragma?: string;
        • If specified, function name to use in place of React.Fragment when compiling JSX with the classic runtime.

        property jsxImportSource

        jsxImportSource?: string;
        • If specified, import path prefix to use in place of "react" when compiling JSX with the automatic runtime.

        property jsxPragma

        jsxPragma?: string;
        • If specified, function name to use in place of React.createClass when compiling JSX with the classic runtime.

        property jsxRuntime

        jsxRuntime?: 'classic' | 'automatic' | 'preserve';
        • Transformation mode for the JSX transform. - "classic" refers to the original behavior using React.createElement. - "automatic" refers to the transform behavior released with React 17, where the jsx function (or a variation) is automatically imported. - "preserve" leaves the JSX as-is.

          Default value: "classic".

        property keepUnusedImports

        keepUnusedImports?: boolean;
        • If specified, disable automatic removal of type-only import and export statements and names. Only statements and names that explicitly use the type keyword are removed.

        property preserveDynamicImport

        preserveDynamicImport?: boolean;
        • If specified, the imports transform does not attempt to change dynamic import() expressions into require() calls.

        property production

        production?: boolean;
        • Compile code for production use. Currently only applies to the JSX transform.

        property sourceMapOptions

        sourceMapOptions?: SourceMapOptions;
        • If specified, we also return a RawSourceMap object alongside the code. filePath must be specified if this option is enabled.

        property transforms

        transforms: Array<Transform>;
        • Unordered array of transform names describing both the allowed syntax (where applicable) and the transformation behavior.

        interface SourceMapOptions

        interface SourceMapOptions {}

          property compiledFilename

          compiledFilename: string;
          • The name to use in the "file" field of the source map. This should be the name of the compiled file.

          interface SucraseContext

          interface SucraseContext {}

            property helperManager

            helperManager: HelperManager;

              property importProcessor

              importProcessor: CJSImportProcessor | null;

                property nameManager

                nameManager: NameManager;

                  property scopes

                  scopes: Array<Scope>;

                    property tokenProcessor

                    tokenProcessor: TokenProcessor;

                      interface TransformResult

                      interface TransformResult {}

                        property code

                        code: string;

                          property sourceMap

                          sourceMap?: RawSourceMap;

                            Type Aliases

                            type Transform

                            type Transform =
                            | 'jsx'
                            | 'typescript'
                            | 'flow'
                            | 'imports'
                            | 'react-hot-loader'
                            | 'jest';

                              Package Files (2)

                              Dependencies (7)

                              Dev Dependencies (21)

                              Peer Dependencies (0)

                              No peer dependencies.


                              To add a badge like this badgeto your package's README, use the codes available below.

                              You may also use to create a custom badge linking to

                              • Markdown
                              • HTML
                                <a href=""><img src="" alt=""></a>