or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

async-generators.mdclass-system.mddecorators.mddestructuring.mdindex.mdmodule-interop.mdprivate-fields.mdtype-system.mdutilities.md
tile.json

tessl/npm-swc--helpers

Runtime helper functions for JavaScript and TypeScript transformations performed by the SWC compiler.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@swc/helpers@0.5.x

To install, run

npx @tessl/cli install tessl/npm-swc--helpers@0.5.0

index.mddocs/

SWC Helpers

SWC 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.

Package Information

  • Package Name: @swc/helpers
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install @swc/helpers

Core Imports

// 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");

Basic Usage

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";
    }
  }
]);

Architecture

SWC Helpers is organized as a collection of modular helper functions:

  • Individual Modules: Each helper is a separate module file for optimal tree-shaking
  • Dual Export: Supports both ESM and CommonJS through conditional exports
  • Runtime Support: Provides the runtime behavior for compiled JavaScript features
  • Auto-Injection: Automatically included by SWC when transformations require runtime support

Capabilities

Class System Helpers

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;

Class System

Async and Generator Helpers

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;

Async and Generators

Destructuring Helpers

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;

Destructuring

Private Field Helpers

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;

Private Fields

Decorator Helpers

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;

Decorators

Module Interoperability

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;

Module Interoperability

Type System Helpers

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;

Type System

Utility Helpers

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;

Utilities