Collection of utility functions for type checking, error handling, JSX, template literals, and other runtime operations.
Utilities for runtime type checking and validation.
/**
* Safe typeof operator that handles temporal dead zone
* Helper name: "typeof"
*/
function _typeof(obj: any): string;
/**
* Safe instanceof operator with proper prototype chain checking
* Helper name: "instanceof"
*/
function _instanceof(left: any, right: any): boolean;
/**
* Check if function is native (not user-defined)
* Helper name: "isNativeFunction"
*/
function _isNativeFunction(fn: Function): boolean;
/**
* Check if Reflect.construct is native implementation
* Helper name: "isNativeReflectConstruct"
*/
function _isNativeReflectConstruct(): boolean;Runtime error utilities for various scenarios.
/**
* Throw error for nullish receiver in optional chaining
* Helper name: "nullishReceiverError"
*/
function _nullishReceiverError(): never;
/**
* Throw error when trying to write to read-only property
* Helper name: "readOnlyError"
*/
function _readOnlyError(name: string): never;
/**
* Throw error when trying to read from write-only property
* Helper name: "writeOnlyError"
*/
function _writeOnlyError(name: string): never;
/**
* Class name temporal dead zone error
* Helper name: "classNameTDZError"
*/
function _classNameTDZError(name: string): never;Utilities for handling temporal dead zone in let/const declarations.
/**
* Temporal dead zone reference check
* Helper name: "temporalRef"
*/
function _temporalRef<T>(val: T, name: string): T;
/**
* Temporal dead zone helper
* Helper name: "tdz"
*/
function _tdz(name: string): never;
/**
* Temporal undefined helper
* Helper name: "temporalUndefined"
*/
function _temporalUndefined(): void;Runtime helpers for JSX transformation.
/**
* JSX element creation helper
* Helper name: "jsx"
*/
function _jsx(
type: string | Function,
props: object,
key?: string | number
): any;Utilities for tagged template literals.
/**
* Tagged template literal helper (standard mode)
* Helper name: "taggedTemplateLiteral"
*/
function _taggedTemplateLiteral(
strings: TemplateStringsArray,
raw?: TemplateStringsArray
): TemplateStringsArray;
/**
* Tagged template literal helper (loose mode)
* Helper name: "taggedTemplateLiteralLoose"
*/
function _taggedTemplateLiteralLoose(
strings: string[],
raw?: string[]
): string[];Utilities for regular expression handling.
/**
* Wrap regular expression with additional functionality
* Helper name: "wrapRegExp"
*/
function _wrapRegExp(re: RegExp, groups: { [key: string]: number }): RegExp;Utilities for arrow function this binding checks.
/**
* Check arrow function this binding
* Helper name: "newArrowCheck"
*/
function _newArrowCheck<T>(innerThis: T, boundThis: T): T;Helpers for using declarations and resource management.
/**
* Using context helper for resource management
* Helper name: "usingCtx"
*/
function _usingCtx(): {
e: any[];
s: boolean;
d: (v: any) => void;
f: () => void;
};
/**
* Using declaration helper
* Helper name: "using"
*/
function _using(obj: any, kind: string): any;
/**
* Dispose resource helper
* Helper name: "dispose"
*/
function _dispose(obj: any, kind: string): void;Utilities for right-hand side expression validation.
/**
* Check in right-hand side expressions
* Helper name: "checkInRHS"
*/
function _checkInRHS(value: any): any;Simple identity function utility.
/**
* Identity function - returns input unchanged
* Helper name: "identity"
*/
function _identity<T>(t: T): T;Utilities for decorator application and initialization.
/**
* Apply decorated descriptor
* Helper name: "applyDecoratedDescriptor"
*/
function _applyDecoratedDescriptor(
target: object,
property: PropertyKey,
decorators: Function[],
descriptor: PropertyDescriptor,
context?: object
): PropertyDescriptor;
/**
* Apply decorators (2023.11 proposal)
* Helper name: "applyDecs2311"
*/
function _applyDecs2311<T extends Function>(
targetClass: T,
memberDecs: any[][],
classDecs: Function[],
classDecsHaveThis: boolean,
instanceBrand: WeakSet<object>
): T;
/**
* Apply decorators (older proposals)
* Helper name: "applyDecs", "applyDecs2203", "applyDecs2203R", "applyDecs2301", "applyDecs2305"
*/
function _applyDecs<T extends Function>(targetClass: T, memberDecs: any[][], classDecs: Function[]): T;
function _applyDecs2203<T extends Function>(targetClass: T, memberDecs: any[][], classDecs: Function[]): T;
function _applyDecs2203R<T extends Function>(targetClass: T, memberDecs: any[][], classDecs: Function[]): T;
function _applyDecs2301<T extends Function>(targetClass: T, memberDecs: any[][], classDecs: Function[]): T;
function _applyDecs2305<T extends Function>(targetClass: T, memberDecs: any[][], classDecs: Function[]): T;
/**
* Decorate class
* Helper name: "decorate"
*/
function _decorate(
decorators: Function[],
factory: Function,
superClass?: Function,
mixins?: Function[]
): Function;
/**
* Initializer define property
* Helper name: "initializerDefineProperty"
*/
function _initializerDefineProperty<T>(
target: object,
key: PropertyKey,
descriptor: PropertyDescriptor,
context?: T
): void;
/**
* Initializer warning helper
* Helper name: "initializerWarningHelper"
*/
function _initializerWarningHelper(descriptor: PropertyDescriptor, context: any): void;// For safe typeof in temporal dead zone:
// typeof x (where x might be in TDZ)
import { get } from "@babel/helpers";
const typeofHelper = get("typeof");
// Babel generates:
// _typeof(x) instead of typeof x
// This avoids ReferenceError in TDZ
// For instanceof with proxy safety:
const instanceofHelper = get("instanceof");
// Babel uses this for safe instanceof checks// For optional chaining with nullish values:
// obj?.prop?.method?.()
const nullishHelper = get("nullishReceiverError");
// Babel generates code that throws proper error:
// obj == null ? void 0 : obj.prop == null ? void 0 : obj.prop.method == null ? _nullishReceiverError() : obj.prop.method()
// For read-only assignments:
const readOnlyHelper = get("readOnlyError");
// Used when trying to assign to const or read-only properties// For JSX elements: <div className="test">content</div>
const jsxHelper = get("jsx");
// Babel transforms to:
// _jsx("div", { className: "test", children: "content" })
// This helper creates the actual React/JSX element// For tagged template literals: tag`Hello ${name}!`
const templateHelper = get("taggedTemplateLiteral");
// Babel transforms to:
// tag(_taggedTemplateLiteral(["Hello ", "!"], ["Hello \\", "!"]), name)
// The helper creates proper TemplateStringsArray with raw strings// For using declarations: using resource = getResource();
const usingHelper = get("usingCtx");
// Babel generates resource management code:
// const _usingCtx = _usingCtx();
// const resource = _usingCtx.d(getResource());
// // ... code using resource
// _usingCtx.f(); // Cleanupimport { get, list, isInternal } from "@babel/helpers";
// Get all utility helpers
const utilityHelpers = [
"typeof", "instanceof", "jsx", "taggedTemplateLiteral",
"nullishReceiverError", "readOnlyError", "writeOnlyError",
"temporalUndefined", "tdz", "identity", "usingCtx",
"newArrowCheck", "checkInRHS", "wrapRegExp"
];
// Filter non-internal utility helpers
const publicUtilities = utilityHelpers.filter(name => !isInternal(name));
// Get helper for specific use case
function getUtilityHelper(useCase: string) {
const helperMap = {
'typeof': get("typeof"),
'instanceof': get("instanceof"),
'jsx': get("jsx"),
'template': get("taggedTemplateLiteral"),
'nullish': get("nullishReceiverError"),
'readonly': get("readOnlyError"),
'tdz': get("temporalRef"),
'identity': get("identity"),
'using': get("usingCtx")
};
return helperMap[useCase];
}The error helpers provide consistent error messages:
// Read-only error example:
function _readOnlyError(name) {
throw new TypeError(`"${name}" is read-only`);
}
// Nullish receiver error:
function _nullishReceiverError() {
throw new TypeError("Cannot read properties of null or undefined");
}
// TDZ error:
function _tdz(name) {
throw new ReferenceError(`${name} is not defined`);
}// The usingCtx helper manages resource lifecycle:
const ctx = _usingCtx();
try {
// Register resources for cleanup
const file = ctx.d(openFile("data.txt"));
const connection = ctx.d(openConnection("db://localhost"));
// Use resources...
} finally {
// Automatic cleanup of all registered resources
ctx.f();
}// The typeof helper handles edge cases:
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
return obj && typeof obj === "object" && typeof obj[Symbol.iterator] === "function"
? "object" : typeof obj;
}
return obj && typeof obj === "object" && typeof obj[Symbol.iterator] === "function"
? "object" : typeof obj;
}