import { J } from '../../java'; import { Marker, Markers } from '../../markers'; import { ConstraintFunction, VariadicOptions } from './types'; /** * Internal storage value type for pattern match captures. * - J: Scalar captures without wrapper (fallback) * - J.RightPadded: Scalar captures with wrapper (preserves trailing markers like semicolons) * - J[]: Variadic captures without wrapper metadata * - J.RightPadded[]: Variadic captures with wrapper metadata (preserves markers like commas) */ export type CaptureStorageValue = J | J.RightPadded | J[] | J.RightPadded[]; /** * Symbol to access wrappersMap without exposing it as public API */ export declare const WRAPPERS_MAP_SYMBOL: unique symbol; /** * Shared wrapper function name used by both patterns and templates. * Using the same name allows cache sharing when pattern and template code is identical. */ export declare const WRAPPER_FUNCTION_NAME = "__WRAPPER__"; /** * Simple LRU (Least Recently Used) cache implementation using Map's insertion order. * JavaScript Map maintains insertion order, so the first entry is the oldest. * * Used by both Pattern and Template caching to provide bounded memory usage. */ export declare class LRUCache { private maxSize; private cache; constructor(maxSize: number); get(key: K): V | undefined; set(key: K, value: V): void; clear(): void; } /** * Shared global LRU cache for both pattern and template ASTs. * When pattern and template code is identical, they share the same cached AST. * This mirrors JavaTemplate's unified approach in the Java implementation. * Bounded to 100 entries using LRU eviction. */ export declare const globalAstCache: LRUCache; /** * Generates a cache key for template/pattern processing. * Used by both Pattern and Template for consistent cache key generation. * * @param templateParts The template string parts * @param itemsKey String representing the captures/parameters (comma-separated) * @param contextStatements Context declarations * @param dependencies NPM dependencies * @returns A cache key string */ export declare function generateCacheKey(templateParts: string[] | TemplateStringsArray, itemsKey: string, contextStatements: string[], dependencies: Record): string; /** * Structural copy of `tree` with a fresh `id` on every `Tree` node, and the ids that were minted; * counterpart of Java's `RandomizeIdVisitor`. */ export declare function randomizeIds(tree: T): Promise<{ tree: T; ids: ReadonlySet; }>; /** The `id` of every `Tree` node in `tree`. */ export declare function treeIds(tree: J): Promise>; /** Copy of `tree` in which an `id` survives only where it is `retainable` and unused so far. */ export declare function retainIds(tree: T, retainable: ReadonlySet): Promise; /** * Marker that stores capture metadata on pattern AST nodes. * This avoids the need to parse capture names from identifiers during matching. */ export declare class CaptureMarker implements Marker { readonly captureName: string; readonly variadicOptions?: VariadicOptions | undefined; readonly constraint?: ConstraintFunction | undefined; readonly kind = "org.openrewrite.javascript.CaptureMarker"; readonly id: string; constructor(captureName: string, variadicOptions?: VariadicOptions | undefined, constraint?: ConstraintFunction | undefined); } /** * Utility class for managing placeholder naming and parsing. * Centralizes all logic related to capture placeholders. */ export declare class PlaceholderUtils { static readonly CAPTURE_PREFIX = "__capt_"; static readonly PLACEHOLDER_PREFIX = "__PLACEHOLDER_"; /** * Checks if a node is a capture placeholder. * * @param node The node to check * @returns true if the node is a capture placeholder, false otherwise */ static isCapture(node: J): boolean; /** * Gets the CaptureMarker from a node, if present. * * @param node The node to check * @returns The CaptureMarker or undefined */ static getCaptureMarker(node: { markers: Markers; }): CaptureMarker | undefined; /** * Parses a capture placeholder to extract name and type constraint. * * @param identifier The identifier string to parse * @returns Object with name and optional type constraint, or null if not a valid capture */ static parseCapture(identifier: string): { name: string; typeConstraint?: string; } | null; /** * Creates a capture placeholder string. * * @param name The capture name * @param typeConstraint Optional type constraint * @returns The formatted placeholder string */ static createCapture(name: string, typeConstraint?: string): string; /** * Checks if a capture marker indicates a variadic capture. * * @param node The node to check * @returns true if the node has a variadic CaptureMarker, false otherwise */ static isVariadicCapture(node: { markers: Markers; }): boolean; /** * Gets the variadic options from a capture marker. * * @param node The node to extract variadic options from * @returns The VariadicOptions, or undefined if not a variadic capture */ static getVariadicOptions(node: { markers: Markers; }): VariadicOptions | undefined; /** * Extracts the relevant AST node from a wrapper function. * Used by both pattern and template processors to intelligently extract * code from `function __WRAPPER__() { code }` wrappers. * * @param lastStatement The last statement from the compilation unit * @param contextName Context name for error messages (e.g., 'Pattern', 'Template') * @returns The extracted AST node */ static extractFromWrapper(lastStatement: J, contextName: string): J; } //# sourceMappingURL=utils.d.ts.map