Runtime helper functions for JavaScript and TypeScript transformations performed by the SWC compiler.
—
Runtime support for modern class syntax including construction, inheritance, private fields, and decorators. These helpers enable ES6+ class features to work in older JavaScript environments.
Ensures a class constructor is called with the new operator.
/**
* Ensures a class constructor is called with the new operator
* @param {any} instance - The instance being created
* @param {Function} Constructor - The constructor function
* @throws {TypeError} If class called without new
*/
function _class_call_check(instance, Constructor): void;Usage Example:
function MyClass() {
_class_call_check(this, MyClass);
// Constructor logic here
}Defines properties on class prototype and constructor (static properties).
/**
* Defines properties on class prototype and constructor
* @param {Function} Constructor - The constructor function
* @param {Array} protoProps - Array of property descriptors for prototype
* @param {Array} staticProps - Array of property descriptors for constructor
* @returns {Function} The constructor with defined properties
*/
function _create_class(Constructor, protoProps, staticProps): Function;Usage Example:
function MyClass() {
_class_call_check(this, MyClass);
}
_create_class(MyClass, [
{
key: "instanceMethod",
value: function instanceMethod() {
return "instance";
}
}
], [
{
key: "staticMethod",
value: function staticMethod() {
return "static";
}
}
]);Sets up prototype-based inheritance between classes.
/**
* Sets up prototype-based inheritance between classes
* @param {Function} subClass - The child class constructor
* @param {Function|null} superClass - The parent class constructor or null
*/
function _inherits(subClass, superClass): void;Loose mode inheritance setup (simpler, less spec-compliant).
/**
* Loose mode inheritance setup
* @param {Function} subClass - The child class constructor
* @param {Function} superClass - The parent class constructor
*/
function _inherits_loose(subClass, superClass): void;Creates a super constructor function for derived classes.
/**
* Creates a super constructor function for derived classes
* @param {Function} Derived - The derived class constructor
* @returns {Function} Super constructor function
*/
function _create_super(Derived): Function;Calls super constructor with proper context handling.
/**
* Calls super constructor with proper context
* @param {any} _this - The current instance
* @param {Function} derived - The derived class
* @param {Array} args - Arguments to pass to super
* @returns {any} Result of super constructor call
*/
function _call_super(_this, derived, args): any;Handles possible constructor return values in inheritance.
/**
* Handles possible constructor return values in inheritance
* @param {any} self - The current instance
* @param {any} call - Result of super constructor call
* @returns {any} The appropriate instance
*/
function _possible_constructor_return(self, call): any;Constructs objects with dynamic arguments using Reflect.construct.
/**
* Constructs objects with dynamic arguments
* @param {Function} Parent - Constructor function
* @param {Array} args - Arguments array
* @param {Function} Class - Target class for construction
* @returns {any} Constructed instance
*/
function _construct(Parent, args, Class): any;Wraps native constructors for proper inheritance.
/**
* Wraps native constructors for proper inheritance
* @param {Function} Class - The class to wrap
* @returns {Function} Wrapped constructor
*/
function _wrap_native_super(Class): Function;Checks if a function is a native function.
/**
* Checks if a function is a native function
* @param {Function} fn - Function to check
* @returns {boolean} True if native function
*/
function _is_native_function(fn): boolean;Checks if Reflect.construct is available and native.
/**
* Checks if Reflect.construct is available and native
* @returns {boolean} True if Reflect.construct is native
*/
function _is_native_reflect_construct(): boolean;Throws an error for class name temporal dead zone violations.
/**
* Throws an error for class name TDZ violations
* @param {string} name - The class name
* @throws {ReferenceError} Class name TDZ error
*/
function _class_name_tdz_error(name): never;Ensures this is initialized in constructors.
/**
* Ensures this is initialized in constructors
* @param {any} self - The this value to check
* @returns {any} The initialized this value
* @throws {ReferenceError} If this is not initialized
*/
function _assert_this_initialized(self): any;Gets property values with prototype chain traversal.
/**
* Gets property values with prototype chain traversal
* @param {Object} target - Target object
* @param {string|symbol} property - Property key
* @param {Object} receiver - Receiver object
* @returns {any} Property value
*/
function _get(target, property, receiver): any;Sets property values with proper prototype handling.
/**
* Sets property values with proper prototype handling
* @param {Object} target - Target object
* @param {string|symbol} property - Property key
* @param {any} value - Value to set
* @param {Object} receiver - Receiver object
* @param {boolean} isStrict - Strict mode flag
* @returns {boolean} Success flag
*/
function _set(target, property, value, receiver, isStrict): boolean;Gets the base object for super property access.
/**
* Gets the base object for super property access
* @param {Object} object - Current object
* @param {string|symbol} property - Property key
* @returns {Object} Base object for super access
*/
function _super_prop_base(object, property): Object;Handles update operations on properties.
/**
* Handles update operations on properties
* @param {Object} target - Target object
* @param {string|symbol} property - Property key
* @param {Function} updater - Update function
* @param {Object} receiver - Receiver object
* @returns {any} Updated value
*/
function _update(target, property, updater, receiver): any;Install with Tessl CLI
npx tessl i tessl/npm-swc--helpers