Babel's modular runtime helpers that provide transpilation support for modern JavaScript features
94
Type and utility helpers provide type checking, control flow validation, error generation, and utility functions for robust transpiled JavaScript code execution.
Enhanced typeof operator with Symbol support and consistent cross-environment behavior.
/**
* Enhanced typeof with symbol support
* @param obj - Value to get type of
* @returns Type string including 'symbol' for symbols
*/
function _typeof(obj: any): string;Usage Example:
import _typeof from '@babel/runtime/helpers/esm/typeof';
// Used by Babel for: typeof someValue === 'symbol'
const type = _typeof(someValue);
// Returns: 'undefined', 'boolean', 'number', 'string', 'symbol', 'object', 'function'Enhanced instanceof operator with proper null prototype handling.
/**
* Enhanced instanceof checks
* @param left - Value to test
* @param right - Constructor to test against
* @returns True if left is instance of right
*/
function _instanceof(left: any, right: any): boolean;Usage Example:
import _instanceof from '@babel/runtime/helpers/esm/instanceof';
// Used by Babel for: someValue instanceof SomeClass
const isInstance = _instanceof(someValue, SomeClass);Identity function utility for functional programming patterns.
/**
* Identity function helper
* @param x - Value to return unchanged
* @returns The input value unchanged
*/
function identity<T>(x: T): T;Validates arrow function context to ensure proper this binding.
/**
* Validates arrow function context
* @param innerThis - This binding inside arrow function
* @param boundThis - Expected this binding
* @returns The validated this binding
* @throws TypeError if this binding is incorrect
*/
function newArrowCheck(innerThis: any, boundThis: any): any;Validates right-hand side expressions in 'in' operator checks.
/**
* Validates right-hand side expressions
* @param value - Value to validate as object
* @returns The validated object
* @throws TypeError if value is not an object
*/
function checkInRHS(value: any): any;Throws appropriate error for read-only property access violations.
/**
* Throws read-only property errors
* @param name - Name of the read-only property
* @throws TypeError indicating property is read-only
*/
function readOnlyError(name: string): never;Throws appropriate error for write-only property access violations.
/**
* Throws write-only property errors
* @param name - Name of the write-only property
* @throws TypeError indicating property is write-only
*/
function writeOnlyError(name: string): never;Throws error when trying to access properties on null/undefined receivers.
/**
* Throws nullish receiver errors
* @param property - Property being accessed
* @throws TypeError for null/undefined property access
*/
function nullishReceiverError(property: PropertyKey): never;Throws temporal dead zone errors for class name access.
/**
* Temporal dead zone errors for class names
* @param name - Class name being accessed
* @throws ReferenceError for temporal dead zone violation
*/
function classNameTDZError(name: string): never;Temporal dead zone helper for let/const declarations.
/**
* Temporal dead zone helper
* @param name - Variable name in temporal dead zone
* @throws ReferenceError for temporal dead zone access
*/
function tdz(name: string): never;Creates temporal references for let/const before initialization.
/**
* Temporal reference helper
* @param val - Value to check for temporal dead zone
* @param name - Variable name
* @returns The value if initialized
* @throws ReferenceError if in temporal dead zone
*/
function temporalRef(val: any, name: string): any;Returns undefined marker for temporal dead zone checking.
/**
* Temporal undefined helper
* @returns Special undefined value for TDZ checking
*/
function temporalUndefined(): any;Usage Example:
import _temporalUndefined from '@babel/runtime/helpers/esm/temporalUndefined';
import _temporalRef from '@babel/runtime/helpers/esm/temporalRef';
// Used by Babel for temporal dead zone in:
// console.log(x); const x = 5;
let x = _temporalUndefined();
console.log(_temporalRef(x, 'x')); // Throws ReferenceError
x = 5;Processes tagged template literals with proper raw string handling.
/**
* Processes tagged template literals
* @param strings - Template string parts
* @param raw - Raw template string parts
* @returns Template literal object with strings and raw properties
*/
function taggedTemplateLiteral(strings: string[], raw?: string[]): TemplateStringsArray;
interface TemplateStringsArray extends ReadonlyArray<string> {
readonly raw: ReadonlyArray<string>;
}Usage Example:
import _taggedTemplateLiteral from '@babel/runtime/helpers/esm/taggedTemplateLiteral';
// Used by Babel for: myTag`Hello ${name}!`
const templateObj = _taggedTemplateLiteral(['Hello ', '!'], ['Hello ', '!']);Loose mode template literal processing (smaller bundle).
/**
* Loose mode template processing (smaller bundle)
* @param strings - Template string parts
* @param raw - Raw template string parts
* @returns Template literal object
*/
function taggedTemplateLiteralLoose(strings: string[], raw?: string[]): TemplateStringsArray;JSX element creation helper for React and similar libraries.
/**
* JSX element creation helper
* @param type - Element type (string or component)
* @param props - Element properties
* @param children - Child elements
* @returns JSX element
*/
function jsx(type: any, props?: any, ...children: any[]): any;Implements using declarations for automatic resource disposal.
/**
* Implements using declarations (TC39 proposal)
* @param stack - Disposal stack
* @param value - Resource to manage
* @returns The managed resource
*/
function using(stack: any[], value: any): any;Using context management for resource disposal coordination.
/**
* Using context management
* @returns Context object for managing disposable resources
*/
function usingCtx(): {
stack: any[];
error: any;
hasError: boolean;
};Resource disposal helper for cleanup operations.
/**
* Resource disposal helper
* @param stack - Stack of resources to dispose
* @param error - Error that occurred during execution
* @param hasError - Whether an error occurred
*/
function dispose(stack: any[], error?: any, hasError?: boolean): void;Usage Example:
import _using from '@babel/runtime/helpers/esm/using';
import _usingCtx from '@babel/runtime/helpers/esm/usingCtx';
import _dispose from '@babel/runtime/helpers/esm/dispose';
// Used by Babel for: using resource = getResource();
const ctx = _usingCtx();
try {
const resource = _using(ctx.stack, getResource());
// use resource
} catch (e) {
ctx.error = e;
ctx.hasError = true;
} finally {
_dispose(ctx.stack, ctx.error, ctx.hasError);
}Rewrites relative import extensions for TypeScript compatibility.
/**
* Rewrites relative import extensions for TypeScript
* @param path - Import path to rewrite
* @param preserveJsx - Whether to preserve JSX extensions
* @returns Rewritten import path
*/
function tsRewriteRelativeImportExtensions(path: string, preserveJsx?: boolean): string;Wraps RegExp objects for enhanced functionality and named capture groups.
/**
* Wraps RegExp for enhanced functionality
* @param re - Regular expression to wrap
* @param groups - Named capture group mappings
* @returns Enhanced RegExp with additional methods
*/
function wrapRegExp(re: RegExp, groups: Record<string, number>): EnhancedRegExp;
interface EnhancedRegExp extends RegExp {
groups: Record<string, number>;
}// Property key types
type PropertyKey = string | number | symbol;
// Template strings array
interface TemplateStringsArray extends ReadonlyArray<string> {
readonly raw: ReadonlyArray<string>;
}
// Enhanced RegExp
interface EnhancedRegExp extends RegExp {
groups: Record<string, number>;
}
// Using context
interface UsingContext {
stack: any[];
error: any;
hasError: boolean;
}
// Disposable resource
interface Disposable {
[Symbol.dispose](): void;
}
// Async disposable resource
interface AsyncDisposable {
[Symbol.asyncDispose](): Promise<void>;
}Install with Tessl CLI
npx tessl i tessl/npm-babel--runtimedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10