or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

babel-preset-stage-0

babel-preset-stage-0 is a Babel preset that enables experimental JavaScript language features in stage 0 of the TC39 proposal process. This preset provides access to the most cutting-edge JavaScript syntax and constructs that are still in early development stages, making it ideal for experimental projects and early adopters who want to leverage the latest language innovations.

Package Information

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

Core Imports

babel-preset-stage-0 is used as a preset configuration in Babel, not imported directly in code. The package's main entry point is lib/index.js (compiled from src/index.js), but users reference it by name in Babel configuration files.

For programmatic usage (requiring the preset directly):

// CommonJS - accessing the compiled preset object
const stage0Preset = require("babel-preset-stage-0");
// Returns: { presets: [...], plugins: [...] }

// Using with babel-core transform
const babel = require("babel-core");
const result = babel.transform(code, {
  presets: [stage0Preset]
});

For Babel configuration files:

.babelrc:

{
  "presets": ["stage-0"]
}

babel.config.js:

module.exports = {
  presets: ["babel-preset-stage-0"]
};

Basic Usage

Via .babelrc (Recommended)

Create a .babelrc file in your project root:

{
  "presets": ["stage-0"]
}

Via CLI

babel script.js --presets stage-0

Via Node API

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

const result = babel.transform(code, {
  presets: ["stage-0"]
});

Architecture

babel-preset-stage-0 follows Babel's preset hierarchy system:

  • Preset Chain: stage-0 → stage-1 → stage-2 → stage-3 → finished proposals
  • Stage-0 Features: Most experimental features (do-expressions, function-bind operator)
  • Inherited Features: All features from higher-numbered stages (stage-1, stage-2, stage-3)
  • Plugin System: Composed of individual Babel transform plugins

Build and Compilation Process

The preset follows Babel's standard build process:

  • Source Code: Written as ES6 modules in src/index.js
  • Compilation: Babel compiles ES6 source to CommonJS in lib/index.js
  • Export Pattern: Uses dual exports (exports.default + module.exports) for maximum compatibility
  • Build Tools: Compiled using Babel 6 with es2015 preset and custom export plugin
  • Published Code: The lib/ directory contains the actual code consumed by users via npm

Capabilities

Preset Configuration

The main export of babel-preset-stage-0 is a Babel preset configuration object that tells Babel which transformations to apply.

/**
 * Main preset export (CommonJS format - compiled from ES6 source)
 * This is the actual structure published to npm as lib/index.js
 */
module.exports = {
  /** Array of child presets - includes babel-preset-stage-1 which inherits stage-2 and stage-3 */
  presets: [require("babel-preset-stage-1")],
  /** Array of plugins specific to stage-0 experimental features */
  plugins: [
    require("babel-plugin-transform-do-expressions"),
    require("babel-plugin-transform-function-bind")
  ]
};

/**
 * Source code structure (ES6 modules in src/index.js)
 * This gets compiled to the CommonJS format above
 */
import presetStage1 from "babel-preset-stage-1";
import transformDoExpressions from "babel-plugin-transform-do-expressions";
import transformFunctionBind from "babel-plugin-transform-function-bind";

export default {
  presets: [presetStage1],
  plugins: [transformDoExpressions, transformFunctionBind]
};

Type Definitions

/**
 * Babel Preset Configuration Object
 * Structure returned by babel-preset-stage-0
 */
interface BabelPresetConfig {
  /** Array of child presets to include in transformation chain */
  presets: BabelPreset[];
  /** Array of transform plugins to apply */
  plugins: BabelPlugin[];
}

/**
 * Individual preset or plugin references
 * Can be plugin functions, preset objects, or string names
 */
type BabelPreset = Function | Object | string;
type BabelPlugin = Function | Object | string;

/**
 * The actual exported object structure
 */
const presetStage0: BabelPresetConfig = {
  presets: [
    /* babel-preset-stage-1 (includes stage-2 and stage-3) */
  ],
  plugins: [
    /* babel-plugin-transform-do-expressions */,
    /* babel-plugin-transform-function-bind */
  ]
};

Stage-0 Specific Features

babel-preset-stage-0 provides two experimental language features:

Do Expressions

Enables do expressions that return values from statement blocks.

Plugin: babel-plugin-transform-do-expressions

Syntax Example:

// Before transformation
const result = do {
  if (condition) {
    'success'
  } else {
    'failure'
  }
};

// Allows statement blocks to return values like expressions

Function Bind Operator

Enables the function bind operator (::) for method binding.

Plugin: babel-plugin-transform-function-bind

Syntax Example:

// Before transformation
const boundMethod = obj::method;
const result = obj::method(arg);

// Equivalent to:
const boundMethod = method.bind(obj);
const result = method.call(obj, arg);

Inherited Features

Through babel-preset-stage-1@^6.24.1, this preset includes all features from:

  • Stage-1 Features:
    • babel-plugin-transform-class-constructor-call@^6.24.1
    • babel-plugin-transform-export-extensions@^6.22.0
  • Stage-2 Features: All plugins from babel-preset-stage-2@^6.24.1
  • Stage-3 Features: All plugins included transitively through the stage hierarchy

Configuration Options

babel-preset-stage-0 accepts no configuration options - it provides a fixed set of transformations. To customize behavior, configure individual plugins instead:

// Custom configuration bypassing the preset
module.exports = {
  plugins: [
    "babel-plugin-transform-do-expressions",
    "babel-plugin-transform-function-bind",
    // ... other stage-1/2/3 plugins
  ]
};

Compatibility

  • Babel Version: Requires Babel 6.x
  • Node.js: Compatible with Node.js environments where Babel 6 runs
  • Browser: Transforms code for any target browser (output depends on other presets)
  • Build Tools: Works with webpack, Rollup, and other bundlers that support Babel

Migration Notes

This preset is part of Babel 6's stage preset system, which was deprecated in Babel 7. For modern projects:

  • Babel 7+: Use individual plugins instead of stage presets
  • Replacement: Manually include @babel/plugin-proposal-do-expressions and @babel/plugin-proposal-function-bind
  • Alternative: Use @babel/preset-env with appropriate targets

Dependencies

The preset internally depends on (exact versions from package.json):

  • babel-plugin-transform-do-expressions@^6.22.0 - Enables do-expression syntax
  • babel-plugin-transform-function-bind@^6.22.0 - Enables function bind operator (::)
  • babel-preset-stage-1@^6.24.1 - Includes all stage-1, stage-2, and stage-3 features

Transitive Dependencies (via babel-preset-stage-1)

Through the stage hierarchy, this preset inherits:

  • Stage-1: babel-plugin-transform-class-constructor-call, babel-plugin-transform-export-extensions
  • Stage-2: All stage-2 plugins (object spread, async/await, decorators, etc.)
  • Stage-3: All stage-3 plugins (exponentiation operator, trailing commas, etc.)