babel-core
Babel compiler core.
Last updated 7 years ago by loganfsmyth .
MIT · Repository · Original npm · Tarball · package.json
$ npm install babel-core 
SYNC missed versions from official npm registry.

babel-core

Babel compiler core.

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 to disable it.

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

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

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

Example

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

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

Asynchronously transforms the entire contents of a file.

babel.transformFile(filename, options, callback)

Example

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

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

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

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

Example

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

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

Given, an AST, transform it.

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.
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, 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 to load and use.
presets [] List of 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).

Current Tags

  • 7.0.0-bridge.0                                ...           bridge (7 years ago)
  • 6.26.3                                ...           latest (7 years ago)
  • 6.26.3                                ...           lerna-temp (7 years ago)
  • 7.0.0-beta.3                                ...           next (7 years ago)
  • 5.8.38                                ...           old (9 years ago)

257 Versions

  • 6.26.3                                ...           7 years ago
  • 6.26.2                                ...           7 years ago
  • 7.0.0-bridge.0                                ...           7 years ago
  • 7.0.0-beta.3                                ...           7 years ago
  • 7.0.0-beta.2                                ...           7 years ago
  • 7.0.0-beta.1                                ...           7 years ago
  • 7.0.0-beta.0                                ...           7 years ago
  • 7.0.0-alpha.20                                ...           7 years ago
  • 6.26.0                                ...           7 years ago
  • 7.0.0-alpha.19                                ...           7 years ago
  • 7.0.0-alpha.18                                ...           7 years ago
  • 7.0.0-alpha.17                                ...           7 years ago
  • 7.0.0-alpha.16                                ...           7 years ago
  • 7.0.0-alpha.15                                ...           7 years ago
  • 7.0.0-alpha.14                                ...           7 years ago
  • 6.25.0                                ...           8 years ago
  • 7.0.0-alpha.12                                ...           8 years ago
  • 7.0.0-alpha.11                                ...           8 years ago
  • 7.0.0-alpha.10                                ...           8 years ago
  • 7.0.0-alpha.9                                ...           8 years ago
  • 7.0.0-alpha.8                                ...           8 years ago
  • 6.24.1                                ...           8 years ago
  • 7.0.0-alpha.7                                ...           8 years ago
  • 7.0.0-alpha.6                                ...           8 years ago
  • 7.0.0-alpha.3                                ...           8 years ago
  • 6.24.0                                ...           8 years ago
  • 7.0.0-alpha.2                                ...           8 years ago
  • 7.0.0-alpha.1                                ...           8 years ago
  • 6.23.1                                ...           8 years ago
  • 6.23.0                                ...           8 years ago
  • 6.22.1                                ...           8 years ago
  • 6.22.0                                ...           8 years ago
  • 6.21.0                                ...           8 years ago
  • 6.20.0                                ...           8 years ago
  • 6.18.2                                ...           8 years ago
  • 6.18.0                                ...           8 years ago
  • 6.17.0                                ...           8 years ago
  • 6.16.0                                ...           8 years ago
  • 6.14.0                                ...           8 years ago
  • 6.13.2                                ...           8 years ago
  • 6.13.1                                ...           8 years ago
  • 6.13.0                                ...           8 years ago
  • 6.11.4                                ...           8 years ago
  • 6.10.4                                ...           9 years ago
  • 6.9.1                                ...           9 years ago
  • 6.9.0                                ...           9 years ago
  • 6.8.0                                ...           9 years ago
  • 6.7.7                                ...           9 years ago
  • 6.7.6                                ...           9 years ago
  • 6.7.5                                ...           9 years ago
  • 6.7.4                                ...           9 years ago
  • 5.8.38                                ...           9 years ago
  • 6.7.2                                ...           9 years ago
  • 6.7.0                                ...           9 years ago
  • 6.6.5                                ...           9 years ago
  • 6.6.4                                ...           9 years ago
  • 6.6.0                                ...           9 years ago
  • 6.5.2-canary.ab7533ed                                ...           9 years ago
  • 6.5.2                                ...           9 years ago
  • 6.5.1                                ...           9 years ago
  • 6.5.0-1                                ...           9 years ago
  • 6.5.0                                ...           9 years ago
  • 5.8.35                                ...           9 years ago
  • 6.4.5                                ...           9 years ago
  • 6.4.0                                ...           9 years ago
  • 6.3.26                                ...           9 years ago
  • 6.3.21                                ...           9 years ago
  • 6.3.17                                ...           9 years ago
  • 6.3.15                                ...           9 years ago
  • 6.3.13                                ...           9 years ago
  • 6.3.2                                ...           9 years ago
  • 6.2.4                                ...           9 years ago
  • 6.2.1                                ...           9 years ago
  • 6.2.0                                ...           9 years ago
  • 6.1.21                                ...           9 years ago
  • 6.1.20                                ...           9 years ago
  • 6.1.19                                ...           9 years ago
  • 6.1.18                                ...           9 years ago
  • 6.1.17                                ...           9 years ago
  • 6.1.16                                ...           9 years ago
  • 6.1.15                                ...           9 years ago
  • 6.1.14                                ...           9 years ago
  • 6.1.13                                ...           9 years ago
  • 6.1.12                                ...           9 years ago
  • 6.1.11                                ...           9 years ago
  • 6.1.10                                ...           9 years ago
  • 6.1.9                                ...           9 years ago
  • 6.1.8                                ...           9 years ago
  • 6.1.7                                ...           9 years ago
  • 6.1.6                                ...           9 years ago
  • 6.1.5                                ...           9 years ago
  • 5.8.34                                ...           9 years ago
  • 6.1.4                                ...           9 years ago
  • 6.1.2                                ...           9 years ago
  • 6.0.20                                ...           9 years ago
  • 6.0.19                                ...           9 years ago
  • 6.0.18                                ...           9 years ago
  • 6.0.17                                ...           9 years ago
  • 6.0.16                                ...           9 years ago
  • 6.0.15                                ...           9 years ago
  • 6.0.14                                ...           9 years ago
  • 6.0.12                                ...           9 years ago
  • 6.0.2                                ...           9 years ago
  • 6.0.1                                ...           9 years ago
  • 6.0.0                                ...           9 years ago
  • 5.8.33 [deprecated]           ...           9 years ago
  • 5.8.32 [deprecated]           ...           9 years ago
  • 5.8.31 [deprecated]           ...           9 years ago
  • 5.8.30 [deprecated]           ...           9 years ago
  • 5.8.29 [deprecated]           ...           9 years ago
  • 5.8.25 [deprecated]           ...           9 years ago
  • 5.8.24 [deprecated]           ...           9 years ago
  • 5.8.23 [deprecated]           ...           9 years ago
  • 5.8.22 [deprecated]           ...           9 years ago
  • 5.8.21 [deprecated]           ...           9 years ago
  • 5.8.20 [deprecated]           ...           9 years ago
  • 5.8.19 [deprecated]           ...           9 years ago
  • 5.8.14 [deprecated]           ...           9 years ago
  • 5.8.12 [deprecated]           ...           9 years ago
  • 5.8.9 [deprecated]           ...           9 years ago
  • 5.8.8 [deprecated]           ...           9 years ago
  • 5.8.6 [deprecated]           ...           9 years ago
  • 5.8.5 [deprecated]           ...           9 years ago
  • 5.8.3 [deprecated]           ...           9 years ago
  • 5.8.2 [deprecated]           ...           9 years ago
  • 5.8.1 [deprecated]           ...           9 years ago
  • 5.7.4 [deprecated]           ...           9 years ago
  • 5.7.3 [deprecated]           ...           9 years ago
  • 5.7.2 [deprecated]           ...           9 years ago
  • 5.7.1 [deprecated]           ...           9 years ago
  • 5.7.0 [deprecated]           ...           9 years ago
  • 5.6.20 [deprecated]           ...           9 years ago
  • 5.6.19 [deprecated]           ...           9 years ago
  • 5.6.18 [deprecated]           ...           9 years ago
  • 5.6.16 [deprecated]           ...           9 years ago
  • 5.6.15 [deprecated]           ...           9 years ago
  • 5.6.14 [deprecated]           ...           9 years ago
  • 5.6.12 [deprecated]           ...           9 years ago
  • 5.6.11 [deprecated]           ...           9 years ago
  • 5.6.10 [deprecated]           ...           9 years ago
  • 5.6.7 [deprecated]           ...           9 years ago
  • 5.6.6 [deprecated]           ...           9 years ago
  • 5.6.5 [deprecated]           ...           9 years ago
  • 5.6.4 [deprecated]           ...           10 years ago
  • 5.6.3 [deprecated]           ...           10 years ago
  • 5.6.2 [deprecated]           ...           10 years ago
  • 5.6.1 [deprecated]           ...           10 years ago
  • 5.5.8 [deprecated]           ...           10 years ago
  • 5.5.7 [deprecated]           ...           10 years ago
  • 5.5.6 [deprecated]           ...           10 years ago
  • 5.5.5 [deprecated]           ...           10 years ago
  • 5.5.4 [deprecated]           ...           10 years ago
  • 5.5.3 [deprecated]           ...           10 years ago
  • 5.5.2 [deprecated]           ...           10 years ago
  • 5.5.1 [deprecated]           ...           10 years ago
  • 5.5.0 [deprecated]           ...           10 years ago
  • 5.4.7 [deprecated]           ...           10 years ago
  • 5.4.6 [deprecated]           ...           10 years ago
  • 5.4.5 [deprecated]           ...           10 years ago
  • 5.4.4 [deprecated]           ...           10 years ago
  • 5.4.3 [deprecated]           ...           10 years ago
  • 5.4.2 [deprecated]           ...           10 years ago
  • 5.4.1 [deprecated]           ...           10 years ago
  • 5.4.0 [deprecated]           ...           10 years ago
  • 5.3.3 [deprecated]           ...           10 years ago
  • 5.3.2 [deprecated]           ...           10 years ago
  • 5.3.1 [deprecated]           ...           10 years ago
  • 5.3.0 [deprecated]           ...           10 years ago
  • 5.2.17 [deprecated]           ...           10 years ago
  • 5.2.16 [deprecated]           ...           10 years ago
  • 5.2.15 [deprecated]           ...           10 years ago
  • 5.2.14 [deprecated]           ...           10 years ago
  • 5.2.13 [deprecated]           ...           10 years ago
  • 5.2.12 [deprecated]           ...           10 years ago
  • 5.2.11 [deprecated]           ...           10 years ago
  • 5.2.10 [deprecated]           ...           10 years ago
  • 5.2.9 [deprecated]           ...           10 years ago
  • 5.2.7 [deprecated]           ...           10 years ago
  • 5.2.6 [deprecated]           ...           10 years ago
  • 5.2.5 [deprecated]           ...           10 years ago
  • 5.2.4 [deprecated]           ...           10 years ago
  • 5.2.3 [deprecated]           ...           10 years ago
  • 5.2.2 [deprecated]           ...           10 years ago
  • 5.2.1 [deprecated]           ...           10 years ago
  • 5.2.0 [deprecated]           ...           10 years ago
  • 5.1.13 [deprecated]           ...           10 years ago
  • 5.1.12 [deprecated]           ...           10 years ago
  • 5.1.11 [deprecated]           ...           10 years ago
  • 5.1.10 [deprecated]           ...           10 years ago
  • 5.1.9 [deprecated]           ...           10 years ago
  • 5.1.8 [deprecated]           ...           10 years ago
  • 5.1.7 [deprecated]           ...           10 years ago
  • 5.1.6 [deprecated]           ...           10 years ago
  • 5.1.5 [deprecated]           ...           10 years ago
  • 5.1.4 [deprecated]           ...           10 years ago
  • 5.1.3 [deprecated]           ...           10 years ago
  • 5.1.2 [deprecated]           ...           10 years ago
  • 5.1.1 [deprecated]           ...           10 years ago
  • 5.1.0 [deprecated]           ...           10 years ago
  • 5.0.13 [deprecated]           ...           10 years ago
  • 5.0.12 [deprecated]           ...           10 years ago
  • 5.0.11 [deprecated]           ...           10 years ago
  • 5.0.10 [deprecated]           ...           10 years ago
  • 5.0.9 [deprecated]           ...           10 years ago
  • 5.0.8 [deprecated]           ...           10 years ago
  • 5.0.7 [deprecated]           ...           10 years ago
  • 5.0.6 [deprecated]           ...           10 years ago
  • 5.0.5 [deprecated]           ...           10 years ago
  • 5.0.4 [deprecated]           ...           10 years ago
  • 5.0.3 [deprecated]           ...           10 years ago
  • 5.0.2 [deprecated]           ...           10 years ago
  • 5.0.1 [deprecated]           ...           10 years ago
  • 5.0.0 [deprecated]           ...           10 years ago
  • 5.0.0-beta4                                ...           10 years ago
  • 5.0.0-beta3                                ...           10 years ago
  • 5.0.0-beta2                                ...           10 years ago
  • 4.7.16                                ...           10 years ago
  • 4.7.15                                ...           10 years ago
  • 4.7.14                                ...           10 years ago
  • 4.7.13                                ...           10 years ago
  • 4.7.12                                ...           10 years ago
  • 4.7.11                                ...           10 years ago
  • 4.7.10                                ...           10 years ago
  • 4.7.9                                ...           10 years ago
  • 4.7.8                                ...           10 years ago
  • 4.7.7                                ...           10 years ago
  • 4.7.6                                ...           10 years ago
  • 4.7.5                                ...           10 years ago
  • 4.7.4                                ...           10 years ago
  • 4.7.3                                ...           10 years ago
  • 4.7.2                                ...           10 years ago
  • 4.7.1                                ...           10 years ago
  • 4.7.0                                ...           10 years ago
  • 4.6.6                                ...           10 years ago
  • 4.6.5                                ...           10 years ago
  • 4.6.4                                ...           10 years ago
  • 4.6.3                                ...           10 years ago
  • 4.6.1                                ...           10 years ago
  • 4.6.0                                ...           10 years ago
  • 4.5.5                                ...           10 years ago
  • 4.5.4                                ...           10 years ago
  • 4.5.3                                ...           10 years ago
  • 4.5.2                                ...           10 years ago
  • 4.5.1                                ...           10 years ago
  • 4.5.0                                ...           10 years ago
  • 4.4.6                                ...           10 years ago
  • 4.4.5                                ...           10 years ago
  • 4.4.4                                ...           10 years ago
  • 4.4.3                                ...           10 years ago
  • 4.4.2                                ...           10 years ago
  • 4.4.1                                ...           10 years ago
  • 4.3.0                                ...           10 years ago
  • 4.2.1                                ...           10 years ago
  • 4.2.0                                ...           10 years ago
  • 4.1.1                                ...           10 years ago
  • 4.0.2                                ...           10 years ago
  • 4.0.1                                ...           10 years ago
Downloads
Total 60
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 29
Dependencies (19)

© 2010 - cnpmjs.org x YWFE | Home | YWFE