or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-operations.mdbrowser-integration.mdindex.mdplugin-system.mdtransformation.mdutilities.md
tile.json

tessl/npm-babel-core

Babel compiler core providing programmatic JavaScript code transformation API with plugin support and source maps

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-core@6.26.x

To install, run

npx @tessl/cli install tessl/npm-babel-core@6.26.0

index.mddocs/

Babel Core

Babel Core is the programmatic API for the Babel JavaScript transpiler, providing comprehensive code transformation capabilities. It offers synchronous and asynchronous methods for transforming JavaScript code strings, files, and ASTs, with full plugin system integration, source map generation, and extensive configuration options.

Package Information

  • Package Name: babel-core
  • Package Type: npm
  • Language: JavaScript (with Flow type annotations)
  • Installation: npm install babel-core

Core Imports

const babel = require("babel-core");
const { 
  transform, transformFile, transformFileSync, transformFromAst, 
  analyse, File, Pipeline, OptionManager, buildExternalHelpers,
  template, traverse, types, messages, util, options,
  resolvePlugin, resolvePreset, version
} = babel;

ES6 imports:

import { 
  transform, transformFile, transformFileSync, transformFromAst,
  analyse, File, Pipeline, OptionManager, buildExternalHelpers,
  template, traverse, types, messages, util, options,
  resolvePlugin, resolvePreset, version
} from 'babel-core';
import * as babel from 'babel-core';

Basic Usage

const babel = require("babel-core");

// Transform code string
const result = babel.transform("const greeting = () => 'Hello World';", {
  presets: ["es2015"]
});
console.log(result.code); // transformed code
console.log(result.map);  // source map
console.log(result.ast);  // AST

// Transform file
babel.transformFile("input.js", { presets: ["es2015"] }, (err, result) => {
  if (err) throw err;
  console.log(result.code);
});

// Transform file synchronously
const fileResult = babel.transformFileSync("input.js", { presets: ["es2015"] });
console.log(fileResult.code);

Architecture

Babel Core is built around several key components:

  • Transform Pipeline: Core transformation orchestration via Pipeline class
  • File System: File class managing code parsing, transformation, and generation
  • Option Management: OptionManager for processing and normalizing configuration
  • Plugin System: Dynamic plugin loading and execution with visitor pattern
  • AST Processing: Integration with babylon parser and babel-generator
  • Source Maps: Built-in source map support with various output modes

Capabilities

Code Transformation

Core synchronous and asynchronous transformation functions for JavaScript code strings and files. Essential for build tools, CLI applications, and development servers.

function transform(code, opts);
function transformFile(filename, opts, callback);
function transformFileSync(filename, opts);

Code Transformation

AST Operations

Advanced AST-based transformations and analysis operations for direct AST manipulation and programmatic code analysis.

function transformFromAst(ast, code, opts);
function analyse(code, opts, visitor);

AST Operations

Browser Integration

Browser-specific API for client-side JavaScript transformation, script loading, and automatic transpilation of script tags.

function run(code, opts);
function load(url, callback, opts, hold);

Browser Integration

Plugin and Configuration System

Comprehensive plugin loading, configuration management, and preset system for extensible transformations.

class OptionManager {
  constructor(log, pipeline);
  init(opts);
}

const options;      // Configuration schema object

function resolvePlugin(name);
function resolvePreset(name);

Plugin System

Utility Functions

Helper functions for file type checking, option processing, and build tool integration.

const util = {
  canCompile(filename, altExts),
  list(val),
  regexify(val),
  arrayify(val, mapFn),
  booleanify(val),
  shouldIgnore(filename, ignore, only)
};

function buildExternalHelpers(whitelist, outputType);

Utilities

Configuration Options

Babel Core accepts extensive configuration options:

  • Core Options: ast, code, comments, compact, env, filename
  • Transformation: plugins, presets, sourceMaps, sourceType
  • File Processing: babelrc, ignore, only, retainLines
  • Parser/Generator: parserOpts, generatorOpts, resolveModuleSource

Full configuration documentation available in individual capability sections.

External Dependencies

Babel Core re-exports several essential Babel packages:

// Re-exported from external packages
const template;    // from babel-template
const traverse;    // from babel-traverse  
const types;       // from babel-types (as 't')
const messages;    // from babel-messages
const version;     // package version string

These provide template parsing, AST traversal, type checking, error messaging, and version information.