CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-runtime

Self-contained Babel runtime providing polyfills and helpers without polluting the global scope

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 Runtime

Babel Runtime is a self-contained runtime library for Babel transformations that provides polyfills and helper functions without polluting the global scope. It serves as a companion to babel-plugin-transform-runtime, offering clean access to ES6+ features and Babel's transformation utilities for environments that need modern JavaScript functionality with backward compatibility.

Package Information

  • Package Name: babel-runtime
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install babel-runtime

Core Imports

The babel-runtime package provides individual modules for each feature, typically imported automatically by babel-plugin-transform-runtime:

// Complete core-js library access
import coreJs from "babel-runtime/core-js";

// Individual core-js polyfills - imported by babel-plugin-transform-runtime
import _Promise from "babel-runtime/core-js/promise";
import _Symbol from "babel-runtime/core-js/symbol";
import _includes from "babel-runtime/core-js/array/includes";

// Babel helpers - imported by babel-plugin-transform-runtime
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
import _classCallCheck from "babel-runtime/helpers/classCallCheck";

// Regenerator runtime - imported by babel-plugin-transform-runtime
import _regeneratorRuntime from "babel-runtime/regenerator";

Manual usage (use babel-plugin-transform-runtime for automatic imports):

// ES modules
import coreJs from "babel-runtime/core-js";
const Promise = coreJs.default.Promise;
const Symbol = coreJs.default.Symbol;

// CommonJS
const Promise = require("babel-runtime/core-js/promise").default;
const regeneratorRuntime = require("babel-runtime/regenerator");
const coreJs = require("babel-runtime/core-js").default;

Basic Usage

Babel Runtime is designed to be used automatically with babel-plugin-transform-runtime. The plugin transforms your code to use these runtime modules:

// Input code (before transformation)
async function fetchData() {
  const data = await new Promise(resolve => {
    setTimeout(() => resolve([1, 2, 3]), 1000);
  });
  return data.includes(2);
}

// Transformed code (after babel-plugin-transform-runtime)
import _regeneratorRuntime from "babel-runtime/regenerator";
import _Promise from "babel-runtime/core-js/promise";
import _includes from "babel-runtime/core-js/array/includes";
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";

var fetchData = function () {
  var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
    var data;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return new _Promise(function (resolve) {
            setTimeout(function () {
              return resolve([1, 2, 3]);
            }, 1000);
          });
        case 2:
          data = _context.sent;
          return _context.abrupt("return", _includes(data).call(data, 2));
        case 4:
        case "end":
          return _context.stop();
      }
    }, _callee, this);
  }));

  return function fetchData() {
    return _ref.apply(this, arguments);
  };
}();

Key transformation patterns:

  • Async functions → regenerator runtime + asyncToGenerator helper
  • Polyfillable features → individual core-js imports instead of global polyfills
  • Class inheritance → classCallCheck, createClass, inherits helpers
  • Object spread → extends helper instead of Object.assign
  • Array destructuring → slicedToArray helper

Architecture

Babel Runtime provides a three-tier module system for clean, isolated access to JavaScript polyfills and transformation utilities:

Tier 1: Core-js Library Access

  • core-js.js: Direct access to the complete core-js library (core-js/library)
  • Provides all ES6+ features in a single import

Tier 2: Individual Core-js Polyfills

  • core-js/* modules: Individual ES6+ polyfill modules organized by feature type
  • Built-in objects: Symbol, Promise, Map, Set, etc.
  • Method polyfills: Array, Object, String, Number, Math, Reflect methods
  • Prevents global scope pollution by providing isolated implementations

Tier 3: Babel Transformation Helpers

  • helpers/* modules: Utility functions for Babel code transformations
  • Class support: classCallCheck, createClass, inherits
  • Async support: asyncToGenerator, asyncGenerator
  • Module interop: interopRequireDefault, interopRequireWildcard
  • Object operations: extends, objectWithoutProperties, defineProperty

Tier 4: Generator Runtime

  • regenerator/: Runtime environment for generators and async functions
  • Re-exports the regenerator-runtime package
  • Provides execution context for transformed generator and async code

Module Export Pattern:

  • Most modules export with { default: implementation, __esModule: true }
  • regenerator module exports directly (no wrapper)
  • All helpers available in camelCase, kebab-case, and underscore-kebab formats

Capabilities

Core-js Polyfills

ES6+ polyfills for built-in objects and methods, providing modern JavaScript features without modifying global prototypes. Includes support for Promise, Symbol, Map, Set, Array methods, Object methods, and more.

// Built-in objects
import _Promise from "babel-runtime/core-js/promise";
import _Symbol from "babel-runtime/core-js/symbol";
import _Map from "babel-runtime/core-js/map";
import _Set from "babel-runtime/core-js/set";

// Method polyfills
import _includes from "babel-runtime/core-js/array/includes";
import _assign from "babel-runtime/core-js/object/assign";
import _from from "babel-runtime/core-js/array/from";

Core-js Polyfills

Babel Helpers

Helper functions for various Babel transformations including class creation, inheritance, async/await conversion, destructuring, and module interop.

// Class helpers
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
import _createClass from "babel-runtime/helpers/createClass";
import _inherits from "babel-runtime/helpers/inherits";

// Async/generator helpers
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
import _asyncGenerator from "babel-runtime/helpers/asyncGenerator";

// Module interop helpers
import _interopRequireDefault from "babel-runtime/helpers/interopRequireDefault";
import _interopRequireWildcard from "babel-runtime/helpers/interopRequireWildcard";

Babel Helpers

Regenerator Runtime

Generator function and async/await support through the regenerator-runtime package, providing the runtime environment for transformed generator and async functions.

import regeneratorRuntime from "babel-runtime/regenerator";

// The regenerator runtime provides the execution environment
// for transformed generator and async functions

Regenerator Runtime

Types

// All modules export with this pattern
interface BabelRuntimeModule<T> {
  default: T;
  __esModule: true;
}

// Core-js modules provide the polyfilled constructor/function
type CoreJSModule<T> = BabelRuntimeModule<T>;

// Helper modules provide transformation utility functions  
type HelperModule<T extends Function> = BabelRuntimeModule<T>;

// Regenerator module provides the runtime object
type RegeneratorModule = any; // Direct export from regenerator-runtime package
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-runtime@6.26.x
Publish Source
CLI
Badge
tessl/npm-babel-runtime badge