/** * Linearized binding slot types for frame-based destructuring. * * Instead of using a callback-based recursive traversal for destructuring, * we pre-flatten the binding pattern into a linear list of "slots". Each slot * represents one variable to bind, with a path describing how to extract the * value from the source object. * * This enables: * 1. Frame-based evaluation of defaults (no callbacks) * 2. Serializable continuation state * 3. Suspension/resume at any point during binding */ import type { Any, Arr } from '../interface'; import type { AstNode, BindingTarget } from '../parser/types'; import type { SourceCodeInfo } from '../tokenizer/token'; import { PersistentMap } from '../utils/persistent'; /** * Validate that the root value matches the expected binding target structure. * * For array destructuring (`let [a, b] = value`), value must be an array. * For object destructuring (`let {a, b} = value`), value must be an object. * For symbol binding (`let x = value`), no validation needed. */ export declare function validateBindingRootType(target: BindingTarget, value: Any, sourceCodeInfo?: SourceCodeInfo): void; /** * A single step in the path to extract a value from a nested structure. */ export type BindingPathStep = { type: 'key'; key: string; } | { type: 'index'; index: number; }; /** * A linearized binding slot representing one variable to bind. * * - `name`: The variable name to add to the context (or '_intermediate_N' for intermediate defaults) * - `path`: Sequence of steps to extract the value from the root * - `defaultNode`: Optional default expression if value is undefined * - `isRest`: If true, this is a rest binding (...x) * - `restKeys`: For object rest, the keys to exclude from rest collection * - `restIndex`: For array rest, the starting index for rest collection * - `nestedTarget`: If present, this slot has an intermediate default and needs * further destructuring after the value is resolved. */ export interface BindingSlot { name: string; path: BindingPathStep[]; defaultNode?: AstNode; isRest?: boolean; restKeys?: Set; restIndex?: number; nestedTarget?: BindingTarget; nodeId: number; } /** * Flatten a binding pattern into a linear list of slots. * * Example: `{a = 1, b: {c = 2}}` * Produces: [ * { name: 'a', path: [{type: 'key', key: 'a'}], defaultNode: <1> }, * { name: 'c', path: [{type: 'key', key: 'b'}, {type: 'key', key: 'c'}], defaultNode: <2> } * ] */ export declare function flattenBindingPattern(target: BindingTarget): BindingSlot[]; /** * Extract a value from a nested structure by following a path. * * Returns undefined if the path cannot be followed (missing key/index). */ export declare function extractValueByPath(rootValue: Any, path: BindingPathStep[], sourceCodeInfo?: SourceCodeInfo): Any | undefined; /** * Extract rest values for an object rest binding. * Returns an object with all keys except those in restKeys. */ export declare function extractObjectRest(value: Any, restKeys: Set, sourceCodeInfo?: SourceCodeInfo): PersistentMap; /** * Extract rest values for an array rest binding. * Returns elements from restIndex onwards. */ export declare function extractArrayRest(value: Any, restIndex: number, sourceCodeInfo?: SourceCodeInfo): Arr;