or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array-iteration-helpers.mdasync-generator-helpers.mdclass-object-helpers.mdcore-helper-management.mdindex.mdmodule-import-helpers.mdutility-runtime-helpers.md
tile.json

array-iteration-helpers.mddocs/

Array and Iteration Helpers

Comprehensive collection of helpers for array operations, destructuring, and iteration patterns including for-of loops, spread syntax, and rest parameters.

Capabilities

Array Conversion Helpers

Utilities for converting array-like objects and iterables to arrays.

/**
 * Convert array-like objects (with length and indexed elements) to arrays
 * Helper name: "arrayLikeToArray"
 */
function _arrayLikeToArray(arr: ArrayLike<any>, len?: number): any[];

/**
 * Convert iterables to arrays
 * Helper name: "iterableToArray"
 */
function _iterableToArray<T>(iter: Iterable<T>): T[];

/**
 * Convert iterables to arrays with length limit
 * Helper name: "iterableToArrayLimit"
 */
function _iterableToArrayLimit<T>(iter: Iterable<T>, limit: number): T[];

/**
 * Convert values to arrays, handling various input types
 * Helper name: "toArray"
 */
function _toArray<T>(arr: ArrayLike<T> | Iterable<T>): T[];

/**
 * Convert to arrays suitable for consumption (spreading)
 * Helper name: "toConsumableArray"
 */
function _toConsumableArray<T>(arr: ArrayLike<T> | Iterable<T>): T[];

/**
 * Check if object might be array-like
 * Helper name: "maybeArrayLike"
 */
function _maybeArrayLike(next: any, arr: any[], i: number): any[];

/**
 * Handle unsupported iterables by falling back to array conversion
 * Helper name: "unsupportedIterableToArray"
 */
function _unsupportedIterableToArray<T>(o: any, minLen?: number): T[] | void;

Array Destructuring Helpers

Helpers for array destructuring patterns with and without holes.

/**
 * Handle array destructuring with holes (sparse arrays)
 * Helper name: "arrayWithHoles"
 */
function _arrayWithHoles<T>(arr: T[]): T[];

/**
 * Handle array destructuring without holes (dense arrays)
 * Helper name: "arrayWithoutHoles"
 */
function _arrayWithoutHoles<T>(arr: T[]): T[];

/**
 * Array destructuring with slicing support
 * Helper name: "slicedToArray"
 */
function _slicedToArray<T>(arr: T[], i: number): T[];

Rest and Spread Helpers

Utilities for handling rest parameters and spread syntax.

/**
 * Handle non-iterable rest elements
 * Helper name: "nonIterableRest"
 */
function _nonIterableRest(): never;

/**
 * Handle non-iterable spread elements
 * Helper name: "nonIterableSpread"
 */
function _nonIterableSpread(): never;

For-Of Loop Helpers

Helpers for creating for-of loop iterators in different modes.

/**
 * Create for-of loop iterator helper (standard mode)
 * Helper name: "createForOfIteratorHelper"
 */
function _createForOfIteratorHelper<T>(
  o: Iterable<T>, 
  allowArrayLike?: boolean
): {
  s(): void;
  n(): { done: boolean; value: T };
  e(e: any): void;
  f(): void;
};

/**
 * Create for-of loop iterator helper (loose mode)
 * Helper name: "createForOfIteratorHelperLoose"
 */
function _createForOfIteratorHelperLoose<T>(
  o: Iterable<T>, 
  allowArrayLike?: boolean
): {
  s(): void;
  n(): { done: boolean; value: T };
  e(e: any): void;
  f(): void;
};

Usage Examples:

// These helpers are typically injected by Babel transforms, not called directly
// Example of how Babel might use them:

// For array destructuring: const [a, b] = arr;
// Babel generates:
import { get } from "@babel/helpers";
const helperCode = get("slicedToArray");
// Injected: function _slicedToArray(arr, i) { /* implementation */ }
// const _ref = _slicedToArray(arr, 2), a = _ref[0], b = _ref[1];

// For spread operator: const newArr = [...iterable];
// Babel generates:  
const spreadHelper = get("toConsumableArray");
// Injected: function _toConsumableArray(arr) { /* implementation */ }
// const newArr = _toConsumableArray(iterable);

// For for-of loops: for (const item of iterable) { ... }
// Babel generates:
const iteratorHelper = get("createForOfIteratorHelper");
// Injected: function _createForOfIteratorHelper(o) { /* implementation */ }
// const _iterator = _createForOfIteratorHelper(iterable);
// for (let _step = _iterator.s(); !(_step = _iterator.n()).done;) {
//   const item = _step.value;
//   // loop body
// }

Helper Dependencies

Many array helpers have dependencies on other helpers:

  • toConsumableArray depends on: arrayWithoutHoles, iterableToArray, unsupportedIterableToArray, nonIterableSpread
  • toArray depends on: arrayWithHoles, iterableToArray, unsupportedIterableToArray, nonIterableRest
  • slicedToArray depends on: arrayWithHoles, iterableToArrayLimit, unsupportedIterableToArray, nonIterableRest

Common Usage Patterns

import { get, getDependencies } from "@babel/helpers";

// Get all array-related helpers
const arrayHelpers = [
  "arrayLikeToArray", "arrayWithHoles", "arrayWithoutHoles",
  "createForOfIteratorHelper", "createForOfIteratorHelperLoose", 
  "iterableToArray", "iterableToArrayLimit", "maybeArrayLike",
  "nonIterableRest", "nonIterableSpread", "slicedToArray",
  "toArray", "toConsumableArray", "unsupportedIterableToArray"
];

// Check which helpers a destructuring operation needs
const destructuringDeps = getDependencies("slicedToArray");
console.log(destructuringDeps); // Dependencies for array destructuring

// Get helper for spread operations
const spreadHelper = get("toConsumableArray");
// This will include all necessary dependencies automatically