sucrase
- Version 3.35.0
- Published
- 1.14 MB
- 7 dependencies
- MIT license
Install
npm i sucrase
yarn add sucrase
pnpm add sucrase
Overview
Super-fast alternative to Babel for when you can target modern JS runtimes
Index
Functions
Interfaces
Type Aliases
Functions
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;
Interfaces
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 thejsx
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 {}
Type Aliases
type Transform
type Transform = | 'jsx' | 'typescript' | 'flow' | 'imports' | 'react-hot-loader' | 'jest';
Package Files (2)
Dependencies (7)
Dev Dependencies (21)
- @babel/core
- @jridgewell/trace-mapping
- @types/mocha
- @types/mz
- @types/node
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- chalk
- codecov
- eslint
- eslint-config-airbnb-base
- eslint-config-prettier
- eslint-plugin-import
- eslint-plugin-prettier
- mocha
- nyc
- prettier
- sucrase
- test262-harness
- ts-interface-builder
- typescript
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/sucrase
.
- Markdown[](https://www.jsdocs.io/package/sucrase)
- HTML<a href="https://www.jsdocs.io/package/sucrase"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2240 ms. - Missing or incorrect documentation? Open an issue for this package.