CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-preset-es2015

Babel preset for transforming ES2015 (ES6) features to ES5-compatible code with comprehensive plugin collection

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

babel-preset-es2015

babel-preset-es2015 is a comprehensive Babel preset that provides a complete collection of transformation plugins for converting ES2015 (ES6) JavaScript features to ES5-compatible code. It includes 24 individual transformation plugins covering all ES2015 language features like arrow functions, classes, destructuring, template literals, modules, and more.

Deprecation Notice: This package has been deprecated since Babel 7.0.0 in favor of @babel/preset-env, which provides more intelligent targeting based on supported environments rather than language version.

Package Information

  • Package Name: babel-preset-es2015
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev babel-preset-es2015

Core Imports

This preset is typically used via Babel configuration files rather than direct imports:

.babelrc

{
  "presets": ["es2015"]
}

babel.config.js

module.exports = {
  presets: ["es2015"]
};

For direct imports (advanced usage):

const es2015 = require("babel-preset-es2015");

Basic Usage

Configuration File Usage (.babelrc)

{
  "presets": ["es2015"]
}

With Options

{
  "presets": [
    ["es2015", {
      "loose": true,
      "modules": false,
      "spec": true
    }]
  ]
}

Programmatic Usage with babel-core

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

// Using preset by name (most common)
const result = babel.transform(code, {
  presets: ["es2015"]
});

// Using with options
const resultWithOptions = babel.transform(code, {
  presets: [["es2015", { loose: true, modules: "amd" }]]
});

// Direct preset import (advanced)
const es2015 = require("babel-preset-es2015");
const directResult = babel.transform(code, {
  presets: [es2015]
});

Architecture

babel-preset-es2015 follows Babel's preset architecture:

  • Static Configuration: Default export provides pre-configured plugin array
  • Dynamic Configuration: buildPreset function creates customized configurations
  • Plugin Orchestration: Bundles 24 ES2015 transformation plugins in correct execution order
  • Backward Compatibility: Dual export strategy supports both old and new Babel versions

Capabilities

Default Preset Configuration

The main export is a preset configuration object with default ES2015 transformation settings.

// Default export - preset configuration object with buildPreset property
interface PresetConfig {
  plugins: Array<PluginConfiguration>;
  buildPreset?: (context: any, options?: PresetOptions) => { plugins: Array<PluginConfiguration> };
}

Usage:

const es2015 = require("babel-preset-es2015");
console.log(es2015.plugins); // Array of plugin configurations
console.log(typeof es2015.buildPreset); // "function"

Custom Preset Builder

The preset object has a buildPreset property function for creating customized configurations.

/**
 * Property function on the default export for creating customized preset configurations
 * @param context - Babel context object (typically null)
 * @param options - Configuration options
 * @returns Preset configuration object with plugins array
 */
preset.buildPreset(
  context: any,
  options?: PresetOptions
): { plugins: Array<PluginConfiguration> };

interface PresetOptions {
  /** Enable loose transformations for faster, less spec-compliant output */
  loose?: boolean;
  /** Module transformation type or false to disable module transforms */
  modules?: "commonjs" | "amd" | "umd" | "systemjs" | false;
  /** Enable spec-compliant transformations for more accurate ES2015 behavior */
  spec?: boolean;
}

Usage:

const es2015 = require("babel-preset-es2015");

// Create custom preset using buildPreset property
const customPreset = es2015.buildPreset(null, {
  loose: true,
  modules: "amd",
  spec: false
});

// Use in Babel configuration
const babel = require("babel-core");
const result = babel.transform(code, {
  presets: [customPreset]
});

Option: loose

Controls the transformation style for plugins that support loose mode.

interface LooseOption {
  /** When true, enables faster but less spec-compliant transformations */
  loose: boolean; // default: false
}

Effect: Loose mode produces simpler, faster code but may not handle all edge cases according to ES2015 specification.

Examples:

  • Classes: Uses simple constructor functions instead of complex inheritance helpers
  • Template literals: Uses string concatenation instead of tagged template helpers
  • Destructuring: Uses simpler variable assignments where possible

Option: modules

Controls ES6 module transformation to different module systems.

interface ModulesOption {
  /** Target module system or false to preserve ES6 modules */
  modules: "commonjs" | "amd" | "umd" | "systemjs" | false; // default: "commonjs"
}

Module Types:

  • "commonjs": Node.js style require()/module.exports
  • "amd": Asynchronous Module Definition for RequireJS
  • "umd": Universal Module Definition for browsers and Node.js
  • "systemjs": SystemJS dynamic module loader format
  • false: Preserve ES6 import/export statements

Option: spec

Controls whether to use spec-compliant transformations.

interface SpecOption {
  /** When true, uses more spec-compliant but potentially slower transformations */
  spec: boolean; // default: false
}

Effect: Spec mode produces code that more closely follows ES2015 specification behavior, but may be larger and slower.

Error Handling

The preset validates options and throws descriptive errors for invalid configurations:

// Thrown for invalid loose option
throw new Error("Preset es2015 'loose' option must be a boolean.");

// Thrown for invalid spec option  
throw new Error("Preset es2015 'spec' option must be a boolean.");

// Thrown for invalid modules option
throw new Error(
  "Preset es2015 'modules' option must be 'false' to indicate no modules\n" +
  "or a module type which be be one of: 'commonjs' (default), 'amd', 'umd', 'systemjs'"
);

Plugin Collection

The preset includes these 24 ES2015 transformation plugins in execution order:

Core Language Features

  • babel-plugin-transform-es2015-template-literals: Template string literals
  • babel-plugin-transform-es2015-literals: Numeric and string literal improvements
  • babel-plugin-transform-es2015-function-name: Function name inference
  • babel-plugin-transform-es2015-arrow-functions: Arrow function syntax
  • babel-plugin-transform-es2015-block-scoped-functions: Block-scoped function declarations
  • babel-plugin-transform-es2015-classes: Class declarations and expressions
  • babel-plugin-transform-es2015-object-super: Super calls in object methods
  • babel-plugin-transform-es2015-shorthand-properties: Object shorthand properties
  • babel-plugin-transform-es2015-duplicate-keys: Duplicate object key handling
  • babel-plugin-transform-es2015-computed-properties: Computed property names
  • babel-plugin-transform-es2015-for-of: For-of loop iteration
  • babel-plugin-transform-es2015-sticky-regex: Sticky (y) regex flag
  • babel-plugin-transform-es2015-unicode-regex: Unicode (u) regex flag
  • babel-plugin-check-es2015-constants: Const declaration validation
  • babel-plugin-transform-es2015-spread: Spread operator
  • babel-plugin-transform-es2015-parameters: Default and rest parameters
  • babel-plugin-transform-es2015-destructuring: Destructuring assignments
  • babel-plugin-transform-es2015-block-scoping: Let and const declarations
  • babel-plugin-transform-es2015-typeof-symbol: Typeof operator with symbols

Module Systems

  • babel-plugin-transform-es2015-modules-commonjs: CommonJS modules
  • babel-plugin-transform-es2015-modules-systemjs: SystemJS modules
  • babel-plugin-transform-es2015-modules-amd: AMD modules
  • babel-plugin-transform-es2015-modules-umd: UMD modules

Advanced Features

  • babel-plugin-transform-regenerator: Generator functions (configured with async: false, asyncGenerators: false)

Types

interface PluginConfiguration {
  /** Plugin function or [plugin, options] array */
  0: Function | [Function, object];
}

interface PresetExport {
  /** Array of Babel plugin configurations */
  plugins: Array<PluginConfiguration>;
  /** Property function to create custom preset configurations (non-enumerable) */
  buildPreset?: (context: any, options?: PresetOptions) => { plugins: Array<PluginConfiguration> };
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-preset-es2015@6.24.x
Publish Source
CLI
Badge
tessl/npm-babel-preset-es2015 badge