# babel-core

> Babel compiler core.

Latest version **6.26.3** (published 2018-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-core
pnpm add babel-core
yarn add babel-core
bun add babel-core
```

## Health

**Score 43/100 (D)** — status: abandoned.

Positive: has types package; no vulnerabilities; high maintenance score; high quality score; popular repo.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.26.3 |
| Published | 2018-04-27 |
| First published | 2015-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/babel-core) |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 104.2 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 43996 |
| Author | Sebastian McKenzie |
| Maintainers | danez, existentialism, hzoo, loganfsmyth, sebmck, thejameskyle |
| Keywords | 6to5, babel, classes, const, es6, harmony, let, modules, transpile, transpiler, var, babel-core, compiler |

## Links

- npm: https://www.npmjs.com/package/babel-core
- Repository: https://github.com/babel/babel/tree/master/packages/babel-core
- Homepage: https://babeljs.io/
- npm.io page: https://npm.io/package/babel-core

## Dependencies (19)

- [debug](https://npm.io/package/debug.md) ^2.6.9
- [json5](https://npm.io/package/json5.md) ^0.5.1
- [slash](https://npm.io/package/slash.md) ^1.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [babylon](https://npm.io/package/babylon.md) ^6.18.0
- [private](https://npm.io/package/private.md) ^0.1.8
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [source-map](https://npm.io/package/source-map.md) ^0.5.7
- [babel-types](https://npm.io/package/babel-types.md) ^6.26.0
- [babel-helpers](https://npm.io/package/babel-helpers.md) ^6.24.1
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [babel-messages](https://npm.io/package/babel-messages.md) ^6.23.0
- [babel-register](https://npm.io/package/babel-register.md) ^6.26.0
- [babel-template](https://npm.io/package/babel-template.md) ^6.26.0
- [babel-traverse](https://npm.io/package/babel-traverse.md) ^6.26.0
- [babel-generator](https://npm.io/package/babel-generator.md) ^6.26.0
- [babel-code-frame](https://npm.io/package/babel-code-frame.md) ^6.26.0
- [path-is-absolute](https://npm.io/package/path-is-absolute.md) ^1.0.1
- [convert-source-map](https://npm.io/package/convert-source-map.md) ^1.5.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 6.26.3 (latest) — 2018-04-27
- 7.0.0-bridge.0 (bridge) — 2017-11-13
- 7.0.0-beta.3 (next) — 2017-10-15
- 5.8.38 (old) — 2016-03-22
- 6.26.2 — 2018-04-26
- 7.0.0-beta.2 — 2017-09-26
- 7.0.0-beta.1 — 2017-09-19
- 7.0.0-beta.0 — 2017-09-12
- 7.0.0-alpha.20 — 2017-08-30
- 6.26.0 — 2017-08-16
- 7.0.0-alpha.19 — 2017-08-07
- 7.0.0-alpha.18 — 2017-08-03
- 7.0.0-alpha.17 — 2017-07-26
- 7.0.0-alpha.16 — 2017-07-25
- 7.0.0-alpha.15 — 2017-07-12
- … 242 more at https://npm.io/package/babel-core/versions

## README

# babel-core

> Babel compiler core.


```javascript
var babel = require("babel-core");
import { transform } from 'babel-core';
import * as babel from 'babel-core';
```

All transformations will use your local configuration files (.babelrc or in package.json). See [options](#options) to disable it.

## babel.transform(code: string, [options?](#options): Object)

Transforms the passed in `code`. Returning an object with the generated code,
source map, and AST.

```js
babel.transform(code, options) // => { code, map, ast }
```

**Example**

```js
var result = babel.transform("code();", options);
result.code;
result.map;
result.ast;
```

## babel.transformFile(filename: string, [options?](#options): Object, callback: Function)

Asynchronously transforms the entire contents of a file.

```js
babel.transformFile(filename, options, callback)
```

**Example**

```js
babel.transformFile("filename.js", options, function (err, result) {
  result; // => { code, map, ast }
});
```

## babel.transformFileSync(filename: string, [options?](#options): Object)

Synchronous version of `babel.transformFile`. Returns the transformed contents of
the `filename`.

```js
babel.transformFileSync(filename, options) // => { code, map, ast }
```

**Example**

```js
babel.transformFileSync("filename.js", options).code;
```

## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object)

Given, an [AST](https://astexplorer.net/), transform it.

```js
const code = "if (true) return;";
const ast = babylon.parse(code, { allowReturnOutsideFunction: true });
const { code, map, ast } = babel.transformFromAst(ast, code, options);
```

## Options

> #### Babel CLI
> 
> You can pass these options from the Babel CLI like so:
> 
> `babel --name=value`

Following is a table of the options you can use:

| Option                   | Default              | Description                     |
| ------------------------ | -------------------- | ------------------------------- |
| `ast`                    | `true`               | Include the AST in the returned object |
| `auxiliaryCommentAfter`  | `null`               | Attach a comment after all non-user injected code. |
| `auxiliaryCommentBefore` | `null`               | Attach a comment before all non-user injected code. |
| `babelrc`                | `true`               | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/en/babel-cli#ignoring-babelrc). |
| `code`                   | `true`               | Enable code generation |
| `comments`               | `true`               | Output comments in generated output. |
| `compact`                | `"auto"`             | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB. |
| `env`                    | `{}`                 | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the environment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` |
| `extends`                | `null`               | A path to an `.babelrc` file to extend |
| `filename`               | `"unknown"`          | Filename for use in errors etc. |
| `filenameRelative`       | `(filename)`         | Filename relative to `sourceRoot`. |
| `generatorOpts`          | `{}`                 | An object containing the options to be passed down to the babel code generator, babel-generator |
| `getModuleId`            | `null`               | Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used. |
| `highlightCode`          | `true`               | ANSI highlight syntax error code frames |
| `ignore`                 | `null`               | Opposite to the `only` option. `ignore` is disregarded if `only` is specified. |
| `inputSourceMap`         | `null`               | A source map object that the output source map will be based on. |
| `minified`               | `false`              | Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe) |
| `moduleId`               | `null`               | Specify a custom name for module ids. |
| `moduleIds`              | `false`              | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) |
| `moduleRoot`             | `(sourceRoot)`       | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. |
| `only`                   | `null`               | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim. |
| `parserOpts`             | `{}`                 | An object containing the options to be passed down to the babel parser, babylon |
| `plugins`                | `[]`                 | List of [plugins](https://babeljs.io/docs/en/plugins) to load and use. |
| `presets`                | `[]`                 | List of [presets](https://babeljs.io/docs/en/plugins#presets) (a set of plugins) to load and use. |
| `retainLines`            | `false`              | Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE:** This will not retain the columns) |
| `resolveModuleSource`    | `null`               | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)`. |
| `shouldPrintComment`     | `null`               | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used. |
| `sourceFileName`         | `(filenameRelative)` | Set `sources[0]` on returned source map. |
| `sourceMaps`             | `false`              | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. |
| `sourceMapTarget`        | `(filenameRelative)` | Set `file` on returned source map. |
| `sourceRoot`             | `(moduleRoot)`       | The root from which all sources are relative. |
| `sourceType`             | `"module"`           | Indicate the mode the code should be parsed in. Can be either "script" or "module". |
| `wrapPluginVisitorMethod`| `null`               | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.

---
_Source: https://npm.io/package/babel-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
