import { J } from '../../java'; /** * Union type for all tree node types that the reconciler handles. * This includes J nodes and their wrapper types. */ type TreeNode = J | J.RightPadded | J.LeftPadded | J.Container | J.Space; /** * A visitor that reconciles whitespace from a formatted tree into the original tree. * Walks both trees in parallel and copies whitespace (prefix, before, after) from * the formatted tree to the original. * * The result preserves the original AST's structure, types, and markers while * applying the formatted tree's whitespace. * * When a target subtree is specified, the reconciler only applies whitespace changes * to that subtree and its descendants, leaving surrounding code unchanged. * * When stopAfter is specified, the reconciler stops applying changes after exiting * that node, leaving all subsequent nodes with their original whitespace. */ export declare class WhitespaceReconciler { /** * Flag indicating whether the trees have compatible structure. */ private compatible; /** * The subtree to reconcile (by reference). If undefined, reconcile everything. * Can be a J node, RightPadded, LeftPadded, or Container. */ private targetSubtree?; /** * The node to stop after (by reference). Once we exit this node, stop reconciling. * Can be a J node, RightPadded, LeftPadded, or Container. */ private stopAfterNode?; /** * Tracks the reconciliation state: * - 'searching': Walking but not yet inside target subtree * - 'reconciling': Inside target subtree, applying changes * - 'done': Exited target subtree or stopAfter node, no more changes */ private reconcileState; /** * Reconciles whitespace from a formatted tree into the original tree. * * @param original The original tree (with types, markers, etc.) * @param formatted The formatted tree (with desired whitespace) * @param targetSubtree Optional subtree to limit reconciliation to (by reference). * Can be a J node, RightPadded, LeftPadded, or Container. * If provided, only this subtree and its descendants will have * whitespace and markers applied. * @param stopAfter Optional node to stop reconciliation after (by reference). * Once we exit this node, no more changes are applied. * @returns The original tree with whitespace from the formatted tree */ reconcile(original: J, formatted: J, targetSubtree?: TreeNode, stopAfter?: TreeNode): J; /** * Returns whether the reconciliation was successful (structures were compatible). */ isCompatible(): boolean; /** * Marks structure as incompatible and returns the original unchanged. */ private structureMismatch; /** * Visit a property value, handling all the different types appropriately. * This is the central entry point for visiting any node, including wrappers. * * @returns The reconciled value (original structure with formatted whitespace) */ private visitProperty; /** * Visit all properties of a tree node (J, RightPadded, LeftPadded, Container). * Copies Space values and markers when reconciling, visits everything else. * * Note: The return type may differ from the input type in cases of semantic * equivalence (e.g., Identifier↔Literal with quoteProps), but will always * be a valid VisitableNode. * * @param original Tree node with kind property * @param formatted Corresponding formatted tree node * @returns The original with whitespace from formatted applied */ private visitNode; /** * Check if we should apply whitespace changes at the current position. */ private shouldReconcile; /** * Structurally compare two Space objects for equality. * Currently only TextComment has additional properties (text, multiline); * if new comment types are added, extend the comparison here. */ private spacesEqual; /** * Checks if two nodes with different kinds are semantically equivalent. * This handles cases like Prettier's quoteProps option which can change * property names between Identifier and Literal forms. */ private isSemanticEquivalent; /** * Creates a copy of the formatted node with type information preserved from the original. * Used when we accept a structural change from Prettier (Identifier ↔ Literal) * but need to keep type attribution from the original. * * Only preserves `type` and `fieldType` since those are the only type-related * fields on J.Identifier and J.Literal. */ private copyWithPreservedTypes; } export {}; //# sourceMappingURL=whitespace-reconciler.d.ts.map