CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-swc--helpers

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

Pending
Overview
Eval results
Files

class-system.mddocs/

Class System Helpers

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.

Capabilities

Class Construction

_class_call_check

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
}

_create_class

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

Class Inheritance

_inherits

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;

_inherits_loose

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;

_create_super

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;

_call_super

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;

_possible_constructor_return

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;

Constructor Utilities

_construct

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;

_wrap_native_super

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;

_is_native_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;

_is_native_reflect_construct

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;

Class Error Handling

_class_name_tdz_error

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;

_assert_this_initialized

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;

Property Access Helpers

_get

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;

_set

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;

_super_prop_base

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;

_update

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

docs

async-generators.md

class-system.md

decorators.md

destructuring.md

index.md

module-interop.md

private-fields.md

type-system.md

utilities.md

tile.json