Helper functions for various Babel transformations including class creation, inheritance, async/await conversion, destructuring, and module interop. Each helper is available as an individual module and also with kebab-case naming for compatibility.
Helper functions for ES6 class transformations and inheritance.
/**
* Ensures a class is called with 'new'
* @module babel-runtime/helpers/classCallCheck
* @param {any} instance - The instance being created
* @param {Function} Constructor - The constructor function
* @throws {TypeError} When class is called without 'new'
*/
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
/**
* Creates class methods with proper descriptors
* @module babel-runtime/helpers/createClass
* @param {Function} Constructor - The constructor function
* @param {Array} protoProps - Prototype method descriptors
* @param {Array} staticProps - Static method descriptors
* @returns {Function} The constructor with methods defined
*/
import _createClass from "babel-runtime/helpers/createClass";
/**
* Sets up inheritance between classes
* @module babel-runtime/helpers/inherits
* @param {Function} subClass - The child class constructor
* @param {Function} superClass - The parent class constructor
* @throws {TypeError} When superClass is not a function or null
*/
import _inherits from "babel-runtime/helpers/inherits";
/**
* Handles constructor return values for classes
* @module babel-runtime/helpers/possibleConstructorReturn
* @param {any} self - The instance ('this' value)
* @param {any} call - The result of super() call
* @returns {any} The proper instance value
* @throws {ReferenceError} When 'this' hasn't been initialized
*/
import _possibleConstructorReturn from "babel-runtime/helpers/possibleConstructorReturn";Usage Example:
// Input ES6 class
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a sound`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name} barks`);
}
}
// Transformed using helpers
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
import _createClass from "babel-runtime/helpers/createClass";
import _inherits from "babel-runtime/helpers/inherits";
import _possibleConstructorReturn from "babel-runtime/helpers/possibleConstructorReturn";
var Animal = function () {
function Animal(name) {
_classCallCheck(this, Animal);
this.name = name;
}
_createClass(Animal, [{
key: "speak",
value: function speak() {
console.log(this.name + " makes a sound");
}
}]);
return Animal;
}();
var Dog = function (_Animal) {
_inherits(Dog, _Animal);
function Dog() {
_classCallCheck(this, Dog);
return _possibleConstructorReturn(this, _Animal.apply(this, arguments));
}
_createClass(Dog, [{
key: "speak",
value: function speak() {
console.log(this.name + " barks");
}
}]);
return Dog;
}(Animal);Helper functions for async/await and generator transformations.
/**
* Transforms async functions to use Promises
* @module babel-runtime/helpers/asyncToGenerator
* @param {GeneratorFunction} fn - The generator function representing async function
* @returns {Function} A function that returns a Promise
*/
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
/**
* Creates async generator wrapper with proper iteration protocol
* @module babel-runtime/helpers/asyncGenerator
* @returns {Object} Object with wrap and await methods
*/
import _asyncGenerator from "babel-runtime/helpers/asyncGenerator";
/**
* Handles async generator delegation (yield*)
* @module babel-runtime/helpers/asyncGeneratorDelegate
* @param {AsyncIterable} inner - The inner async iterable
* @param {Function} awaitWrap - The await wrapper function
* @returns {AsyncIterator} Delegating async iterator
*/
import _asyncGeneratorDelegate from "babel-runtime/helpers/asyncGeneratorDelegate";
/**
* Creates async iterator from iterable
* @module babel-runtime/helpers/asyncIterator
* @param {any} iterable - Object to create async iterator from
* @returns {AsyncIterator} The async iterator
* @throws {TypeError} When object is not async iterable
*/
import _asyncIterator from "babel-runtime/helpers/asyncIterator";Usage Example:
// Input async function
async function fetchData() {
const response = await fetch('/api/data');
return response.json();
}
// Transformed using asyncToGenerator
import _regeneratorRuntime from "babel-runtime/regenerator";
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
var fetchData = function () {
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var response;
return _regeneratorRuntime.wrap(function _callee(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return fetch('/api/data');
case 2:
response = _context.sent;
return _context.abrupt('return', response.json());
case 4:
case 'end':
return _context.stop();
}
}, _callee, this);
}));
return function fetchData() {
return _ref.apply(this, arguments);
};
}();Helper functions for object manipulation and property handling.
/**
* Defines a property with fallback for simple assignment
* @module babel-runtime/helpers/defineProperty
* @param {Object} obj - The object to define property on
* @param {string|Symbol} key - The property key
* @param {any} value - The property value
* @returns {Object} The object with the property defined
*/
import _defineProperty from "babel-runtime/helpers/defineProperty";
/**
* Defines multiple enumerable properties on an object
* @module babel-runtime/helpers/defineEnumerableProperties
* @param {Object} obj - The target object
* @param {Object} descs - Object with property descriptors
* @returns {Object} The object with properties defined
*/
import _defineEnumerableProperties from "babel-runtime/helpers/defineEnumerableProperties";
/**
* Object extension utility (Object.assign fallback)
* @module babel-runtime/helpers/extends
* @param {Object} target - The target object
* @param {...Object} sources - Source objects to merge
* @returns {Object} The extended target object
*/
import _extends from "babel-runtime/helpers/extends";
/**
* Sets default properties on an object
* @module babel-runtime/helpers/defaults
* @param {Object} obj - The target object
* @param {Object} defaults - Default properties to set
* @returns {Object} The object with defaults applied
*/
import _defaults from "babel-runtime/helpers/defaults";
/**
* Creates new object excluding specified properties
* @module babel-runtime/helpers/objectWithoutProperties
* @param {Object} obj - The source object
* @param {Array<string>} keys - Keys to exclude
* @returns {Object} New object without excluded properties
*/
import _objectWithoutProperties from "babel-runtime/helpers/objectWithoutProperties";
/**
* Checks object destructuring target is not null/undefined
* @module babel-runtime/helpers/objectDestructuringEmpty
* @param {any} obj - The object to check
* @throws {TypeError} When obj is null or undefined
*/
import _objectDestructuringEmpty from "babel-runtime/helpers/objectDestructuringEmpty";Helper functions for super property access and getter/setter operations.
/**
* Gets super property value with proper receiver binding
* @module babel-runtime/helpers/get
* @param {Object} object - The object to get property from
* @param {string|Symbol} property - The property name
* @param {Object} receiver - The receiver for getter calls
* @returns {any} The property value
*/
import _get from "babel-runtime/helpers/get";
/**
* Sets super property value with proper receiver binding
* @module babel-runtime/helpers/set
* @param {Object} object - The object to set property on
* @param {string|Symbol} property - The property name
* @param {any} value - The value to set
* @param {Object} receiver - The receiver for setter calls
* @returns {any} The value that was set
*/
import _set from "babel-runtime/helpers/set";Helper functions for array operations and destructuring assignments.
/**
* Converts array-like to array for destructuring
* @module babel-runtime/helpers/slicedToArray
* @param {ArrayLike} arr - Array-like object to convert
* @param {number} i - Maximum number of elements to extract
* @returns {Array} Array with at most i elements
* @throws {TypeError} When attempting to destructure non-iterable
*/
import _slicedToArray from "babel-runtime/helpers/slicedToArray";
/**
* Loose version of slicedToArray with simpler iteration
* @module babel-runtime/helpers/slicedToArrayLoose
* @param {ArrayLike} arr - Array-like object to convert
* @param {number} i - Maximum number of elements to extract
* @returns {Array} Array with at most i elements
* @throws {TypeError} When attempting to destructure non-iterable
*/
import _slicedToArrayLoose from "babel-runtime/helpers/slicedToArrayLoose";
/**
* Converts array-like to true array
* @module babel-runtime/helpers/toArray
* @param {ArrayLike} arr - Array-like object to convert
* @returns {Array} Converted array
*/
import _toArray from "babel-runtime/helpers/toArray";
/**
* Creates consumable array for spread operations
* @module babel-runtime/helpers/toConsumableArray
* @param {ArrayLike} arr - Array-like object to convert
* @returns {Array} New array safe for spreading
*/
import _toConsumableArray from "babel-runtime/helpers/toConsumableArray";Helper functions for tagged template literal transformations.
/**
* Creates frozen template literal object
* @module babel-runtime/helpers/taggedTemplateLiteral
* @param {Array<string>} strings - Template string parts
* @param {Array<string>} raw - Raw template string parts
* @returns {Object} Frozen template object with raw property
*/
import _taggedTemplateLiteral from "babel-runtime/helpers/taggedTemplateLiteral";
/**
* Creates loose template literal object (not frozen)
* @module babel-runtime/helpers/taggedTemplateLiteralLoose
* @param {Array<string>} strings - Template string parts
* @param {Array<string>} raw - Raw template string parts
* @returns {Object} Template object with raw property
*/
import _taggedTemplateLiteralLoose from "babel-runtime/helpers/taggedTemplateLiteralLoose";Helper functions for module system interoperability.
/**
* Handles default import from CommonJS modules
* @module babel-runtime/helpers/interopRequireDefault
* @param {any} obj - The module object
* @returns {Object} Object with default property or wrapped module
*/
import _interopRequireDefault from "babel-runtime/helpers/interopRequireDefault";
/**
* Handles wildcard import from CommonJS modules
* @module babel-runtime/helpers/interopRequireWildcard
* @param {any} obj - The module object
* @returns {Object} Namespace object with all exports
*/
import _interopRequireWildcard from "babel-runtime/helpers/interopRequireWildcard";Usage Example:
// Input ES6 imports
import defaultExport from 'some-module';
import * as namespace from 'another-module';
// Transformed using interop helpers
import _interopRequireDefault from "babel-runtime/helpers/interopRequireDefault";
import _interopRequireWildcard from "babel-runtime/helpers/interopRequireWildcard";
var _someModule = _interopRequireDefault(require('some-module'));
var _anotherModule = _interopRequireWildcard(require('another-module'));
var defaultExport = _someModule.default;
var namespace = _anotherModule;Helper functions for type checking and validation.
/**
* Safe typeof implementation that handles Symbol correctly
* @module babel-runtime/helpers/typeof
* @param {any} obj - Value to get type of
* @returns {string} The type string
*/
import _typeof from "babel-runtime/helpers/typeof";
/**
* instanceof helper with Symbol.hasInstance support
* @module babel-runtime/helpers/instanceof
* @param {any} left - Value to test
* @param {Function} right - Constructor to test against
* @returns {boolean} Whether left is instance of right
*/
import _instanceof from "babel-runtime/helpers/instanceof";
/**
* Prevents arrow function instantiation
* @module babel-runtime/helpers/newArrowCheck
* @param {any} innerThis - The inner 'this' value
* @param {any} boundThis - The bound 'this' value
* @throws {TypeError} When arrow function is instantiated
*/
import _newArrowCheck from "babel-runtime/helpers/newArrowCheck";Helper functions for handling temporal dead zone in let/const declarations.
/**
* Checks temporal dead zone reference
* @module babel-runtime/helpers/temporalRef
* @param {any} val - The variable value
* @param {string} name - The variable name
* @param {any} undef - The undefined marker
* @returns {any} The value if defined
* @throws {ReferenceError} When accessing variable in temporal dead zone
*/
import _temporalRef from "babel-runtime/helpers/temporalRef";
/**
* Marker value for temporal dead zone
* @module babel-runtime/helpers/temporalUndefined
* @returns {Object} Unique undefined marker object
*/
import _temporalUndefined from "babel-runtime/helpers/temporalUndefined";Miscellaneous helper functions for various transformations.
/**
* Gets global object reference
* @module babel-runtime/helpers/selfGlobal
* @returns {Object} The global object (global or self)
*/
import _selfGlobal from "babel-runtime/helpers/selfGlobal";
/**
* JSX element creation helper
* @module babel-runtime/helpers/jsx
* @param {any} type - Element type (string or component)
* @param {Object} props - Element properties
* @param {string|number} key - Element key
* @param {...any} children - Child elements
* @returns {Object} JSX element object
*/
import _jsx from "babel-runtime/helpers/jsx";Each helper is available in multiple naming formats for compatibility. The build process creates three versions of each helper:
helpers/helperName.jshelpers/_helper-name.jshelpers/helper-name.js (when different from camelCase)// All three formats reference the same helper implementation
// Main camelCase versions (recommended)
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
import _createClass from "babel-runtime/helpers/createClass";
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
import _defineProperty from "babel-runtime/helpers/defineProperty";
import _objectWithoutProperties from "babel-runtime/helpers/objectWithoutProperties";
// Underscore-prefixed kebab-case aliases
import _classCallCheck from "babel-runtime/helpers/_class-call-check";
import _createClass from "babel-runtime/helpers/_create-class";
import _asyncToGenerator from "babel-runtime/helpers/_async-to-generator";
import _defineProperty from "babel-runtime/helpers/_define-property";
import _objectWithoutProperties from "babel-runtime/helpers/_object-without-properties";
// Direct kebab-case aliases
import _classCallCheck from "babel-runtime/helpers/class-call-check";
import _createClass from "babel-runtime/helpers/create-class";
import _asyncToGenerator from "babel-runtime/helpers/async-to-generator";
import _defineProperty from "babel-runtime/helpers/define-property";
import _objectWithoutProperties from "babel-runtime/helpers/object-without-properties";Complete list of helpers with all naming variants:
| CamelCase | Underscore Kebab | Direct Kebab |
|---|---|---|
helpers/typeof.js | helpers/_typeof.js | helpers/typeof.js |
helpers/classCallCheck.js | helpers/_class-call-check.js | helpers/class-call-check.js |
helpers/createClass.js | helpers/_create-class.js | helpers/create-class.js |
helpers/asyncToGenerator.js | helpers/_async-to-generator.js | helpers/async-to-generator.js |
helpers/defineProperty.js | helpers/_define-property.js | helpers/define-property.js |
helpers/objectWithoutProperties.js | helpers/_object-without-properties.js | helpers/object-without-properties.js |
| ... | ... | ... |
Note: All alias files simply require and re-export the main camelCase implementation.
// All helper modules export with this pattern
interface HelperModule<T extends Function> {
default: T;
__esModule: true;
}
// Common helper function types
type ClassCallCheckFunction = (instance: any, Constructor: Function) => void;
type CreateClassFunction = (Constructor: Function, protoProps?: any[], staticProps?: any[]) => Function;
type AsyncToGeneratorFunction = (fn: GeneratorFunction) => Function;
type DefinePropertyFunction = (obj: object, key: string | symbol, value: any) => object;
type ExtendsFunction = (target: object, ...sources: object[]) => object;
type InteropRequireDefaultFunction = (obj: any) => { default: any; [key: string]: any };
type SlicedToArrayFunction = (arr: ArrayLike<any>, i: number) => any[];
type TypeofFunction = (obj: any) => string;