Private member helpers provide support for JavaScript private fields and methods, including access control, brand checking, and initialization patterns for both instance and static private members.
Gets the value of a private field from an instance.
/**
* Gets private field value
* @param receiver - Instance containing the private field
* @param privateMap - WeakMap storing private field values
* @returns Private field value
*/
function classPrivateFieldGet(receiver: any, privateMap: WeakMap<any, any>): any;Alternative private field getter implementation.
/**
* Alternative private field getter
* @param receiver - Instance containing the private field
* @param privateMap - WeakMap storing private field values
* @returns Private field value
*/
function classPrivateFieldGet2(receiver: any, privateMap: WeakMap<any, any>): any;Sets the value of a private field on an instance.
/**
* Sets private field value
* @param receiver - Instance to set private field on
* @param privateMap - WeakMap storing private field values
* @param value - Value to set
* @returns The set value
*/
function classPrivateFieldSet(receiver: any, privateMap: WeakMap<any, any>, value: any): any;Alternative private field setter implementation.
/**
* Alternative private field setter
* @param receiver - Instance to set private field on
* @param privateMap - WeakMap storing private field values
* @param value - Value to set
* @returns The set value
*/
function classPrivateFieldSet2(receiver: any, privateMap: WeakMap<any, any>, value: any): any;Initializes private field specifications for a class.
/**
* Initializes private field specs
* @param obj - Object to initialize private fields on
* @param privateMap - WeakMap for storing private values
* @param value - Initial value for the private field
*/
function classPrivateFieldInitSpec(obj: any, privateMap: WeakMap<any, any>, value: any): void;Base helper for loose mode private fields (smaller bundle size).
/**
* Loose mode private field base
* @param receiver - Object to access private field on
* @param privateKey - Unique key for the private field
* @returns Receiver object for chaining
*/
function classPrivateFieldLooseBase(receiver: any, privateKey: any): any;Generates unique keys for loose mode private fields.
/**
* Loose mode private field key
* @param name - Name of the private field
* @returns Unique key for loose private field
*/
function classPrivateFieldLooseKey(name: string): string;Gets a private method from an instance with proper binding.
/**
* Gets private method
* @param receiver - Instance containing the private method
* @param privateSet - WeakSet tracking instances with private methods
* @param fn - The private method function
* @returns Bound private method
*/
function classPrivateMethodGet(receiver: any, privateSet: WeakSet<any>, fn: Function): Function;Throws error when attempting to set a private method (read-only).
/**
* Sets private method (throws error - methods are read-only)
* @throws TypeError - Private methods are read-only
*/
function classPrivateMethodSet(): never;Initializes private method specifications for a class.
/**
* Initializes private method specs
* @param obj - Object to initialize private methods on
* @param privateSet - WeakSet for tracking method access
*/
function classPrivateMethodInitSpec(obj: any, privateSet: WeakSet<any>): void;Accesses private getter methods.
/**
* Private getter access
* @param receiver - Instance with private getter
* @param privateMap - WeakMap containing getter function
* @returns Result of calling private getter
*/
function classPrivateGetter(receiver: any, privateMap: WeakMap<any, any>): any;Accesses private setter methods.
/**
* Private setter access
* @param receiver - Instance with private setter
* @param privateMap - WeakMap containing setter function
* @param value - Value to pass to setter
*/
function classPrivateSetter(receiver: any, privateMap: WeakMap<any, any>, value: any): void;Gets the value of a static private field.
/**
* Gets static private field
* @param receiver - Class constructor
* @param classConstructor - Expected class constructor
* @param descriptor - Field descriptor containing value
* @returns Static private field value
*/
function classStaticPrivateFieldSpecGet(receiver: any, classConstructor: Function, descriptor: any): any;Sets the value of a static private field.
/**
* Sets static private field
* @param receiver - Class constructor
* @param classConstructor - Expected class constructor
* @param descriptor - Field descriptor to update
* @param value - Value to set
* @returns The set value
*/
function classStaticPrivateFieldSpecSet(receiver: any, classConstructor: Function, descriptor: any, value: any): any;Sets static private field in destructuring context.
/**
* Static private field destructuring
* @param receiver - Class constructor
* @param classConstructor - Expected class constructor
* @param descriptor - Field descriptor
* @param value - Value to set
* @returns The set value
*/
function classStaticPrivateFieldDestructureSet(receiver: any, classConstructor: Function, descriptor: any, value: any): any;Gets a static private method with proper binding.
/**
* Gets static private method
* @param receiver - Class constructor
* @param classConstructor - Expected class constructor
* @param method - The static private method
* @returns The static private method
*/
function classStaticPrivateMethodGet(receiver: any, classConstructor: Function, method: Function): Function;Throws error when attempting to set a static private method.
/**
* Sets static private method (throws error - methods are read-only)
* @throws TypeError - Static private methods are read-only
*/
function classStaticPrivateMethodSet(): never;Asserts that an object has the correct class brand for private member access.
/**
* Asserts class brand for private access
* @param e - Instance to check
* @param t - Expected brand/class
* @param n - Error name (optional)
* @returns The validated instance
* @throws TypeError if brand check fails
*/
function assertClassBrand(e: any, t: any, n?: any): any;Prevents redeclaration of private members during class definition.
/**
* Prevents private member redeclaration
* @param obj - Object being defined
* @param privateCollection - Collection tracking private members
* @throws SyntaxError if private member already declared
*/
function checkPrivateRedeclaration(obj: any, privateCollection: WeakSet<any> | WeakMap<any, any>): void;Checks access permissions for static private members.
/**
* Checks static private access
* @param receiver - Object attempting access
* @param classConstructor - Expected class constructor
* @throws TypeError if access denied
*/
function classCheckPrivateStaticAccess(receiver: any, classConstructor: Function): void;Validates static private field descriptors.
/**
* Checks static field descriptor
* @param descriptor - Field descriptor to validate
* @param action - Action being performed ('get' or 'set')
* @returns Validated descriptor
*/
function classCheckPrivateStaticFieldDescriptor(descriptor: any, action: string): any;Extracts field descriptors from private field definitions.
/**
* Extracts field descriptors
* @param receiver - Object containing field
* @param privateMap - WeakMap with field data
* @param action - Action being performed
* @returns Field descriptor
*/
function classExtractFieldDescriptor(receiver: any, privateMap: WeakMap<any, any>, action: string): any;Sets private field values in destructuring assignments.
/**
* Sets private field in destructuring
* @param receiver - Instance to set field on
* @param privateMap - WeakMap storing field values
* @param value - Value to destructure and set
* @returns The set value
*/
function classPrivateFieldDestructureSet(receiver: any, privateMap: WeakMap<any, any>, value: any): any;// Private field storage
interface PrivateFieldMap extends WeakMap<any, any> {}
// Private method tracking
interface PrivateMethodSet extends WeakSet<any> {}
// Static private field descriptor
interface StaticPrivateFieldDescriptor {
value: any;
writable?: boolean;
}
// Private member collections
type PrivateCollection = WeakSet<any> | WeakMap<any, any>;
// Class brand for private access
interface ClassBrand {
_: void;
}