Runtime helper functions for JavaScript and TypeScript transformations performed by the SWC compiler.
npx @tessl/cli install tessl/npm-swc--helpers@0.5.0SWC Helpers provides runtime helper functions for JavaScript and TypeScript transformations performed by the SWC compiler. It contains 100+ individual helper modules that implement various JavaScript language features and transformations, enabling SWC to compile modern JavaScript and TypeScript features down to older JavaScript versions while maintaining correct runtime behavior.
npm install @swc/helpers// Import specific helpers
import { _class_call_check, _async_to_generator } from "@swc/helpers";For individual helper imports:
// Import individual helpers
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";CommonJS:
const { _class_call_check, _async_to_generator } = require("@swc/helpers");SWC Helpers are typically auto-injected by the SWC compiler during transformations, but can be used directly:
import { _class_call_check, _create_class } from "@swc/helpers";
// Ensure class constructor called with new
function MyClass() {
_class_call_check(this, MyClass);
}
// Define class methods
_create_class(MyClass, [
{
key: "myMethod",
value: function myMethod() {
return "Hello World";
}
}
]);SWC Helpers is organized as a collection of modular helper functions:
Runtime support for modern class syntax including construction, inheritance, private fields, and decorators. Essential for compiling ES6+ classes to older JavaScript versions.
function _class_call_check(instance, Constructor): void;
function _create_class(Constructor, protoProps, staticProps): Function;
function _inherits(subClass, superClass): void;Implementation of async/await syntax and generator functions for older JavaScript environments that don't support these features natively.
function _async_to_generator(fn): Function;
function _async_generator(fn): Function;
function _await_value(value): any;Support for destructuring assignments, rest/spread operators, and array/object manipulation patterns.
function _sliced_to_array(arr, i): Array;
function _array_without_holes(arr): Array;
function _object_without_properties(source, excluded): Object;Runtime implementation of private class fields and methods, providing encapsulation features for classes.
function _class_private_field_get(receiver, privateMap): any;
function _class_private_field_set(receiver, privateMap, value): void;
function _class_private_method_get(receiver, privateSet, fn): Function;Support for decorator syntax including method decorators, class decorators, and property decorators.
function _decorate(decorators, target, key, desc): any;
function _apply_decorated_descriptor(target, property, decorators, descriptor, context): any;Helpers for handling different module systems and import/export patterns between CommonJS and ES modules.
function _interop_require_default(obj): any;
function _interop_require_wildcard(obj): any;
function _export_star(from, to): void;Utilities for type checking, conversion, and property access operations commonly used in TypeScript and JavaScript.
function _type_of(obj): string;
function _instanceof(left, right): boolean;
function _to_primitive(input, hint): any;General-purpose utility functions for error handling, property operations, and other common runtime needs.
function _define_property(obj, key, value): Object;
function _extends(...sources): Object;
function _throw(error): never;