import { JavaScriptVisitor } from './visitor'; import { J } from '../java'; import { JS, JSX } from './tree'; import { Cursor, Tree } from "../tree"; /** * A visitor that compares two AST trees in lock step. * It takes another `J` instance as context and visits both trees simultaneously. * The visit operation is aborted when the nodes don't match. */ export declare class JavaScriptComparatorVisitor extends JavaScriptVisitor { /** * Flag indicating whether the trees match so far */ protected match: boolean; /** * Cursor tracking the current position in the target tree. * Maintained in parallel with the pattern tree cursor (this.cursor). */ protected targetCursor?: Cursor; /** * Compares two AST trees. * * @param tree1 The first tree to compare (pattern tree) * @param tree2 The second tree to compare (target tree) * @param parentCursor1 Optional parent cursor for the pattern tree (for navigating to root) * @param parentCursor2 Optional parent cursor for the target tree (for navigating to root) * @returns true if the trees match, false otherwise */ compare(tree1: J, tree2: J, parentCursor1?: Cursor, parentCursor2?: Cursor): Promise; /** * Checks if two nodes have the same kind. * * @param j The node being visited * @param other The other node to compare with * @returns true if the nodes have the same kind, false otherwise */ protected hasSameKind(j: J, other: J): boolean; /** * Aborts the visit operation by setting the match flag to false. * * @param t The node being compared * @param reason Optional reason for the mismatch (e.g., 'kind-mismatch', 'property-mismatch') * @param propertyName Optional property name where mismatch occurred * @param expected Optional expected value * @param actual Optional actual value */ protected abort(t: T, reason?: string, propertyName?: string, expected?: any, actual?: any): T; /** * Specialized abort methods for common mismatch scenarios. * These provide a cleaner API at call sites. * Can be overridden in subclasses to extract values from cursors and provide richer error messages. */ protected kindMismatch(): any; protected structuralMismatch(propertyName?: string): any; protected arrayLengthMismatch(propertyName: string): any; protected valueMismatch(propertyName?: string, expected?: any, actual?: any): any; protected typeMismatch(propertyName?: string): any; /** * Helper method to visit an array property by iterating through both arrays in lock-step. * Checks length mismatch first, then visits each element pair. * Can be overridden in subclasses to add path tracking or other instrumentation. * * @param parent The parent node containing the array property * @param propertyName The name of the array property * @param array1 The array from the first tree * @param array2 The array from the second tree * @param visitor Function to visit each element pair (no need to return anything) * @returns undefined, modifying this.match if a mismatch occurs */ protected visitArrayProperty(parent: J, propertyName: string, array1: T[], array2: T[], visitor: (item1: T, item2: T, index: number) => Promise): Promise; /** * Helper method to visit a container property with proper context. * Can be overridden in subclasses to add path tracking or other instrumentation. * * @param parent The parent node containing the container property * @param propertyName The name of the container property * @param container The container from the first tree * @param otherContainer The container from the second tree * @returns The container from the first tree */ protected visitContainerProperty(propertyName: string, container: J.Container, otherContainer: J.Container): Promise>; /** * Helper to visit a RightPadded property with property context. * This allows subclasses to track which property is being visited. * * @param propertyName The property name for context * @param rightPadded The RightPadded from the first tree * @param otherRightPadded The RightPadded from the second tree * @returns The RightPadded from the first tree */ protected visitRightPaddedProperty(propertyName: string, rightPadded: J.RightPadded, otherRightPadded: J.RightPadded): Promise>; /** * Helper to visit a LeftPadded property with property context. * This allows subclasses to track which property is being visited. * * @param propertyName The property name for context * @param leftPadded The LeftPadded from the first tree * @param otherLeftPadded The LeftPadded from the second tree * @returns The LeftPadded from the first tree */ protected visitLeftPaddedProperty(propertyName: string, leftPadded: J.LeftPadded, otherLeftPadded: J.LeftPadded): Promise>; /** * Generic method to visit a property value using the appropriate visitor method. * This ensures wrappers (RightPadded, LeftPadded, Container) are properly tracked on the cursor. * * @param j The property value from the first tree * @param other The corresponding property value from the second tree * @param propertyName Optional property name for error reporting * @returns The visited property value from the first tree */ protected visitProperty(j: any, other: any, propertyName?: string): Promise; /** * Generic method to visit all properties of an element, calling visitProperty for each. * This automatically handles wrappers and ensures proper cursor tracking. * Also checks that both elements have the same kind. * * @param j The element from the first tree * @param other The corresponding element from the second tree * @returns The visited element from the first tree */ protected visitElement(j: T, other: T): Promise; visit(j: Tree, p: J, parent?: Cursor): Promise; /** * Override visitRightPadded to compare only the elements, not markers or spacing. * The context parameter p contains the corresponding element from the other tree. * Pushes the wrapper onto the cursor stack so captures can access it. * Also updates targetCursor in parallel. */ visitRightPadded(right: J.RightPadded, p: J): Promise>; /** * Override visitLeftPadded to compare only the elements, not markers or spacing. * The context parameter p contains the corresponding element from the other tree. * Pushes the wrapper onto the cursor stack so captures can access it. * Also updates targetCursor in parallel. */ visitLeftPadded(left: J.LeftPadded, p: J): Promise>; /** * Override visitContainer to compare only the elements, not markers or spacing. * The context parameter p contains the corresponding element from the other tree. * Pushes the wrapper onto the cursor stack so captures can access it. * Also updates targetCursor in parallel. */ visitContainer(container: J.Container, p: J): Promise>; /** * Overrides the visitBinary method to compare binary expressions. * * @param binary The binary expression to visit * @param other The other binary expression to compare with * @returns The visited binary expression, or undefined if the visit was aborted */ visitBinary(binary: J.Binary, other: J): Promise; /** * Overrides the visitIdentifier method to compare identifiers. * * @param identifier The identifier to visit * @param other The other identifier to compare with * @returns The visited identifier, or undefined if the visit was aborted */ visitIdentifier(identifier: J.Identifier, other: J): Promise; /** * Overrides the visitLiteral method to compare literals. * * @param literal The literal to visit * @param other The other literal to compare with * @returns The visited literal, or undefined if the visit was aborted */ visitLiteral(literal: J.Literal, other: J): Promise; /** * Overrides the visitBlock method to compare blocks. * * @param block The block to visit * @param other The other block to compare with * @returns The visited block, or undefined if the visit was aborted */ visitBlock(block: J.Block, other: J): Promise; /** * Overrides the visitJsCompilationUnit method to compare compilation units. * * @param compilationUnit The compilation unit to visit * @param other The other compilation unit to compare with * @returns The visited compilation unit, or undefined if the visit was aborted */ visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, other: J): Promise; /** * Overrides the visitAlias method to compare aliases. * * @param alias The alias to visit * @param other The other alias to compare with * @returns The visited alias, or undefined if the visit was aborted */ visitAlias(alias: JS.Alias, other: J): Promise; /** * Overrides the visitArrowFunction method to compare arrow functions. * * @param arrowFunction The arrow function to visit * @param other The other arrow function to compare with * @returns The visited arrow function, or undefined if the visit was aborted */ visitArrowFunction(arrowFunction: JS.ArrowFunction, other: J): Promise; /** * Overrides the visitAwait method to compare await expressions. * * @param await_ The await expression to visit * @param other The other await expression to compare with * @returns The visited await expression, or undefined if the visit was aborted */ visitAwait(await_: JS.Await, other: J): Promise; /** * Overrides the visitJsxTag method to compare JSX tags. * * @param element The JSX tag to visit * @param other The other JSX tag to compare with * @returns The visited JSX tag, or undefined if the visit was aborted */ visitJsxTag(element: JSX.Tag, other: J): Promise; /** * Overrides the visitJsxAttribute method to compare JSX attributes. * * @param attribute The JSX attribute to visit * @param other The other JSX attribute to compare with * @returns The visited JSX attribute, or undefined if the visit was aborted */ visitJsxAttribute(attribute: JSX.Attribute, other: J): Promise; /** * Overrides the visitJsxSpreadAttribute method to compare JSX spread attributes. * * @param spread The JSX spread attribute to visit * @param other The other JSX spread attribute to compare with * @returns The visited JSX spread attribute, or undefined if the visit was aborted */ visitJsxSpreadAttribute(spread: JSX.SpreadAttribute, other: J): Promise; /** * Overrides the visitJsxExpression method to compare JSX expressions. * * @param expr The JSX expression to visit * @param other The other JSX expression to compare with * @returns The visited JSX expression, or undefined if the visit was aborted */ visitJsxEmbeddedExpression(expr: JSX.EmbeddedExpression, other: J): Promise; /** * Overrides the visitJsxNamespacedName method to compare JSX namespaced names. * * @param ns The JSX namespaced name to visit * @param other The other JSX namespaced name to compare with * @returns The visited JSX namespaced name, or undefined if the visit was aborted */ visitJsxNamespacedName(ns: JSX.NamespacedName, other: J): Promise; /** * Overrides the visitConditionalType method to compare conditional types. * * @param conditionalType The conditional type to visit * @param other The other conditional type to compare with * @returns The visited conditional type, or undefined if the visit was aborted */ visitConditionalType(conditionalType: JS.ConditionalType, other: J): Promise; /** * Overrides the visitDelete method to compare delete expressions. * * @param delete_ The delete expression to visit * @param other The other delete expression to compare with * @returns The visited delete expression, or undefined if the visit was aborted */ visitDelete(delete_: JS.Delete, other: J): Promise; /** * Overrides the visitExpressionStatement method to compare expression statements. * * @param expressionStatement The expression statement to visit * @param other The other expression statement to compare with * @returns The visited expression statement, or undefined if the visit was aborted */ visitExpressionStatement(expressionStatement: JS.ExpressionStatement, other: J): Promise; /** * Overrides the visitExpressionWithTypeArguments method to compare expressions with type arguments. * * @param expressionWithTypeArguments The expression with type arguments to visit * @param other The other expression with type arguments to compare with * @returns The visited expression with type arguments, or undefined if the visit was aborted */ visitExpressionWithTypeArguments(expressionWithTypeArguments: JS.ExpressionWithTypeArguments, other: J): Promise; /** * Overrides the visitFunctionCall method to compare method invocations. * * @param functionCall The function call to visit * @param other The other function call to compare with * @returns The visited function call, or undefined if the visit was aborted */ visitFunctionCall(functionCall: JS.FunctionCall, other: J): Promise; /** * Overrides the visitFunctionType method to compare function types. * * @param functionType The function type to visit * @param other The other function type to compare with * @returns The visited function type, or undefined if the visit was aborted */ visitFunctionType(functionType: JS.FunctionType, other: J): Promise; /** * Overrides the visitInferType method to compare infer types. * * @param inferType The infer type to visit * @param other The other infer type to compare with * @returns The visited infer type, or undefined if the visit was aborted */ visitInferType(inferType: JS.InferType, other: J): Promise; /** * Overrides the visitImportType method to compare import types. * * @param importType The import type to visit * @param other The other import type to compare with * @returns The visited import type, or undefined if the visit was aborted */ visitImportType(importType: JS.ImportType, other: J): Promise; /** * Overrides the visitImportDeclaration method to compare import declarations. * * @param jsImport The import declaration to visit * @param other The other import declaration to compare with * @returns The visited import declaration, or undefined if the visit was aborted */ visitImportDeclaration(jsImport: JS.Import, other: J): Promise; /** * Overrides the visitImportClause method to compare import clauses. * * @param importClause The import clause to visit * @param other The other import clause to compare with * @returns The visited import clause, or undefined if the visit was aborted */ visitImportClause(importClause: JS.ImportClause, other: J): Promise; /** * Overrides the visitNamedImports method to compare named imports. * * @param namedImports The named imports to visit * @param other The other named imports to compare with * @returns The visited named imports, or undefined if the visit was aborted */ visitNamedImports(namedImports: JS.NamedImports, other: J): Promise; /** * Overrides the visitImportSpecifier method to compare import specifiers. * * @param importSpecifier The import specifier to visit * @param other The other import specifier to compare with * @returns The visited import specifier, or undefined if the visit was aborted */ visitImportSpecifier(importSpecifier: JS.ImportSpecifier, other: J): Promise; /** * Overrides the visitImportAttributes method to compare import attributes. * * @param importAttributes The import attributes to visit * @param other The other import attributes to compare with * @returns The visited import attributes, or undefined if the visit was aborted */ visitImportAttributes(importAttributes: JS.ImportAttributes, other: J): Promise; /** * Overrides the visitImportTypeAttributes method to compare import type attributes. * * @param importTypeAttributes The import type attributes to visit * @param other The other import type attributes to compare with * @returns The visited import type attributes, or undefined if the visit was aborted */ visitImportTypeAttributes(importTypeAttributes: JS.ImportTypeAttributes, other: J): Promise; /** * Overrides the visitImportAttribute method to compare import attributes. * * @param importAttribute The import attribute to visit * @param other The other import attribute to compare with * @returns The visited import attribute, or undefined if the visit was aborted */ visitImportAttribute(importAttribute: JS.ImportAttribute, other: J): Promise; /** * Overrides the visitBinaryExtensions method to compare binary expressions. * * @param jsBinary The binary expression to visit * @param other The other binary expression to compare with * @returns The visited binary expression, or undefined if the visit was aborted */ visitBinaryExtensions(jsBinary: JS.Binary, other: J): Promise; /** * Overrides the visitLiteralType method to compare literal types. * * @param literalType The literal type to visit * @param other The other literal type to compare with * @returns The visited literal type, or undefined if the visit was aborted */ visitLiteralType(literalType: JS.LiteralType, other: J): Promise; /** * Overrides the visitMappedType method to compare mapped types. * * @param mappedType The mapped type to visit * @param other The other mapped type to compare with * @returns The visited mapped type, or undefined if the visit was aborted */ visitMappedType(mappedType: JS.MappedType, other: J): Promise; /** * Overrides the visitKeysRemapping method to compare keys remapping. * * @param keysRemapping The keys remapping to visit * @param other The other keys remapping to compare with * @returns The visited keys remapping, or undefined if the visit was aborted */ visitMappedTypeKeysRemapping(keysRemapping: JS.MappedType.KeysRemapping, other: J): Promise; /** * Overrides the visitMappedTypeParameter method to compare mapped type parameters. * * @param mappedTypeParameter The mapped type parameter to visit * @param other The other mapped type parameter to compare with * @returns The visited mapped type parameter, or undefined if the visit was aborted */ visitMappedTypeParameter(mappedTypeParameter: JS.MappedType.Parameter, other: J): Promise; /** * Overrides the visitObjectBindingPattern method to compare object binding declarations. * * @param objectBindingPattern The object binding declarations to visit * @param other The other object binding declarations to compare with * @returns The visited object binding declarations, or undefined if the visit was aborted */ visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, other: J): Promise; /** * Overrides the visitPropertyAssignment method to compare property assignments. * * @param propertyAssignment The property assignment to visit * @param other The other property assignment to compare with * @returns The visited property assignment, or undefined if the visit was aborted */ visitPropertyAssignment(propertyAssignment: JS.PropertyAssignment, other: J): Promise; /** * Overrides the visitSatisfiesExpression method to compare satisfies expressions. * * @param satisfiesExpression The satisfies expression to visit * @param other The other satisfies expression to compare with * @returns The visited satisfies expression, or undefined if the visit was aborted */ visitSatisfiesExpression(satisfiesExpression: JS.SatisfiesExpression, other: J): Promise; /** * Overrides the visitScopedVariableDeclarations method to compare scoped variable declarations. * * @param scopedVariableDeclarations The scoped variable declarations to visit * @param other The other scoped variable declarations to compare with * @returns The visited scoped variable declarations, or undefined if the visit was aborted */ visitScopedVariableDeclarations(scopedVariableDeclarations: JS.ScopedVariableDeclarations, other: J): Promise; /** * Overrides the visitShebang method to compare shebangs. * * @param shebang The shebang to visit * @param other The other shebang to compare with * @returns The visited shebang, or undefined if the visit was aborted */ visitShebang(shebang: JS.Shebang, other: J): Promise; /** * Overrides the visitSpread method to compare spread expressions. * * @param spread The spread expression to visit * @param other The other spread expression to compare with * @returns The visited spread expression, or undefined if the visit was aborted */ visitSpread(spread: JS.Spread, other: J): Promise; /** * Overrides the visitStatementExpression method to compare statement expressions. * * @param statementExpression The statement expression to visit * @param other The other statement expression to compare with * @returns The visited statement expression, or undefined if the visit was aborted */ visitStatementExpression(statementExpression: JS.StatementExpression, other: J): Promise; /** * Overrides the visitTaggedTemplateExpression method to compare tagged template expressions. * * @param taggedTemplateExpression The tagged template expression to visit * @param other The other tagged template expression to compare with * @returns The visited tagged template expression, or undefined if the visit was aborted */ visitTaggedTemplateExpression(taggedTemplateExpression: JS.TaggedTemplateExpression, other: J): Promise; /** * Overrides the visitTemplateExpression method to compare template expressions. * * @param templateExpression The template expression to visit * @param other The other template expression to compare with * @returns The visited template expression, or undefined if the visit was aborted */ visitTemplateExpression(templateExpression: JS.TemplateExpression, other: J): Promise; /** * Overrides the visitTemplateExpressionSpan method to compare template expression spans. * * @param span The template expression span to visit * @param other The other template expression span to compare with * @returns The visited template expression span, or undefined if the visit was aborted */ visitTemplateExpressionSpan(span: JS.TemplateExpression.Span, other: J): Promise; /** * Overrides the visitTuple method to compare tuples. * * @param tuple The tuple to visit * @param other The other tuple to compare with * @returns The visited tuple, or undefined if the visit was aborted */ visitTuple(tuple: JS.Tuple, other: J): Promise; /** * Overrides the visitTypeDeclaration method to compare type declarations. * * @param typeDeclaration The type declaration to visit * @param other The other type declaration to compare with * @returns The visited type declaration, or undefined if the visit was aborted */ visitTypeDeclaration(typeDeclaration: JS.TypeDeclaration, other: J): Promise; /** * Overrides the visitTypeOf method to compare typeof expressions. * * @param typeOf The typeof expression to visit * @param other The other typeof expression to compare with * @returns The visited typeof expression, or undefined if the visit was aborted */ visitTypeOf(typeOf: JS.TypeOf, other: J): Promise; /** * Overrides the visitTypeTreeExpression method to compare type tree expressions. * * @param typeTreeExpression The type tree expression to visit * @param other The other type tree expression to compare with * @returns The visited type tree expression, or undefined if the visit was aborted */ visitTypeTreeExpression(typeTreeExpression: JS.TypeTreeExpression, other: J): Promise; /** * Overrides the visitAs method to compare as expressions. * * @param as_ The as expression to visit * @param other The other as expression to compare with * @returns The visited as expression, or undefined if the visit was aborted */ visitAs(as_: JS.As, other: J): Promise; /** * Overrides the visitAssignmentOperationExtensions method to compare assignment operations. * * @param assignmentOperation The assignment operation to visit * @param other The other assignment operation to compare with * @returns The visited assignment operation, or undefined if the visit was aborted */ visitAssignmentOperationExtensions(assignmentOperation: JS.AssignmentOperation, other: J): Promise; /** * Overrides the visitIndexedAccessType method to compare indexed access types. * * @param indexedAccessType The indexed access type to visit * @param other The other indexed access type to compare with * @returns The visited indexed access type, or undefined if the visit was aborted */ visitIndexedAccessType(indexedAccessType: JS.IndexedAccessType, other: J): Promise; /** * Overrides the visitIndexType method to compare index types. * * @param indexType The index type to visit * @param other The other index type to compare with * @returns The visited index type, or undefined if the visit was aborted */ visitIndexedAccessTypeIndexType(indexType: JS.IndexedAccessType.IndexType, other: J): Promise; /** * Overrides the visitTypeQuery method to compare type queries. * * @param typeQuery The type query to visit * @param other The other type query to compare with * @returns The visited type query, or undefined if the visit was aborted */ visitTypeQuery(typeQuery: JS.TypeQuery, other: J): Promise; /** * Overrides the visitTypeInfo method to compare type info. * * @param typeInfo The type info to visit * @param other The other type info to compare with * @returns The visited type info, or undefined if the visit was aborted */ visitTypeInfo(typeInfo: JS.TypeInfo, other: J): Promise; /** * Overrides the visitComputedPropertyName method to compare computed property names. * * @param computedPropertyName The computed property name to visit * @param other The other computed property name to compare with * @returns The visited computed property name, or undefined if the visit was aborted */ visitComputedPropertyName(computedPropertyName: JS.ComputedPropertyName, other: J): Promise; /** * Overrides the visitTypeOperator method to compare type operators. * * @param typeOperator The type operator to visit * @param other The other type operator to compare with * @returns The visited type operator, or undefined if the visit was aborted */ visitTypeOperator(typeOperator: JS.TypeOperator, other: J): Promise; /** * Overrides the visitTypePredicate method to compare type predicates. * * @param typePredicate The type predicate to visit * @param other The other type predicate to compare with * @returns The visited type predicate, or undefined if the visit was aborted */ visitTypePredicate(typePredicate: JS.TypePredicate, other: J): Promise; /** * Overrides the visitUnion method to compare unions. * * @param union The union to visit * @param other The other union to compare with * @returns The visited union, or undefined if the visit was aborted */ visitUnion(union: JS.Union, other: J): Promise; /** * Overrides the visitIntersection method to compare intersections. * * @param intersection The intersection to visit * @param other The other intersection to compare with * @returns The visited intersection, or undefined if the visit was aborted */ visitIntersection(intersection: JS.Intersection, other: J): Promise; /** * Overrides the visitAnnotatedType method to compare annotated types. * * @param annotatedType The annotated type to visit * @param other The other annotated type to compare with * @returns The visited annotated type, or undefined if the visit was aborted */ visitAnnotatedType(annotatedType: J.AnnotatedType, other: J): Promise; /** * Overrides the visitAnnotation method to compare annotations. * * @param annotation The annotation to visit * @param other The other annotation to compare with * @returns The visited annotation, or undefined if the visit was aborted */ visitAnnotation(annotation: J.Annotation, other: J): Promise; /** * Overrides the visitArrayAccess method to compare array access expressions. * * @param arrayAccess The array access expression to visit * @param other The other array access expression to compare with * @returns The visited array access expression, or undefined if the visit was aborted */ visitArrayAccess(arrayAccess: J.ArrayAccess, other: J): Promise; /** * Overrides the visitArrayDimension method to compare array dimensions. * * @param arrayDimension The array dimension to visit * @param other The other array dimension to compare with * @returns The visited array dimension, or undefined if the visit was aborted */ visitArrayDimension(arrayDimension: J.ArrayDimension, other: J): Promise; /** * Overrides the visitArrayType method to compare array types. * * @param arrayType The array type to visit * @param other The other array type to compare with * @returns The visited array type, or undefined if the visit was aborted */ visitArrayType(arrayType: J.ArrayType, other: J): Promise; /** * Overrides the visitAssert method to compare assert statements. * * @param anAssert The assert statement to visit * @param other The other assert statement to compare with * @returns The visited assert statement, or undefined if the visit was aborted */ visitAssert(anAssert: J.Assert, other: J): Promise; /** * Overrides the visitAssignment method to compare assignment expressions. * * @param assignment The assignment expression to visit * @param other The other assignment expression to compare with * @returns The visited assignment expression, or undefined if the visit was aborted */ visitAssignment(assignment: J.Assignment, other: J): Promise; /** * Overrides the visitAssignmentOperation method to compare assignment operation expressions. * * @param assignOp The assignment operation expression to visit * @param other The other assignment operation expression to compare with * @returns The visited assignment operation expression, or undefined if the visit was aborted */ visitAssignmentOperation(assignOp: J.AssignmentOperation, other: J): Promise; /** * Overrides the visitBreak method to compare break statements. * * @param breakStatement The break statement to visit * @param other The other break statement to compare with * @returns The visited break statement, or undefined if the visit was aborted */ visitBreak(breakStatement: J.Break, other: J): Promise; /** * Overrides the visitCase method to compare case statements. * * @param aCase The case statement to visit * @param other The other case statement to compare with * @returns The visited case statement, or undefined if the visit was aborted */ visitCase(aCase: J.Case, other: J): Promise; /** * Overrides the visitClassDeclaration method to compare class declarations. * * @param classDecl The class declaration to visit * @param other The other class declaration to compare with * @returns The visited class declaration, or undefined if the visit was aborted */ visitClassDeclaration(classDecl: J.ClassDeclaration, other: J): Promise; /** * Overrides the visitClassDeclarationKind method to compare class declaration kinds. * * @param kind The class declaration kind to visit * @param other The other class declaration kind to compare with * @returns The visited class declaration kind, or undefined if the visit was aborted */ visitClassDeclarationKind(kind: J.ClassDeclaration.Kind, other: J): Promise; /** * Overrides the visitCompilationUnit method to compare compilation units. * * @param compilationUnit The compilation unit to visit * @param other The other compilation unit to compare with * @returns The visited compilation unit, or undefined if the visit was aborted */ visitCompilationUnit(compilationUnit: J.CompilationUnit, other: J): Promise; /** * Overrides the visitContinue method to compare continue statements. * * @param continueStatement The continue statement to visit * @param other The other continue statement to compare with * @returns The visited continue statement, or undefined if the visit was aborted */ visitContinue(continueStatement: J.Continue, other: J): Promise; /** * Overrides the visitControlParentheses method to compare control parentheses. * * @param controlParens The control parentheses to visit * @param other The other control parentheses to compare with * @returns The visited control parentheses, or undefined if the visit was aborted */ visitControlParentheses(controlParens: J.ControlParentheses, other: J): Promise; /** * Overrides the visitDeconstructionPattern method to compare deconstruction patterns. * * @param pattern The deconstruction pattern to visit * @param other The other deconstruction pattern to compare with * @returns The visited deconstruction pattern, or undefined if the visit was aborted */ visitDeconstructionPattern(pattern: J.DeconstructionPattern, other: J): Promise; /** * Overrides the visitDoWhileLoop method to compare do-while loops. * * @param doWhileLoop The do-while loop to visit * @param other The other do-while loop to compare with * @returns The visited do-while loop, or undefined if the visit was aborted */ visitDoWhileLoop(doWhileLoop: J.DoWhileLoop, other: J): Promise; /** * Overrides the visitEmpty method to compare empty statements. * * @param empty The empty statement to visit * @param other The other empty statement to compare with * @returns The visited empty statement, or undefined if the visit was aborted */ visitEmpty(empty: J.Empty, other: J): Promise; /** * Overrides the visitEnumValue method to compare enum values. * * @param enumValue The enum value to visit * @param other The other enum value to compare with * @returns The visited enum value, or undefined if the visit was aborted */ visitEnumValue(enumValue: J.EnumValue, other: J): Promise; /** * Overrides the visitEnumValueSet method to compare enum value sets. * * @param enumValueSet The enum value set to visit * @param other The other enum value set to compare with * @returns The visited enum value set, or undefined if the visit was aborted */ visitEnumValueSet(enumValueSet: J.EnumValueSet, other: J): Promise; /** * Overrides the visitErroneous method to compare erroneous nodes. * * @param erroneous The erroneous node to visit * @param other The other erroneous node to compare with * @returns The visited erroneous node, or undefined if the visit was aborted */ visitErroneous(erroneous: J.Erroneous, other: J): Promise; /** * Overrides the visitFieldAccess method to compare field access expressions. * * @param fieldAccess The field access expression to visit * @param other The other field access expression to compare with * @returns The visited field access expression, or undefined if the visit was aborted */ visitFieldAccess(fieldAccess: J.FieldAccess, other: J): Promise; /** * Overrides the visitForEachLoop method to compare for-each loops. * * @param forEachLoop The for-each loop to visit * @param other The other for-each loop to compare with * @returns The visited for-each loop, or undefined if the visit was aborted */ visitForEachLoop(forEachLoop: J.ForEachLoop, other: J): Promise; /** * Overrides the visitForEachLoopControl method to compare for-each loop controls. * * @param control The for-each loop control to visit * @param other The other for-each loop control to compare with * @returns The visited for-each loop control, or undefined if the visit was aborted */ visitForEachLoopControl(control: J.ForEachLoop.Control, other: J): Promise; /** * Overrides the visitForLoop method to compare for loops. * * @param forLoop The for loop to visit * @param other The other for loop to compare with * @returns The visited for loop, or undefined if the visit was aborted */ visitForLoop(forLoop: J.ForLoop, other: J): Promise; /** * Overrides the visitForLoopControl method to compare for loop controls. * * @param control The for loop control to visit * @param other The other for loop control to compare with * @returns The visited for loop control, or undefined if the visit was aborted */ visitForLoopControl(control: J.ForLoop.Control, other: J): Promise; /** * Overrides the visitIf method to compare if statements. * * @param ifStatement The if statement to visit * @param other The other if statement to compare with * @returns The visited if statement, or undefined if the visit was aborted */ visitIf(ifStatement: J.If, other: J): Promise; /** * Overrides the visitElse method to compare else statements. * * @param elseStatement The else statement to visit * @param other The other else statement to compare with * @returns The visited else statement, or undefined if the visit was aborted */ visitElse(elseStatement: J.If.Else, other: J): Promise; /** * Overrides the visitImport method to compare import statements. * * @param importStatement The import statement to visit * @param other The other import statement to compare with * @returns The visited import statement, or undefined if the visit was aborted */ visitImport(importStatement: J.Import, other: J): Promise; /** * Overrides the visitInstanceOf method to compare instanceof expressions. * * @param instanceOf The instanceof expression to visit * @param other The other instanceof expression to compare with * @returns The visited instanceof expression, or undefined if the visit was aborted */ visitInstanceOf(instanceOf: J.InstanceOf, other: J): Promise; /** * Overrides the visitIntersectionType method to compare intersection types. * * @param intersectionType The intersection type to visit * @param other The other intersection type to compare with * @returns The visited intersection type, or undefined if the visit was aborted */ visitIntersectionType(intersectionType: J.IntersectionType, other: J): Promise; /** * Overrides the visitLabel method to compare label statements. * * @param label The label statement to visit * @param other The other label statement to compare with * @returns The visited label statement, or undefined if the visit was aborted */ visitLabel(label: J.Label, other: J): Promise; /** * Overrides the visitLambda method to compare lambda expressions. * * @param lambda The lambda expression to visit * @param other The other lambda expression to compare with * @returns The visited lambda expression, or undefined if the visit was aborted */ visitLambda(lambda: J.Lambda, other: J): Promise; /** * Overrides the visitLambdaParameters method to compare lambda parameters. * * @param parameters The lambda parameters to visit * @param other The other lambda parameters to compare with * @returns The visited lambda parameters, or undefined if the visit was aborted */ visitLambdaParameters(parameters: J.Lambda.Parameters, other: J): Promise; /** * Overrides the visitMemberReference method to compare member references. * * @param memberReference The member reference to visit * @param other The other member reference to compare with * @returns The visited member reference, or undefined if the visit was aborted */ visitMemberReference(memberReference: J.MemberReference, other: J): Promise; /** * Overrides the visitMethodDeclaration method to compare method declarations. * * @param methodDeclaration The method declaration to visit * @param other The other method declaration to compare with * @returns The visited method declaration, or undefined if the visit was aborted */ visitMethodDeclaration(methodDeclaration: J.MethodDeclaration, other: J): Promise; /** * Overrides the visitMethodInvocation method to compare method invocations. * * @param methodInvocation The method invocation to visit * @param other The other method invocation to compare with * @returns The visited method invocation, or undefined if the visit was aborted */ visitMethodInvocation(methodInvocation: J.MethodInvocation, other: J): Promise; /** * Overrides the visitModifier method to compare modifiers. * * @param modifier The modifier to visit * @param other The other modifier to compare with * @returns The visited modifier, or undefined if the visit was aborted */ visitModifier(modifier: J.Modifier, other: J): Promise; /** * Overrides the visitMultiCatch method to compare multi-catch expressions. * * @param multiCatch The multi-catch expression to visit * @param other The other multi-catch expression to compare with * @returns The visited multi-catch expression, or undefined if the visit was aborted */ visitMultiCatch(multiCatch: J.MultiCatch, other: J): Promise; /** * Overrides the visitNewArray method to compare new array expressions. * * @param newArray The new array expression to visit * @param other The other new array expression to compare with * @returns The visited new array expression, or undefined if the visit was aborted */ visitNewArray(newArray: J.NewArray, other: J): Promise; /** * Overrides the visitNewClass method to compare new class expressions. * * @param newClass The new class expression to visit * @param other The other new class expression to compare with * @returns The visited new class expression, or undefined if the visit was aborted */ visitNewClass(newClass: J.NewClass, other: J): Promise; /** * Overrides the visitNullableType method to compare nullable types. * * @param nullableType The nullable type to visit * @param other The other nullable type to compare with * @returns The visited nullable type, or undefined if the visit was aborted */ visitNullableType(nullableType: J.NullableType, other: J): Promise; /** * Overrides the visitPackage method to compare package declarations. * * @param packageDeclaration The package declaration to visit * @param other The other package declaration to compare with * @returns The visited package declaration, or undefined if the visit was aborted */ visitPackage(packageDeclaration: J.Package, other: J): Promise; /** * Overrides the visitParameterizedType method to compare parameterized types. * * @param parameterizedType The parameterized type to visit * @param other The other parameterized type to compare with * @returns The visited parameterized type, or undefined if the visit was aborted */ visitParameterizedType(parameterizedType: J.ParameterizedType, other: J): Promise; /** * Overrides the visitParentheses method to compare parentheses expressions. * * @param parentheses The parentheses expression to visit * @param other The other parentheses expression to compare with * @returns The visited parentheses expression, or undefined if the visit was aborted */ visitParentheses(parentheses: J.Parentheses, other: J): Promise; /** * Overrides the visitParenthesizedTypeTree method to compare parenthesized type trees. * * @param parenthesizedTypeTree The parenthesized type tree to visit * @param other The other parenthesized type tree to compare with * @returns The visited parenthesized type tree, or undefined if the visit was aborted */ visitParenthesizedTypeTree(parenthesizedTypeTree: J.ParenthesizedTypeTree, other: J): Promise; /** * Overrides the visitPrimitive method to compare primitive types. * * @param primitive The primitive type to visit * @param other The other primitive type to compare with * @returns The visited primitive type, or undefined if the visit was aborted */ visitPrimitive(primitive: J.Primitive, other: J): Promise; /** * Overrides the visitReturn method to compare return statements. * * @param returnStatement The return statement to visit * @param other The other return statement to compare with * @returns The visited return statement, or undefined if the visit was aborted */ visitReturn(returnStatement: J.Return, other: J): Promise; /** * Overrides the visitSwitch method to compare switch statements. * * @param switchStatement The switch statement to visit * @param other The other switch statement to compare with * @returns The visited switch statement, or undefined if the visit was aborted */ visitSwitch(switchStatement: J.Switch, other: J): Promise; /** * Overrides the visitSwitchExpression method to compare switch expressions. * * @param switchExpression The switch expression to visit * @param other The other switch expression to compare with * @returns The visited switch expression, or undefined if the visit was aborted */ visitSwitchExpression(switchExpression: J.SwitchExpression, other: J): Promise; /** * Overrides the visitSynchronized method to compare synchronized statements. * * @param synchronizedStatement The synchronized statement to visit * @param other The other synchronized statement to compare with * @returns The visited synchronized statement, or undefined if the visit was aborted */ visitSynchronized(synchronizedStatement: J.Synchronized, other: J): Promise; /** * Overrides the visitTernary method to compare ternary expressions. * * @param ternary The ternary expression to visit * @param other The other ternary expression to compare with * @returns The visited ternary expression, or undefined if the visit was aborted */ visitTernary(ternary: J.Ternary, other: J): Promise; /** * Overrides the visitThrow method to compare throw statements. * * @param throwStatement The throw statement to visit * @param other The other throw statement to compare with * @returns The visited throw statement, or undefined if the visit was aborted */ visitThrow(throwStatement: J.Throw, other: J): Promise; /** * Overrides the visitTry method to compare try statements. * * @param tryStatement The try statement to visit * @param other The other try statement to compare with * @returns The visited try statement, or undefined if the visit was aborted */ visitTry(tryStatement: J.Try, other: J): Promise; /** * Overrides the visitTryResource method to compare try resources. * * @param resource The try resource to visit * @param other The other try resource to compare with * @returns The visited try resource, or undefined if the visit was aborted */ visitTryResource(resource: J.Try.Resource, other: J): Promise; /** * Overrides the visitTryCatch method to compare try catch blocks. * * @param tryCatch The try catch block to visit * @param other The other try catch block to compare with * @returns The visited try catch block, or undefined if the visit was aborted */ visitTryCatch(tryCatch: J.Try.Catch, other: J): Promise; /** * Overrides the visitTypeCast method to compare type cast expressions. * * @param typeCast The type cast expression to visit * @param other The other type cast expression to compare with * @returns The visited type cast expression, or undefined if the visit was aborted */ visitTypeCast(typeCast: J.TypeCast, other: J): Promise; /** * Overrides the visitTypeParameter method to compare type parameters. * * @param typeParameter The type parameter to visit * @param other The other type parameter to compare with * @returns The visited type parameter, or undefined if the visit was aborted */ visitTypeParameter(typeParameter: J.TypeParameter, other: J): Promise; /** * Overrides the visitTypeParameters method to compare type parameters. * * @param typeParameters The type parameters to visit * @param other The other type parameters to compare with * @returns The visited type parameters, or undefined if the visit was aborted */ visitTypeParameters(typeParameters: J.TypeParameters, other: J): Promise; /** * Overrides the visitUnary method to compare unary expressions. * * @param unary The unary expression to visit * @param other The other unary expression to compare with * @returns The visited unary expression, or undefined if the visit was aborted */ visitUnary(unary: J.Unary, other: J): Promise; /** * Overrides the visitUnknown method to compare unknown nodes. * * @param unknown The unknown node to visit * @param other The other unknown node to compare with * @returns The visited unknown node, or undefined if the visit was aborted */ visitUnknown(unknown: J.Unknown, other: J): Promise; /** * Overrides the visitUnknownSource method to compare unknown sources. * * @param unknownSource The unknown source to visit * @param other The other unknown source to compare with * @returns The visited unknown source, or undefined if the visit was aborted */ visitUnknownSource(unknownSource: J.UnknownSource, other: J): Promise; /** * Overrides the visitVariableDeclarations method to compare variable declarations. * * @param variableDeclarations The variable declarations to visit * @param other The other variable declarations to compare with * @returns The visited variable declarations, or undefined if the visit was aborted */ visitVariableDeclarations(variableDeclarations: J.VariableDeclarations, other: J): Promise; /** * Overrides the visitVariable method to compare variable declarations. * * @param variable The variable declaration to visit * @param other The other variable declaration to compare with * @returns The visited variable declaration, or undefined if the visit was aborted */ visitVariable(variable: J.VariableDeclarations.NamedVariable, other: J): Promise; /** * Overrides the visitWhileLoop method to compare while loops. * * @param whileLoop The while loop to visit * @param other The other while loop to compare with * @returns The visited while loop, or undefined if the visit was aborted */ visitWhileLoop(whileLoop: J.WhileLoop, other: J): Promise; /** * Overrides the visitWildcard method to compare wildcards. * * @param wildcard The wildcard to visit * @param other The other wildcard to compare with * @returns The visited wildcard, or undefined if the visit was aborted */ visitWildcard(wildcard: J.Wildcard, other: J): Promise; /** * Overrides the visitYield method to compare yield statements. * * @param yieldStatement The yield statement to visit * @param other The other yield statement to compare with * @returns The visited yield statement, or undefined if the visit was aborted */ visitYield(yieldStatement: J.Yield, other: J): Promise; /** * Overrides the visitVoid method to compare void expressions. * * @param void_ The void expression to visit * @param other The other void expression to compare with * @returns The visited void expression, or undefined if the visit was aborted */ visitVoid(void_: JS.Void, other: J): Promise; /** * Overrides the visitWithStatement method to compare with statements. * * @param withStatement The with statement to visit * @param other The other with statement to compare with * @returns The visited with statement, or undefined if the visit was aborted */ visitWithStatement(withStatement: JS.WithStatement, other: J): Promise; /** * Overrides the visitIndexSignatureDeclaration method to compare index signature declarations. * * @param indexSignatureDeclaration The index signature declaration to visit * @param other The other index signature declaration to compare with * @returns The visited index signature declaration, or undefined if the visit was aborted */ visitIndexSignatureDeclaration(indexSignatureDeclaration: JS.IndexSignatureDeclaration, other: J): Promise; /** * Overrides the visitForOfLoop method to compare for-of loops. * * @param forOfLoop The for-of loop to visit * @param other The other for-of loop to compare with * @returns The visited for-of loop, or undefined if the visit was aborted */ visitForOfLoop(forOfLoop: JS.ForOfLoop, other: J): Promise; /** * Overrides the visitForInLoop method to compare for-in loops. * * @param forInLoop The for-in loop to visit * @param other The other for-in loop to compare with * @returns The visited for-in loop, or undefined if the visit was aborted */ visitForInLoop(forInLoop: JS.ForInLoop, other: J): Promise; /** * Overrides the visitNamespaceDeclaration method to compare namespace declarations. * * @param namespaceDeclaration The namespace declaration to visit * @param other The other namespace declaration to compare with * @returns The visited namespace declaration, or undefined if the visit was aborted */ visitNamespaceDeclaration(namespaceDeclaration: JS.NamespaceDeclaration, other: J): Promise; /** * Overrides the visitTypeLiteral method to compare type literals. * * @param typeLiteral The type literal to visit * @param other The other type literal to compare with * @returns The visited type literal, or undefined if the visit was aborted */ visitTypeLiteral(typeLiteral: JS.TypeLiteral, other: J): Promise; /** * Overrides the visitBindingElement method to compare binding elements. * * @param bindingElement The binding element to visit * @param other The other binding element to compare with * @returns The visited binding element, or undefined if the visit was aborted */ visitBindingElement(bindingElement: JS.BindingElement, other: J): Promise; /** * Overrides the visitArrayBindingPattern method to compare array binding patterns. * * @param arrayBindingPattern The array binding pattern to visit * @param other The other array binding pattern to compare with * @returns The visited array binding pattern, or undefined if the visit was aborted */ visitArrayBindingPattern(arrayBindingPattern: JS.ArrayBindingPattern, other: J): Promise; /** * Overrides the visitExportDeclaration method to compare export declarations. * * @param exportDeclaration The export declaration to visit * @param other The other export declaration to compare with * @returns The visited export declaration, or undefined if the visit was aborted */ visitExportDeclaration(exportDeclaration: JS.ExportDeclaration, other: J): Promise; /** * Overrides the visitExportAssignment method to compare export assignments. * * @param exportAssignment The export assignment to visit * @param other The other export assignment to compare with * @returns The visited export assignment, or undefined if the visit was aborted */ visitExportAssignment(exportAssignment: JS.ExportAssignment, other: J): Promise; /** * Overrides the visitNamedExports method to compare named exports. * * @param namedExports The named exports to visit * @param other The other named exports to compare with * @returns The visited named exports, or undefined if the visit was aborted */ visitNamedExports(namedExports: JS.NamedExports, other: J): Promise; /** * Overrides the visitExportSpecifier method to compare export specifiers. * * @param exportSpecifier The export specifier to visit * @param other The other export specifier to compare with * @returns The visited export specifier, or undefined if the visit was aborted */ visitExportSpecifier(exportSpecifier: JS.ExportSpecifier, other: J): Promise; /** * Overrides the visitComputedPropertyMethodDeclaration method to compare computed property method declarations. * * @param computedPropMethod The computed property method declaration to visit * @param other The other computed property method declaration to compare with * @returns The visited computed property method declaration, or undefined if the visit was aborted */ visitComputedPropertyMethodDeclaration(computedPropMethod: JS.ComputedPropertyMethodDeclaration, other: J): Promise; } /** * A comparator visitor that checks semantic equality including type attribution. * This ensures comparisons account for type information, allowing semantically * equivalent code to match even when structurally different (e.g., `foo()` vs `module.foo()` * when both refer to the same method). */ export declare class JavaScriptSemanticComparatorVisitor extends JavaScriptComparatorVisitor { /** * When true, allows patterns without type annotations to match code with type annotations. * This enables lenient matching where undefined types on either side are considered compatible. */ protected readonly lenientTypeMatching: boolean; /** * Creates a new semantic comparator visitor. * * @param lenientTypeMatching If true, allows matching between nodes with and without type annotations */ constructor(lenientTypeMatching?: boolean); /** * Unwraps parentheses from a tree node recursively. * This allows comparing expressions with and without redundant parentheses. * * @param tree The tree to unwrap * @returns The unwrapped tree */ protected unwrap(tree: Tree | undefined): Tree | undefined; visit(j: Tree, p: J, parent?: Cursor): Promise; /** * Override visitArrowFunction to allow semantic equivalence between expression body * and block with single return statement forms. * * Examples: * - `x => x + 1` matches `x => { return x + 1; }` * - `(x, y) => x + y` matches `(x, y) => { return x + y; }` */ visitArrowFunction(arrowFunction: JS.ArrowFunction, other: J): Promise; /** * Override visitLambdaParameters to allow semantic equivalence between * arrow functions with and without parentheses around single parameters. * * Examples: * - `x => x + 1` matches `(x) => x + 1` */ visitLambdaParameters(parameters: J.Lambda.Parameters, other: J): Promise; /** * Override visitPropertyAssignment to allow semantic equivalence between * object property shorthand and longhand forms. * * Examples: * - `{ x }` matches `{ x: x }` * - `{ x: x, y: y }` matches `{ x, y }` */ visitPropertyAssignment(propertyAssignment: JS.PropertyAssignment, other: J): Promise; /** * Extracts the property name from a PropertyAssignment. * Returns the simple name if the property is an identifier, undefined otherwise. */ private getPropertyName; /** * Checks if an expression is an identifier with the given name. */ private isIdentifierWithName; /** * Extracts the expression from an arrow function body. * Returns the expression if: * - body is already an Expression, OR * - body is a Block with exactly one Return statement * Otherwise returns undefined. */ private extractExpression; /** * Override visitProperty to allow lenient type matching. * When lenientTypeMatching is enabled, null vs Type comparisons are allowed * (where one value is null/undefined and the other is a Type object). */ protected visitProperty(j: any, other: any, propertyName?: string): Promise; /** * Checks if two types are semantically equal. * For method types, this checks that the declaring type and method name match. * With lenient type matching, undefined types on either side are considered compatible. */ private isOfType; /** * Override method invocation comparison to include type attribution checking. * When types match semantically, we allow matching even if one has a receiver * and the other doesn't (e.g., `isDate(x)` vs `util.isDate(x)`). */ visitMethodInvocation(method: J.MethodInvocation, other: J): Promise; /** * Override identifier comparison to include: * 1. Type checking for field access * 2. Semantic equivalence between `undefined` identifier and void expressions */ visitIdentifier(identifier: J.Identifier, other: J): Promise; /** * Override variable declarations comparison to handle lenient type matching. * When lenientTypeMatching is true, patterns without typeExpression can match * code with typeExpression. */ visitVariableDeclarations(variableDeclarations: J.VariableDeclarations, other: J): Promise; /** * Override method declaration comparison to handle lenient type matching. * When lenientTypeMatching is true, patterns without returnTypeExpression can match * code with returnTypeExpression. */ visitMethodDeclaration(methodDeclaration: J.MethodDeclaration, other: J): Promise; /** * Override visitVoid to allow semantic equivalence with undefined identifier. * This handles the reverse case where the pattern is a void expression * and the source is the undefined identifier. * * Examples: * - `void 0` matches `undefined` * - `void(0)` matches `undefined` * - `void 1` matches `undefined` */ visitVoid(voidExpr: JS.Void, other: J): Promise; /** * Override visitLiteral to allow semantic equivalence between * different numeric literal formats. * * Examples: * - `255` matches `0xFF` * - `255` matches `0o377` * - `255` matches `0b11111111` * - `1000` matches `1e3` */ visitLiteral(literal: J.Literal, other: J): Promise; } //# sourceMappingURL=comparator.d.ts.map