@openrewrite/rewrite 8.67.0-20251104-111121 → 8.67.0-20251104-114312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/javascript/comparator.d.ts +67 -4
  2. package/dist/javascript/comparator.d.ts.map +1 -1
  3. package/dist/javascript/comparator.js +523 -2794
  4. package/dist/javascript/comparator.js.map +1 -1
  5. package/dist/javascript/index.d.ts +1 -1
  6. package/dist/javascript/index.d.ts.map +1 -1
  7. package/dist/javascript/index.js +1 -1
  8. package/dist/javascript/index.js.map +1 -1
  9. package/dist/javascript/templating/capture.d.ts +226 -0
  10. package/dist/javascript/templating/capture.d.ts.map +1 -0
  11. package/dist/javascript/templating/capture.js +371 -0
  12. package/dist/javascript/templating/capture.js.map +1 -0
  13. package/dist/javascript/templating/comparator.d.ts +61 -0
  14. package/dist/javascript/templating/comparator.d.ts.map +1 -0
  15. package/dist/javascript/templating/comparator.js +393 -0
  16. package/dist/javascript/templating/comparator.js.map +1 -0
  17. package/dist/javascript/templating/engine.d.ts +75 -0
  18. package/dist/javascript/templating/engine.d.ts.map +1 -0
  19. package/dist/javascript/templating/engine.js +228 -0
  20. package/dist/javascript/templating/engine.js.map +1 -0
  21. package/dist/javascript/templating/index.d.ts +6 -0
  22. package/dist/javascript/templating/index.d.ts.map +1 -0
  23. package/dist/javascript/templating/index.js +42 -0
  24. package/dist/javascript/templating/index.js.map +1 -0
  25. package/dist/javascript/templating/pattern.d.ts +171 -0
  26. package/dist/javascript/templating/pattern.d.ts.map +1 -0
  27. package/dist/javascript/templating/pattern.js +681 -0
  28. package/dist/javascript/templating/pattern.js.map +1 -0
  29. package/dist/javascript/templating/placeholder-replacement.d.ts +58 -0
  30. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
  31. package/dist/javascript/templating/placeholder-replacement.js +365 -0
  32. package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
  33. package/dist/javascript/templating/rewrite.d.ts +39 -0
  34. package/dist/javascript/templating/rewrite.d.ts.map +1 -0
  35. package/dist/javascript/templating/rewrite.js +81 -0
  36. package/dist/javascript/templating/rewrite.js.map +1 -0
  37. package/dist/javascript/templating/template.d.ts +204 -0
  38. package/dist/javascript/templating/template.d.ts.map +1 -0
  39. package/dist/javascript/templating/template.js +293 -0
  40. package/dist/javascript/templating/template.js.map +1 -0
  41. package/dist/javascript/templating/types.d.ts +263 -0
  42. package/dist/javascript/templating/types.d.ts.map +1 -0
  43. package/dist/javascript/templating/types.js +3 -0
  44. package/dist/javascript/templating/types.js.map +1 -0
  45. package/dist/javascript/templating/utils.d.ts +118 -0
  46. package/dist/javascript/templating/utils.d.ts.map +1 -0
  47. package/dist/javascript/templating/utils.js +253 -0
  48. package/dist/javascript/templating/utils.js.map +1 -0
  49. package/dist/version.txt +1 -1
  50. package/package.json +2 -1
  51. package/src/javascript/comparator.ts +554 -3323
  52. package/src/javascript/index.ts +1 -1
  53. package/src/javascript/templating/capture.ts +503 -0
  54. package/src/javascript/templating/comparator.ts +430 -0
  55. package/src/javascript/templating/engine.ts +252 -0
  56. package/src/javascript/templating/index.ts +60 -0
  57. package/src/javascript/templating/pattern.ts +727 -0
  58. package/src/javascript/templating/placeholder-replacement.ts +372 -0
  59. package/src/javascript/templating/rewrite.ts +95 -0
  60. package/src/javascript/templating/template.ts +326 -0
  61. package/src/javascript/templating/types.ts +300 -0
  62. package/src/javascript/templating/utils.ts +284 -0
  63. package/dist/javascript/templating.d.ts +0 -265
  64. package/dist/javascript/templating.d.ts.map +0 -1
  65. package/dist/javascript/templating.js +0 -1027
  66. package/dist/javascript/templating.js.map +0 -1
  67. package/src/javascript/templating.ts +0 -1226
@@ -27,18 +27,15 @@ exports.JavaScriptSemanticComparatorVisitor = exports.JavaScriptComparatorVisito
27
27
  */
28
28
  const visitor_1 = require("./visitor");
29
29
  const java_1 = require("../java");
30
- const tree_1 = require("./tree");
30
+ const tree_1 = require("../tree");
31
31
  /**
32
32
  * A visitor that compares two AST trees in lock step.
33
33
  * It takes another `J` instance as context and visits both trees simultaneously.
34
34
  * The visit operation is aborted when the nodes don't match.
35
35
  */
36
36
  class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
37
- /**
38
- * Creates a new comparator visitor.
39
- */
40
37
  constructor() {
41
- super();
38
+ super(...arguments);
42
39
  /**
43
40
  * Flag indicating whether the trees match so far
44
41
  */
@@ -75,6 +72,102 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
75
72
  this.match = false;
76
73
  return t;
77
74
  }
75
+ /**
76
+ * Generic method to visit a property value using the appropriate visitor method.
77
+ * This ensures wrappers (RightPadded, LeftPadded, Container) are properly tracked on the cursor.
78
+ *
79
+ * @param j The property value from the first tree
80
+ * @param other The corresponding property value from the second tree
81
+ * @returns The visited property value from the first tree
82
+ */
83
+ visitProperty(j, other) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ // Handle null/undefined (but not other falsy values like 0, false, '')
86
+ if (j == null || other == null) {
87
+ if (j !== other) {
88
+ this.abort(j);
89
+ }
90
+ return j;
91
+ }
92
+ const kind = j.kind;
93
+ // Check wrappers by kind
94
+ if (kind === java_1.J.Kind.RightPadded) {
95
+ return yield this.visitRightPadded(j, other);
96
+ }
97
+ if (kind === java_1.J.Kind.LeftPadded) {
98
+ return yield this.visitLeftPadded(j, other);
99
+ }
100
+ if (kind === java_1.J.Kind.Container) {
101
+ return yield this.visitContainer(j, other);
102
+ }
103
+ // Check if it's a Space (skip comparison)
104
+ if (kind === java_1.J.Kind.Space) {
105
+ return j;
106
+ }
107
+ // Check if it's a Tree node (has a kind property with a string value)
108
+ if (kind !== undefined && typeof kind === 'string') {
109
+ // Check if it's a Type node (starts with "org.openrewrite.java.tree.JavaType$")
110
+ if (kind.startsWith('org.openrewrite.java.tree.JavaType$')) {
111
+ return yield this.visitType(j, other);
112
+ }
113
+ return yield this.visit(j, other);
114
+ }
115
+ // For primitive values, compare directly
116
+ if (j !== other) {
117
+ this.abort(j);
118
+ }
119
+ return j;
120
+ });
121
+ }
122
+ /**
123
+ * Generic method to visit all properties of an element, calling visitProperty for each.
124
+ * This automatically handles wrappers and ensures proper cursor tracking.
125
+ * Also checks that both elements have the same kind.
126
+ *
127
+ * @param j The element from the first tree
128
+ * @param other The corresponding element from the second tree
129
+ * @returns The visited element from the first tree
130
+ */
131
+ visitElement(j, other) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ if (!this.match) {
134
+ return j;
135
+ }
136
+ // Check if kinds match
137
+ if (j.kind !== other.kind) {
138
+ return this.abort(j);
139
+ }
140
+ // Iterate over all properties
141
+ for (const key of Object.keys(j)) {
142
+ // Skip internal/private properties, id property, and markers property
143
+ if (key.startsWith('_') || key === 'id' || key === 'markers') {
144
+ continue;
145
+ }
146
+ const jValue = j[key];
147
+ const otherValue = other[key];
148
+ // Handle arrays - compare element by element
149
+ if (Array.isArray(jValue)) {
150
+ if (!Array.isArray(otherValue) || jValue.length !== otherValue.length) {
151
+ return this.abort(j);
152
+ }
153
+ for (let i = 0; i < jValue.length; i++) {
154
+ yield this.visitProperty(jValue[i], otherValue[i]);
155
+ if (!this.match) {
156
+ return j;
157
+ }
158
+ }
159
+ }
160
+ else {
161
+ // Visit the property (which will handle wrappers, trees, primitives, etc.)
162
+ yield this.visitProperty(jValue, otherValue);
163
+ if (!this.match) {
164
+ return j;
165
+ }
166
+ }
167
+ }
168
+ return j;
169
+ });
170
+ }
78
171
  visit(j, p, parent) {
79
172
  const _super = Object.create(null, {
80
173
  visit: { get: () => super.visit }
@@ -92,6 +185,93 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
92
185
  return _super.visit.call(this, j, p);
93
186
  });
94
187
  }
188
+ /**
189
+ * Override visitRightPadded to compare only the elements, not markers or spacing.
190
+ * The context parameter p contains the corresponding element from the other tree.
191
+ * Pushes the wrapper onto the cursor stack so captures can access it.
192
+ */
193
+ visitRightPadded(right, p) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ if (!this.match) {
196
+ return right;
197
+ }
198
+ // Extract the other element if it's also a RightPadded
199
+ const otherElement = p.kind === java_1.J.Kind.RightPadded
200
+ ? p.element
201
+ : p;
202
+ // Push wrapper onto cursor, then compare only the elements, not markers or spacing
203
+ const savedCursor = this.cursor;
204
+ this.cursor = new tree_1.Cursor(right, this.cursor);
205
+ try {
206
+ yield this.visitProperty(right.element, otherElement);
207
+ }
208
+ finally {
209
+ this.cursor = savedCursor;
210
+ }
211
+ return right;
212
+ });
213
+ }
214
+ /**
215
+ * Override visitLeftPadded to compare only the elements, not markers or spacing.
216
+ * The context parameter p contains the corresponding element from the other tree.
217
+ * Pushes the wrapper onto the cursor stack so captures can access it.
218
+ */
219
+ visitLeftPadded(left, p) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ if (!this.match) {
222
+ return left;
223
+ }
224
+ // Extract the other element if it's also a LeftPadded
225
+ const otherElement = p.kind === java_1.J.Kind.LeftPadded
226
+ ? p.element
227
+ : p;
228
+ // Push wrapper onto cursor, then compare only the elements, not markers or spacing
229
+ const savedCursor = this.cursor;
230
+ this.cursor = new tree_1.Cursor(left, this.cursor);
231
+ try {
232
+ yield this.visitProperty(left.element, otherElement);
233
+ }
234
+ finally {
235
+ this.cursor = savedCursor;
236
+ }
237
+ return left;
238
+ });
239
+ }
240
+ /**
241
+ * Override visitContainer to compare only the elements, not markers or spacing.
242
+ * The context parameter p contains the corresponding element from the other tree.
243
+ * Pushes the wrapper onto the cursor stack so captures can access it.
244
+ */
245
+ visitContainer(container, p) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ if (!this.match) {
248
+ return container;
249
+ }
250
+ // Extract the other elements if it's also a Container
251
+ const otherElements = p.kind === java_1.J.Kind.Container
252
+ ? p.elements
253
+ : p;
254
+ // Compare elements array length
255
+ if (container.elements.length !== otherElements.length) {
256
+ return this.abort(container);
257
+ }
258
+ // Push wrapper onto cursor, then compare each element
259
+ const savedCursor = this.cursor;
260
+ this.cursor = new tree_1.Cursor(container, this.cursor);
261
+ try {
262
+ for (let i = 0; i < container.elements.length; i++) {
263
+ yield this.visitProperty(container.elements[i], otherElements[i]);
264
+ if (!this.match) {
265
+ return this.abort(container);
266
+ }
267
+ }
268
+ }
269
+ finally {
270
+ this.cursor = savedCursor;
271
+ }
272
+ return container;
273
+ });
274
+ }
95
275
  /**
96
276
  * Overrides the visitBinary method to compare binary expressions.
97
277
  *
@@ -101,19 +281,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
101
281
  */
102
282
  visitBinary(binary, other) {
103
283
  return __awaiter(this, void 0, void 0, function* () {
104
- if (!this.match || other.kind !== java_1.J.Kind.Binary) {
105
- return this.abort(binary);
106
- }
107
- const otherBinary = other;
108
- if (binary.operator.element !== otherBinary.operator.element) {
109
- return this.abort(binary);
110
- }
111
- // Visit left and right operands in lock step
112
- yield this.visit(binary.left, otherBinary.left);
113
- if (!this.match)
114
- return this.abort(binary);
115
- yield this.visit(binary.right, otherBinary.right);
116
- return binary;
284
+ return this.visitElement(binary, other);
117
285
  });
118
286
  }
119
287
  /**
@@ -125,14 +293,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
125
293
  */
126
294
  visitIdentifier(identifier, other) {
127
295
  return __awaiter(this, void 0, void 0, function* () {
128
- if (!this.match || other.kind !== java_1.J.Kind.Identifier) {
129
- return this.abort(identifier);
130
- }
131
- const otherIdentifier = other;
132
- if (identifier.simpleName !== otherIdentifier.simpleName) {
133
- return this.abort(identifier);
134
- }
135
- return identifier;
296
+ return this.visitElement(identifier, other);
136
297
  });
137
298
  }
138
299
  /**
@@ -144,14 +305,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
144
305
  */
145
306
  visitLiteral(literal, other) {
146
307
  return __awaiter(this, void 0, void 0, function* () {
147
- if (!this.match || other.kind !== java_1.J.Kind.Literal) {
148
- return this.abort(literal);
149
- }
150
- const otherLiteral = other;
151
- if (literal.valueSource !== otherLiteral.valueSource) {
152
- return this.abort(literal);
153
- }
154
- return literal;
308
+ return this.visitElement(literal, other);
155
309
  });
156
310
  }
157
311
  /**
@@ -163,21 +317,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
163
317
  */
164
318
  visitBlock(block, other) {
165
319
  return __awaiter(this, void 0, void 0, function* () {
166
- if (!this.match || other.kind !== java_1.J.Kind.Block) {
167
- return this.abort(block);
168
- }
169
- const otherBlock = other;
170
- if (block.statements.length !== otherBlock.statements.length) {
171
- return this.abort(block);
172
- }
173
- // Visit each statement in lock step
174
- for (let i = 0; i < block.statements.length; i++) {
175
- yield this.visit(block.statements[i].element, otherBlock.statements[i].element);
176
- if (!this.match) {
177
- return this.abort(block);
178
- }
179
- }
180
- return block;
320
+ return this.visitElement(block, other);
181
321
  });
182
322
  }
183
323
  /**
@@ -189,21 +329,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
189
329
  */
190
330
  visitJsCompilationUnit(compilationUnit, other) {
191
331
  return __awaiter(this, void 0, void 0, function* () {
192
- if (!this.match || other.kind !== tree_1.JS.Kind.CompilationUnit) {
193
- return this.abort(compilationUnit);
194
- }
195
- const otherCompilationUnit = other;
196
- if (compilationUnit.statements.length !== otherCompilationUnit.statements.length) {
197
- return this.abort(compilationUnit);
198
- }
199
- // Visit each statement in lock step
200
- for (let i = 0; i < compilationUnit.statements.length; i++) {
201
- yield this.visit(compilationUnit.statements[i].element, otherCompilationUnit.statements[i].element);
202
- if (!this.match) {
203
- return this.abort(compilationUnit);
204
- }
205
- }
206
- return compilationUnit;
332
+ return this.visitElement(compilationUnit, other);
207
333
  });
208
334
  }
209
335
  /**
@@ -215,17 +341,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
215
341
  */
216
342
  visitAlias(alias, other) {
217
343
  return __awaiter(this, void 0, void 0, function* () {
218
- if (!this.match || other.kind !== tree_1.JS.Kind.Alias) {
219
- return this.abort(alias);
220
- }
221
- const otherAlias = other;
222
- // Visit property name and alias in lock step
223
- yield this.visit(alias.propertyName.element, otherAlias.propertyName.element);
224
- if (!this.match) {
225
- return this.abort(alias);
226
- }
227
- yield this.visit(alias.alias, otherAlias.alias);
228
- return alias;
344
+ return this.visitElement(alias, other);
229
345
  });
230
346
  }
231
347
  /**
@@ -237,41 +353,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
237
353
  */
238
354
  visitArrowFunction(arrowFunction, other) {
239
355
  return __awaiter(this, void 0, void 0, function* () {
240
- if (!this.match || other.kind !== tree_1.JS.Kind.ArrowFunction) {
241
- return this.abort(arrowFunction);
242
- }
243
- const otherArrowFunction = other;
244
- // Compare modifiers
245
- if (arrowFunction.modifiers.length !== otherArrowFunction.modifiers.length) {
246
- return this.abort(arrowFunction);
247
- }
248
- // Visit modifiers in lock step
249
- for (let i = 0; i < arrowFunction.modifiers.length; i++) {
250
- yield this.visit(arrowFunction.modifiers[i], otherArrowFunction.modifiers[i]);
251
- if (!this.match)
252
- return arrowFunction;
253
- }
254
- // Visit type parameters if present
255
- if (!!arrowFunction.typeParameters !== !!otherArrowFunction.typeParameters) {
256
- return this.abort(arrowFunction);
257
- }
258
- if (arrowFunction.typeParameters) {
259
- yield this.visit(arrowFunction.typeParameters, otherArrowFunction.typeParameters);
260
- if (!this.match)
261
- return arrowFunction;
262
- }
263
- // Visit lambda
264
- yield this.visit(arrowFunction.lambda, otherArrowFunction.lambda);
265
- if (!this.match)
266
- return arrowFunction;
267
- // Visit return type expression if present
268
- if (!!arrowFunction.returnTypeExpression !== !!otherArrowFunction.returnTypeExpression) {
269
- return this.abort(arrowFunction);
270
- }
271
- if (arrowFunction.returnTypeExpression) {
272
- yield this.visit(arrowFunction.returnTypeExpression, otherArrowFunction.returnTypeExpression);
273
- }
274
- return arrowFunction;
356
+ return this.visitElement(arrowFunction, other);
275
357
  });
276
358
  }
277
359
  /**
@@ -283,13 +365,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
283
365
  */
284
366
  visitAwait(await_, other) {
285
367
  return __awaiter(this, void 0, void 0, function* () {
286
- if (!this.match || other.kind !== tree_1.JS.Kind.Await) {
287
- return this.abort(await_);
288
- }
289
- const otherAwait = other;
290
- // Visit expression
291
- yield this.visit(await_.expression, otherAwait.expression);
292
- return await_;
368
+ return this.visitElement(await_, other);
293
369
  });
294
370
  }
295
371
  /**
@@ -301,51 +377,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
301
377
  */
302
378
  visitJsxTag(element, other) {
303
379
  return __awaiter(this, void 0, void 0, function* () {
304
- if (!this.match || other.kind !== tree_1.JS.Kind.JsxTag) {
305
- return this.abort(element);
306
- }
307
- const otherElement = other;
308
- // Visit open name
309
- yield this.visit(element.openName.element, otherElement.openName.element);
310
- if (!this.match)
311
- return element;
312
- // Compare attributes
313
- if (element.attributes.length !== otherElement.attributes.length) {
314
- return this.abort(element);
315
- }
316
- // Visit attributes in lock step
317
- for (let i = 0; i < element.attributes.length; i++) {
318
- yield this.visit(element.attributes[i].element, otherElement.attributes[i].element);
319
- if (!this.match)
320
- return element;
321
- }
322
- // Compare self-closing
323
- if (!!element.selfClosing !== !!otherElement.selfClosing) {
324
- return this.abort(element);
325
- }
326
- // Compare children
327
- if (!!element.children !== !!otherElement.children) {
328
- return this.abort(element);
329
- }
330
- if (element.children) {
331
- if (element.children.length !== otherElement.children.length) {
332
- return this.abort(element);
333
- }
334
- // Visit children in lock step
335
- for (let i = 0; i < element.children.length; i++) {
336
- yield this.visit(element.children[i], otherElement.children[i]);
337
- if (!this.match)
338
- return element;
339
- }
340
- }
341
- // Compare closing name
342
- if (!!element.closingName !== !!otherElement.closingName) {
343
- return this.abort(element);
344
- }
345
- if (element.closingName) {
346
- yield this.visit(element.closingName.element, otherElement.closingName.element);
347
- }
348
- return element;
380
+ return this.visitElement(element, other);
349
381
  });
350
382
  }
351
383
  /**
@@ -357,22 +389,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
357
389
  */
358
390
  visitJsxAttribute(attribute, other) {
359
391
  return __awaiter(this, void 0, void 0, function* () {
360
- if (!this.match || other.kind !== tree_1.JS.Kind.JsxAttribute) {
361
- return this.abort(attribute);
362
- }
363
- const otherAttribute = other;
364
- // Visit key
365
- yield this.visit(attribute.key, otherAttribute.key);
366
- if (!this.match)
367
- return attribute;
368
- // Compare value
369
- if (!!attribute.value !== !!otherAttribute.value) {
370
- return this.abort(attribute);
371
- }
372
- if (attribute.value) {
373
- yield this.visit(attribute.value.element, otherAttribute.value.element);
374
- }
375
- return attribute;
392
+ return this.visitElement(attribute, other);
376
393
  });
377
394
  }
378
395
  /**
@@ -384,13 +401,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
384
401
  */
385
402
  visitJsxSpreadAttribute(spread, other) {
386
403
  return __awaiter(this, void 0, void 0, function* () {
387
- if (!this.match || other.kind !== tree_1.JS.Kind.JsxSpreadAttribute) {
388
- return this.abort(spread);
389
- }
390
- const otherSpread = other;
391
- // Visit expression
392
- yield this.visit(spread.expression.element, otherSpread.expression.element);
393
- return spread;
404
+ return this.visitElement(spread, other);
394
405
  });
395
406
  }
396
407
  /**
@@ -402,13 +413,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
402
413
  */
403
414
  visitJsxEmbeddedExpression(expr, other) {
404
415
  return __awaiter(this, void 0, void 0, function* () {
405
- if (!this.match || other.kind !== tree_1.JS.Kind.JsxEmbeddedExpression) {
406
- return this.abort(expr);
407
- }
408
- const otherExpr = other;
409
- // Visit expression
410
- yield this.visit(expr.expression.element, otherExpr.expression.element);
411
- return expr;
416
+ return this.visitElement(expr, other);
412
417
  });
413
418
  }
414
419
  /**
@@ -420,17 +425,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
420
425
  */
421
426
  visitJsxNamespacedName(ns, other) {
422
427
  return __awaiter(this, void 0, void 0, function* () {
423
- if (!this.match || other.kind !== tree_1.JS.Kind.JsxNamespacedName) {
424
- return this.abort(ns);
425
- }
426
- const otherNs = other;
427
- // Visit namespace
428
- yield this.visit(ns.namespace, otherNs.namespace);
429
- if (!this.match)
430
- return ns;
431
- // Visit name
432
- yield this.visit(ns.name.element, otherNs.name.element);
433
- return ns;
428
+ return this.visitElement(ns, other);
434
429
  });
435
430
  }
436
431
  /**
@@ -442,17 +437,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
442
437
  */
443
438
  visitConditionalType(conditionalType, other) {
444
439
  return __awaiter(this, void 0, void 0, function* () {
445
- if (!this.match || other.kind !== tree_1.JS.Kind.ConditionalType) {
446
- return this.abort(conditionalType);
447
- }
448
- const otherConditionalType = other;
449
- // Visit check type
450
- yield this.visit(conditionalType.checkType, otherConditionalType.checkType);
451
- if (!this.match)
452
- return conditionalType;
453
- // Visit condition
454
- yield this.visit(conditionalType.condition.element, otherConditionalType.condition.element);
455
- return conditionalType;
440
+ return this.visitElement(conditionalType, other);
456
441
  });
457
442
  }
458
443
  /**
@@ -464,13 +449,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
464
449
  */
465
450
  visitDelete(delete_, other) {
466
451
  return __awaiter(this, void 0, void 0, function* () {
467
- if (!this.match || other.kind !== tree_1.JS.Kind.Delete) {
468
- return this.abort(delete_);
469
- }
470
- const otherDelete = other;
471
- // Visit expression
472
- yield this.visit(delete_.expression, otherDelete.expression);
473
- return delete_;
452
+ return this.visitElement(delete_, other);
474
453
  });
475
454
  }
476
455
  /**
@@ -482,13 +461,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
482
461
  */
483
462
  visitExpressionStatement(expressionStatement, other) {
484
463
  return __awaiter(this, void 0, void 0, function* () {
485
- if (!this.match || other.kind !== tree_1.JS.Kind.ExpressionStatement) {
486
- return this.abort(expressionStatement);
487
- }
488
- const otherExpressionStatement = other;
489
- // Visit expression
490
- yield this.visit(expressionStatement.expression, otherExpressionStatement.expression);
491
- return expressionStatement;
464
+ return this.visitElement(expressionStatement, other);
492
465
  });
493
466
  }
494
467
  /**
@@ -500,30 +473,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
500
473
  */
501
474
  visitExpressionWithTypeArguments(expressionWithTypeArguments, other) {
502
475
  return __awaiter(this, void 0, void 0, function* () {
503
- if (!this.match || other.kind !== tree_1.JS.Kind.ExpressionWithTypeArguments) {
504
- return this.abort(expressionWithTypeArguments);
505
- }
506
- const otherExpressionWithTypeArguments = other;
507
- // Visit class
508
- yield this.visit(expressionWithTypeArguments.clazz, otherExpressionWithTypeArguments.clazz);
509
- if (!this.match)
510
- return expressionWithTypeArguments;
511
- // Compare type arguments
512
- if (!!expressionWithTypeArguments.typeArguments !== !!otherExpressionWithTypeArguments.typeArguments) {
513
- return this.abort(expressionWithTypeArguments);
514
- }
515
- if (expressionWithTypeArguments.typeArguments) {
516
- if (expressionWithTypeArguments.typeArguments.elements.length !== otherExpressionWithTypeArguments.typeArguments.elements.length) {
517
- return this.abort(expressionWithTypeArguments);
518
- }
519
- // Visit type arguments in lock step
520
- for (let i = 0; i < expressionWithTypeArguments.typeArguments.elements.length; i++) {
521
- yield this.visit(expressionWithTypeArguments.typeArguments.elements[i].element, otherExpressionWithTypeArguments.typeArguments.elements[i].element);
522
- if (!this.match)
523
- return expressionWithTypeArguments;
524
- }
525
- }
526
- return expressionWithTypeArguments;
476
+ return this.visitElement(expressionWithTypeArguments, other);
527
477
  });
528
478
  }
529
479
  /**
@@ -535,47 +485,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
535
485
  */
536
486
  visitFunctionCall(functionCall, other) {
537
487
  return __awaiter(this, void 0, void 0, function* () {
538
- if (!this.match || other.kind !== tree_1.JS.Kind.FunctionCall) {
539
- return this.abort(functionCall);
540
- }
541
- const otherFunctionCall = other;
542
- // Compare function
543
- if ((functionCall.function === undefined) !== (otherFunctionCall.function === undefined)) {
544
- return this.abort(functionCall);
545
- }
546
- // Visit function if present
547
- if (functionCall.function && otherFunctionCall.function) {
548
- yield this.visit(functionCall.function.element, otherFunctionCall.function.element);
549
- if (!this.match)
550
- return functionCall;
551
- }
552
- // Compare typeParameters
553
- if ((functionCall.typeParameters === undefined) !== (otherFunctionCall.typeParameters === undefined)) {
554
- return this.abort(functionCall);
555
- }
556
- // Visit typeParameters if present
557
- if (functionCall.typeParameters && otherFunctionCall.typeParameters) {
558
- if (functionCall.typeParameters.elements.length !== otherFunctionCall.typeParameters.elements.length) {
559
- return this.abort(functionCall);
560
- }
561
- // Visit each type parameter in lock step
562
- for (let i = 0; i < functionCall.typeParameters.elements.length; i++) {
563
- yield this.visit(functionCall.typeParameters.elements[i].element, otherFunctionCall.typeParameters.elements[i].element);
564
- if (!this.match)
565
- return functionCall;
566
- }
567
- }
568
- // Compare arguments
569
- if (functionCall.arguments.elements.length !== otherFunctionCall.arguments.elements.length) {
570
- return this.abort(functionCall);
571
- }
572
- // Visit each argument in lock step
573
- for (let i = 0; i < functionCall.arguments.elements.length; i++) {
574
- yield this.visit(functionCall.arguments.elements[i].element, otherFunctionCall.arguments.elements[i].element);
575
- if (!this.match)
576
- return functionCall;
577
- }
578
- return functionCall;
488
+ return this.visitElement(functionCall, other);
579
489
  });
580
490
  }
581
491
  /**
@@ -587,41 +497,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
587
497
  */
588
498
  visitFunctionType(functionType, other) {
589
499
  return __awaiter(this, void 0, void 0, function* () {
590
- if (!this.match || other.kind !== tree_1.JS.Kind.FunctionType) {
591
- return this.abort(functionType);
592
- }
593
- const otherFunctionType = other;
594
- // Compare constructor type
595
- if (!!functionType.constructorType.element !== !!otherFunctionType.constructorType.element) {
596
- return this.abort(functionType);
597
- }
598
- if (functionType.constructorType.element) {
599
- if (functionType.constructorType.element !== otherFunctionType.constructorType.element) {
600
- return this.abort(functionType);
601
- }
602
- }
603
- // Compare type parameters
604
- if (!!functionType.typeParameters !== !!otherFunctionType.typeParameters) {
605
- return this.abort(functionType);
606
- }
607
- if (functionType.typeParameters) {
608
- yield this.visit(functionType.typeParameters, otherFunctionType.typeParameters);
609
- if (!this.match)
610
- return functionType;
611
- }
612
- // Compare parameters
613
- if (functionType.parameters.elements.length !== otherFunctionType.parameters.elements.length) {
614
- return this.abort(functionType);
615
- }
616
- // Visit parameters in lock step
617
- for (let i = 0; i < functionType.parameters.elements.length; i++) {
618
- yield this.visit(functionType.parameters.elements[i].element, otherFunctionType.parameters.elements[i].element);
619
- if (!this.match)
620
- return functionType;
621
- }
622
- // Compare return type
623
- yield this.visit(functionType.returnType.element, otherFunctionType.returnType.element);
624
- return functionType;
500
+ return this.visitElement(functionType, other);
625
501
  });
626
502
  }
627
503
  /**
@@ -633,13 +509,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
633
509
  */
634
510
  visitInferType(inferType, other) {
635
511
  return __awaiter(this, void 0, void 0, function* () {
636
- if (!this.match || other.kind !== tree_1.JS.Kind.InferType) {
637
- return this.abort(inferType);
638
- }
639
- const otherInferType = other;
640
- // Visit type parameter
641
- yield this.visit(inferType.typeParameter.element, otherInferType.typeParameter.element);
642
- return inferType;
512
+ return this.visitElement(inferType, other);
643
513
  });
644
514
  }
645
515
  /**
@@ -651,49 +521,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
651
521
  */
652
522
  visitImportType(importType, other) {
653
523
  return __awaiter(this, void 0, void 0, function* () {
654
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportType) {
655
- return this.abort(importType);
656
- }
657
- const otherImportType = other;
658
- // Compare has typeof
659
- if (importType.hasTypeof.element !== otherImportType.hasTypeof.element) {
660
- return this.abort(importType);
661
- }
662
- // Compare argument and attributes
663
- if (importType.argumentAndAttributes.elements.length !== otherImportType.argumentAndAttributes.elements.length) {
664
- return this.abort(importType);
665
- }
666
- // Visit argument and attributes in lock step
667
- for (let i = 0; i < importType.argumentAndAttributes.elements.length; i++) {
668
- yield this.visit(importType.argumentAndAttributes.elements[i].element, otherImportType.argumentAndAttributes.elements[i].element);
669
- if (!this.match)
670
- return importType;
671
- }
672
- // Compare qualifier
673
- if (!!importType.qualifier !== !!otherImportType.qualifier) {
674
- return this.abort(importType);
675
- }
676
- if (importType.qualifier) {
677
- yield this.visit(importType.qualifier.element, otherImportType.qualifier.element);
678
- if (!this.match)
679
- return importType;
680
- }
681
- // Compare type arguments
682
- if (!!importType.typeArguments !== !!otherImportType.typeArguments) {
683
- return this.abort(importType);
684
- }
685
- if (importType.typeArguments) {
686
- if (importType.typeArguments.elements.length !== otherImportType.typeArguments.elements.length) {
687
- return this.abort(importType);
688
- }
689
- // Visit type arguments in lock step
690
- for (let i = 0; i < importType.typeArguments.elements.length; i++) {
691
- yield this.visit(importType.typeArguments.elements[i].element, otherImportType.typeArguments.elements[i].element);
692
- if (!this.match)
693
- return importType;
694
- }
695
- }
696
- return importType;
524
+ return this.visitElement(importType, other);
697
525
  });
698
526
  }
699
527
  /**
@@ -705,49 +533,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
705
533
  */
706
534
  visitImportDeclaration(jsImport, other) {
707
535
  return __awaiter(this, void 0, void 0, function* () {
708
- if (!this.match || other.kind !== tree_1.JS.Kind.Import) {
709
- return this.abort(jsImport);
710
- }
711
- const otherImport = other;
712
- // Compare modifiers
713
- if (jsImport.modifiers.length !== otherImport.modifiers.length) {
714
- return this.abort(jsImport);
715
- }
716
- // Visit each modifier in lock step
717
- for (let i = 0; i < jsImport.modifiers.length; i++) {
718
- yield this.visit(jsImport.modifiers[i], otherImport.modifiers[i]);
719
- if (!this.match)
720
- return jsImport;
721
- }
722
- // Compare import clause
723
- if (!!jsImport.importClause !== !!otherImport.importClause) {
724
- return this.abort(jsImport);
725
- }
726
- if (jsImport.importClause) {
727
- yield this.visit(jsImport.importClause, otherImport.importClause);
728
- if (!this.match)
729
- return jsImport;
730
- }
731
- // Visit module specifier
732
- if (jsImport.moduleSpecifier) {
733
- yield this.visit(jsImport.moduleSpecifier.element, otherImport.moduleSpecifier.element);
734
- if (!this.match)
735
- return jsImport;
736
- }
737
- // Compare attributes
738
- if (!!jsImport.attributes !== !!otherImport.attributes) {
739
- return this.abort(jsImport);
740
- }
741
- if (jsImport.attributes) {
742
- yield this.visit(jsImport.attributes, otherImport.attributes);
743
- }
744
- // Compare initializer
745
- if (jsImport.initializer) {
746
- yield this.visit(jsImport.initializer.element, otherImport.initializer.element);
747
- if (!this.match)
748
- return jsImport;
749
- }
750
- return jsImport;
536
+ return this.visitElement(jsImport, other);
751
537
  });
752
538
  }
753
539
  /**
@@ -759,27 +545,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
759
545
  */
760
546
  visitImportClause(importClause, other) {
761
547
  return __awaiter(this, void 0, void 0, function* () {
762
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportClause) {
763
- return this.abort(importClause);
764
- }
765
- const otherImportClause = other;
766
- // Compare name
767
- if (!!importClause.name !== !!otherImportClause.name) {
768
- return this.abort(importClause);
769
- }
770
- if (importClause.name) {
771
- yield this.visit(importClause.name.element, otherImportClause.name.element);
772
- if (!this.match)
773
- return importClause;
774
- }
775
- // Compare named bindings
776
- if (!!importClause.namedBindings !== !!otherImportClause.namedBindings) {
777
- return this.abort(importClause);
778
- }
779
- if (importClause.namedBindings) {
780
- yield this.visit(importClause.namedBindings, otherImportClause.namedBindings);
781
- }
782
- return importClause;
548
+ return this.visitElement(importClause, other);
783
549
  });
784
550
  }
785
551
  /**
@@ -791,21 +557,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
791
557
  */
792
558
  visitNamedImports(namedImports, other) {
793
559
  return __awaiter(this, void 0, void 0, function* () {
794
- if (!this.match || other.kind !== tree_1.JS.Kind.NamedImports) {
795
- return this.abort(namedImports);
796
- }
797
- const otherNamedImports = other;
798
- // Compare elements
799
- if (namedImports.elements.elements.length !== otherNamedImports.elements.elements.length) {
800
- return this.abort(namedImports);
801
- }
802
- // Visit elements in lock step
803
- for (let i = 0; i < namedImports.elements.elements.length; i++) {
804
- yield this.visit(namedImports.elements.elements[i].element, otherNamedImports.elements.elements[i].element);
805
- if (!this.match)
806
- return namedImports;
807
- }
808
- return namedImports;
560
+ return this.visitElement(namedImports, other);
809
561
  });
810
562
  }
811
563
  /**
@@ -817,22 +569,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
817
569
  */
818
570
  visitImportSpecifier(importSpecifier, other) {
819
571
  return __awaiter(this, void 0, void 0, function* () {
820
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportSpecifier) {
821
- return this.abort(importSpecifier);
822
- }
823
- const otherImportSpecifier = other;
824
- // Compare import type
825
- if (!!importSpecifier.importType.element !== !!otherImportSpecifier.importType.element) {
826
- return this.abort(importSpecifier);
827
- }
828
- if (importSpecifier.importType.element) {
829
- if (importSpecifier.importType.element !== otherImportSpecifier.importType.element) {
830
- return this.abort(importSpecifier);
831
- }
832
- }
833
- // Visit specifier
834
- yield this.visit(importSpecifier.specifier, otherImportSpecifier.specifier);
835
- return importSpecifier;
572
+ return this.visitElement(importSpecifier, other);
836
573
  });
837
574
  }
838
575
  /**
@@ -844,21 +581,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
844
581
  */
845
582
  visitImportAttributes(importAttributes, other) {
846
583
  return __awaiter(this, void 0, void 0, function* () {
847
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportAttributes) {
848
- return this.abort(importAttributes);
849
- }
850
- const otherImportAttributes = other;
851
- // Compare elements
852
- if (importAttributes.elements.elements.length !== otherImportAttributes.elements.elements.length) {
853
- return this.abort(importAttributes);
854
- }
855
- // Visit elements in lock step
856
- for (let i = 0; i < importAttributes.elements.elements.length; i++) {
857
- yield this.visit(importAttributes.elements.elements[i].element, otherImportAttributes.elements.elements[i].element);
858
- if (!this.match)
859
- return importAttributes;
860
- }
861
- return importAttributes;
584
+ return this.visitElement(importAttributes, other);
862
585
  });
863
586
  }
864
587
  /**
@@ -870,25 +593,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
870
593
  */
871
594
  visitImportTypeAttributes(importTypeAttributes, other) {
872
595
  return __awaiter(this, void 0, void 0, function* () {
873
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportTypeAttributes) {
874
- return this.abort(importTypeAttributes);
875
- }
876
- const otherImportTypeAttributes = other;
877
- // Compare token
878
- yield this.visit(importTypeAttributes.token.element, otherImportTypeAttributes.token.element);
879
- if (!this.match)
880
- return importTypeAttributes;
881
- // Compare elements
882
- if (importTypeAttributes.elements.elements.length !== otherImportTypeAttributes.elements.elements.length) {
883
- return this.abort(importTypeAttributes);
884
- }
885
- // Visit elements in lock step
886
- for (let i = 0; i < importTypeAttributes.elements.elements.length; i++) {
887
- yield this.visit(importTypeAttributes.elements.elements[i].element, otherImportTypeAttributes.elements.elements[i].element);
888
- if (!this.match)
889
- return importTypeAttributes;
890
- }
891
- return importTypeAttributes;
596
+ return this.visitElement(importTypeAttributes, other);
892
597
  });
893
598
  }
894
599
  /**
@@ -900,17 +605,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
900
605
  */
901
606
  visitImportAttribute(importAttribute, other) {
902
607
  return __awaiter(this, void 0, void 0, function* () {
903
- if (!this.match || other.kind !== tree_1.JS.Kind.ImportAttribute) {
904
- return this.abort(importAttribute);
905
- }
906
- const otherImportAttribute = other;
907
- // Visit name
908
- yield this.visit(importAttribute.name, otherImportAttribute.name);
909
- if (!this.match)
910
- return importAttribute;
911
- // Visit value
912
- yield this.visit(importAttribute.value.element, otherImportAttribute.value.element);
913
- return importAttribute;
608
+ return this.visitElement(importAttribute, other);
914
609
  });
915
610
  }
916
611
  /**
@@ -922,21 +617,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
922
617
  */
923
618
  visitBinaryExtensions(jsBinary, other) {
924
619
  return __awaiter(this, void 0, void 0, function* () {
925
- if (!this.match || other.kind !== tree_1.JS.Kind.Binary) {
926
- return this.abort(jsBinary);
927
- }
928
- const otherBinary = other;
929
- // Visit left operand
930
- yield this.visit(jsBinary.left, otherBinary.left);
931
- if (!this.match)
932
- return jsBinary;
933
- // Compare operator
934
- if (jsBinary.operator.element !== otherBinary.operator.element) {
935
- return this.abort(jsBinary);
936
- }
937
- // Visit right operand
938
- yield this.visit(jsBinary.right, otherBinary.right);
939
- return jsBinary;
620
+ return this.visitElement(jsBinary, other);
940
621
  });
941
622
  }
942
623
  /**
@@ -948,13 +629,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
948
629
  */
949
630
  visitLiteralType(literalType, other) {
950
631
  return __awaiter(this, void 0, void 0, function* () {
951
- if (!this.match || other.kind !== tree_1.JS.Kind.LiteralType) {
952
- return this.abort(literalType);
953
- }
954
- const otherLiteralType = other;
955
- // Visit literal
956
- yield this.visit(literalType.literal, otherLiteralType.literal);
957
- return literalType;
632
+ return this.visitElement(literalType, other);
958
633
  });
959
634
  }
960
635
  /**
@@ -966,51 +641,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
966
641
  */
967
642
  visitMappedType(mappedType, other) {
968
643
  return __awaiter(this, void 0, void 0, function* () {
969
- if (!this.match || other.kind !== tree_1.JS.Kind.MappedType) {
970
- return this.abort(mappedType);
971
- }
972
- const otherMappedType = other;
973
- // Compare prefix token
974
- if (!!mappedType.prefixToken !== !!otherMappedType.prefixToken) {
975
- return this.abort(mappedType);
976
- }
977
- if (mappedType.prefixToken) {
978
- yield this.visit(mappedType.prefixToken.element, otherMappedType.prefixToken.element);
979
- if (!this.match)
980
- return mappedType;
981
- }
982
- // Compare has readonly
983
- if (mappedType.hasReadonly.element !== otherMappedType.hasReadonly.element) {
984
- return this.abort(mappedType);
985
- }
986
- // Visit keys remapping
987
- yield this.visit(mappedType.keysRemapping, otherMappedType.keysRemapping);
988
- if (!this.match)
989
- return mappedType;
990
- // Compare suffix token
991
- if (!!mappedType.suffixToken !== !!otherMappedType.suffixToken) {
992
- return this.abort(mappedType);
993
- }
994
- if (mappedType.suffixToken) {
995
- yield this.visit(mappedType.suffixToken.element, otherMappedType.suffixToken.element);
996
- if (!this.match)
997
- return mappedType;
998
- }
999
- // Compare has question token
1000
- if (mappedType.hasQuestionToken.element !== otherMappedType.hasQuestionToken.element) {
1001
- return this.abort(mappedType);
1002
- }
1003
- // Compare value type
1004
- if (mappedType.valueType.elements.length !== otherMappedType.valueType.elements.length) {
1005
- return this.abort(mappedType);
1006
- }
1007
- // Visit value type elements in lock step
1008
- for (let i = 0; i < mappedType.valueType.elements.length; i++) {
1009
- yield this.visit(mappedType.valueType.elements[i].element, otherMappedType.valueType.elements[i].element);
1010
- if (!this.match)
1011
- return mappedType;
1012
- }
1013
- return mappedType;
644
+ return this.visitElement(mappedType, other);
1014
645
  });
1015
646
  }
1016
647
  /**
@@ -1022,22 +653,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1022
653
  */
1023
654
  visitMappedTypeKeysRemapping(keysRemapping, other) {
1024
655
  return __awaiter(this, void 0, void 0, function* () {
1025
- if (!this.match || other.kind !== tree_1.JS.Kind.MappedTypeKeysRemapping) {
1026
- return this.abort(keysRemapping);
1027
- }
1028
- const otherKeysRemapping = other;
1029
- // Visit type parameter
1030
- yield this.visit(keysRemapping.typeParameter.element, otherKeysRemapping.typeParameter.element);
1031
- if (!this.match)
1032
- return keysRemapping;
1033
- // Compare name type
1034
- if (!!keysRemapping.nameType !== !!otherKeysRemapping.nameType) {
1035
- return this.abort(keysRemapping);
1036
- }
1037
- if (keysRemapping.nameType) {
1038
- yield this.visit(keysRemapping.nameType.element, otherKeysRemapping.nameType.element);
1039
- }
1040
- return keysRemapping;
656
+ return this.visitElement(keysRemapping, other);
1041
657
  });
1042
658
  }
1043
659
  /**
@@ -1049,17 +665,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1049
665
  */
1050
666
  visitMappedTypeParameter(mappedTypeParameter, other) {
1051
667
  return __awaiter(this, void 0, void 0, function* () {
1052
- if (!this.match || other.kind !== tree_1.JS.Kind.MappedTypeParameter) {
1053
- return this.abort(mappedTypeParameter);
1054
- }
1055
- const otherMappedTypeParameter = other;
1056
- // Visit name
1057
- yield this.visit(mappedTypeParameter.name, otherMappedTypeParameter.name);
1058
- if (!this.match)
1059
- return mappedTypeParameter;
1060
- // Visit iterate type
1061
- yield this.visit(mappedTypeParameter.iterateType.element, otherMappedTypeParameter.iterateType.element);
1062
- return mappedTypeParameter;
668
+ return this.visitElement(mappedTypeParameter, other);
1063
669
  });
1064
670
  }
1065
671
  /**
@@ -1071,57 +677,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1071
677
  */
1072
678
  visitObjectBindingPattern(objectBindingPattern, other) {
1073
679
  return __awaiter(this, void 0, void 0, function* () {
1074
- if (!this.match || other.kind !== tree_1.JS.Kind.ObjectBindingPattern) {
1075
- return this.abort(objectBindingPattern);
1076
- }
1077
- const otherObjectBindingPattern = other;
1078
- // Compare leading annotations
1079
- if (objectBindingPattern.leadingAnnotations.length !== otherObjectBindingPattern.leadingAnnotations.length) {
1080
- return this.abort(objectBindingPattern);
1081
- }
1082
- // Visit leading annotations in lock step
1083
- for (let i = 0; i < objectBindingPattern.leadingAnnotations.length; i++) {
1084
- yield this.visit(objectBindingPattern.leadingAnnotations[i], otherObjectBindingPattern.leadingAnnotations[i]);
1085
- if (!this.match)
1086
- return objectBindingPattern;
1087
- }
1088
- // Compare modifiers
1089
- if (objectBindingPattern.modifiers.length !== otherObjectBindingPattern.modifiers.length) {
1090
- return this.abort(objectBindingPattern);
1091
- }
1092
- // Visit modifiers in lock step
1093
- for (let i = 0; i < objectBindingPattern.modifiers.length; i++) {
1094
- yield this.visit(objectBindingPattern.modifiers[i], otherObjectBindingPattern.modifiers[i]);
1095
- if (!this.match)
1096
- return objectBindingPattern;
1097
- }
1098
- // Compare type expression
1099
- if (!!objectBindingPattern.typeExpression !== !!otherObjectBindingPattern.typeExpression) {
1100
- return this.abort(objectBindingPattern);
1101
- }
1102
- if (objectBindingPattern.typeExpression) {
1103
- yield this.visit(objectBindingPattern.typeExpression, otherObjectBindingPattern.typeExpression);
1104
- if (!this.match)
1105
- return objectBindingPattern;
1106
- }
1107
- // Compare bindings
1108
- if (objectBindingPattern.bindings.elements.length !== otherObjectBindingPattern.bindings.elements.length) {
1109
- return this.abort(objectBindingPattern);
1110
- }
1111
- // Visit bindings in lock step
1112
- for (let i = 0; i < objectBindingPattern.bindings.elements.length; i++) {
1113
- yield this.visit(objectBindingPattern.bindings.elements[i].element, otherObjectBindingPattern.bindings.elements[i].element);
1114
- if (!this.match)
1115
- return objectBindingPattern;
1116
- }
1117
- // Compare initializer
1118
- if (!!objectBindingPattern.initializer !== !!otherObjectBindingPattern.initializer) {
1119
- return this.abort(objectBindingPattern);
1120
- }
1121
- if (objectBindingPattern.initializer) {
1122
- yield this.visit(objectBindingPattern.initializer.element, otherObjectBindingPattern.initializer.element);
1123
- }
1124
- return objectBindingPattern;
680
+ return this.visitElement(objectBindingPattern, other);
1125
681
  });
1126
682
  }
1127
683
  /**
@@ -1133,22 +689,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1133
689
  */
1134
690
  visitPropertyAssignment(propertyAssignment, other) {
1135
691
  return __awaiter(this, void 0, void 0, function* () {
1136
- if (!this.match || other.kind !== tree_1.JS.Kind.PropertyAssignment) {
1137
- return this.abort(propertyAssignment);
1138
- }
1139
- const otherPropertyAssignment = other;
1140
- // Visit name
1141
- yield this.visit(propertyAssignment.name.element, otherPropertyAssignment.name.element);
1142
- if (!this.match)
1143
- return propertyAssignment;
1144
- // Compare initializer
1145
- if (!!propertyAssignment.initializer !== !!otherPropertyAssignment.initializer) {
1146
- return this.abort(propertyAssignment);
1147
- }
1148
- if (propertyAssignment.initializer) {
1149
- yield this.visit(propertyAssignment.initializer, otherPropertyAssignment.initializer);
1150
- }
1151
- return propertyAssignment;
692
+ return this.visitElement(propertyAssignment, other);
1152
693
  });
1153
694
  }
1154
695
  /**
@@ -1160,17 +701,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1160
701
  */
1161
702
  visitSatisfiesExpression(satisfiesExpression, other) {
1162
703
  return __awaiter(this, void 0, void 0, function* () {
1163
- if (!this.match || other.kind !== tree_1.JS.Kind.SatisfiesExpression) {
1164
- return this.abort(satisfiesExpression);
1165
- }
1166
- const otherSatisfiesExpression = other;
1167
- // Visit expression
1168
- yield this.visit(satisfiesExpression.expression, otherSatisfiesExpression.expression);
1169
- if (!this.match)
1170
- return satisfiesExpression;
1171
- // Visit satisfies type
1172
- yield this.visit(satisfiesExpression.satisfiesType.element, otherSatisfiesExpression.satisfiesType.element);
1173
- return satisfiesExpression;
704
+ return this.visitElement(satisfiesExpression, other);
1174
705
  });
1175
706
  }
1176
707
  /**
@@ -1182,31 +713,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1182
713
  */
1183
714
  visitScopedVariableDeclarations(scopedVariableDeclarations, other) {
1184
715
  return __awaiter(this, void 0, void 0, function* () {
1185
- if (!this.match || other.kind !== tree_1.JS.Kind.ScopedVariableDeclarations) {
1186
- return this.abort(scopedVariableDeclarations);
1187
- }
1188
- const otherScopedVariableDeclarations = other;
1189
- // Compare modifiers
1190
- if (scopedVariableDeclarations.modifiers.length !== otherScopedVariableDeclarations.modifiers.length) {
1191
- return this.abort(scopedVariableDeclarations);
1192
- }
1193
- // Visit modifiers in lock step
1194
- for (let i = 0; i < scopedVariableDeclarations.modifiers.length; i++) {
1195
- yield this.visit(scopedVariableDeclarations.modifiers[i], otherScopedVariableDeclarations.modifiers[i]);
1196
- if (!this.match)
1197
- return scopedVariableDeclarations;
1198
- }
1199
- // Compare variables
1200
- if (scopedVariableDeclarations.variables.length !== otherScopedVariableDeclarations.variables.length) {
1201
- return this.abort(scopedVariableDeclarations);
1202
- }
1203
- // Visit variables in lock step
1204
- for (let i = 0; i < scopedVariableDeclarations.variables.length; i++) {
1205
- yield this.visit(scopedVariableDeclarations.variables[i].element, otherScopedVariableDeclarations.variables[i].element);
1206
- if (!this.match)
1207
- return scopedVariableDeclarations;
1208
- }
1209
- return scopedVariableDeclarations;
716
+ return this.visitElement(scopedVariableDeclarations, other);
1210
717
  });
1211
718
  }
1212
719
  /**
@@ -1218,13 +725,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1218
725
  */
1219
726
  visitStatementExpression(statementExpression, other) {
1220
727
  return __awaiter(this, void 0, void 0, function* () {
1221
- if (!this.match || other.kind !== tree_1.JS.Kind.StatementExpression) {
1222
- return this.abort(statementExpression);
1223
- }
1224
- const otherStatementExpression = other;
1225
- // Visit statement
1226
- yield this.visit(statementExpression.statement, otherStatementExpression.statement);
1227
- return statementExpression;
728
+ return this.visitElement(statementExpression, other);
1228
729
  });
1229
730
  }
1230
731
  /**
@@ -1236,37 +737,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1236
737
  */
1237
738
  visitTaggedTemplateExpression(taggedTemplateExpression, other) {
1238
739
  return __awaiter(this, void 0, void 0, function* () {
1239
- if (!this.match || other.kind !== tree_1.JS.Kind.TaggedTemplateExpression) {
1240
- return this.abort(taggedTemplateExpression);
1241
- }
1242
- const otherTaggedTemplateExpression = other;
1243
- // Compare tag
1244
- if (!!taggedTemplateExpression.tag !== !!otherTaggedTemplateExpression.tag) {
1245
- return this.abort(taggedTemplateExpression);
1246
- }
1247
- if (taggedTemplateExpression.tag) {
1248
- yield this.visit(taggedTemplateExpression.tag.element, otherTaggedTemplateExpression.tag.element);
1249
- if (!this.match)
1250
- return taggedTemplateExpression;
1251
- }
1252
- // Compare type arguments
1253
- if (!!taggedTemplateExpression.typeArguments !== !!otherTaggedTemplateExpression.typeArguments) {
1254
- return this.abort(taggedTemplateExpression);
1255
- }
1256
- if (taggedTemplateExpression.typeArguments) {
1257
- if (taggedTemplateExpression.typeArguments.elements.length !== otherTaggedTemplateExpression.typeArguments.elements.length) {
1258
- return this.abort(taggedTemplateExpression);
1259
- }
1260
- // Visit type arguments in lock step
1261
- for (let i = 0; i < taggedTemplateExpression.typeArguments.elements.length; i++) {
1262
- yield this.visit(taggedTemplateExpression.typeArguments.elements[i].element, otherTaggedTemplateExpression.typeArguments.elements[i].element);
1263
- if (!this.match)
1264
- return taggedTemplateExpression;
1265
- }
1266
- }
1267
- // Visit template expression
1268
- yield this.visit(taggedTemplateExpression.templateExpression, otherTaggedTemplateExpression.templateExpression);
1269
- return taggedTemplateExpression;
740
+ return this.visitElement(taggedTemplateExpression, other);
1270
741
  });
1271
742
  }
1272
743
  /**
@@ -1278,25 +749,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1278
749
  */
1279
750
  visitTemplateExpression(templateExpression, other) {
1280
751
  return __awaiter(this, void 0, void 0, function* () {
1281
- if (!this.match || other.kind !== tree_1.JS.Kind.TemplateExpression) {
1282
- return this.abort(templateExpression);
1283
- }
1284
- const otherTemplateExpression = other;
1285
- // Visit head
1286
- yield this.visit(templateExpression.head, otherTemplateExpression.head);
1287
- if (!this.match)
1288
- return templateExpression;
1289
- // Compare spans
1290
- if (templateExpression.spans.length !== otherTemplateExpression.spans.length) {
1291
- return this.abort(templateExpression);
1292
- }
1293
- // Visit spans in lock step
1294
- for (let i = 0; i < templateExpression.spans.length; i++) {
1295
- yield this.visit(templateExpression.spans[i].element, otherTemplateExpression.spans[i].element);
1296
- if (!this.match)
1297
- return templateExpression;
1298
- }
1299
- return templateExpression;
752
+ return this.visitElement(templateExpression, other);
1300
753
  });
1301
754
  }
1302
755
  /**
@@ -1308,17 +761,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1308
761
  */
1309
762
  visitTemplateExpressionSpan(span, other) {
1310
763
  return __awaiter(this, void 0, void 0, function* () {
1311
- if (!this.match || other.kind !== tree_1.JS.Kind.TemplateExpressionSpan) {
1312
- return this.abort(span);
1313
- }
1314
- const otherSpan = other;
1315
- // Visit expression
1316
- yield this.visit(span.expression, otherSpan.expression);
1317
- if (!this.match)
1318
- return span;
1319
- // Visit tail
1320
- yield this.visit(span.tail, otherSpan.tail);
1321
- return span;
764
+ return this.visitElement(span, other);
1322
765
  });
1323
766
  }
1324
767
  /**
@@ -1330,21 +773,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1330
773
  */
1331
774
  visitTuple(tuple, other) {
1332
775
  return __awaiter(this, void 0, void 0, function* () {
1333
- if (!this.match || other.kind !== tree_1.JS.Kind.Tuple) {
1334
- return this.abort(tuple);
1335
- }
1336
- const otherTuple = other;
1337
- // Compare elements
1338
- if (tuple.elements.elements.length !== otherTuple.elements.elements.length) {
1339
- return this.abort(tuple);
1340
- }
1341
- // Visit elements in lock step
1342
- for (let i = 0; i < tuple.elements.elements.length; i++) {
1343
- yield this.visit(tuple.elements.elements[i].element, otherTuple.elements.elements[i].element);
1344
- if (!this.match)
1345
- return tuple;
1346
- }
1347
- return tuple;
776
+ return this.visitElement(tuple, other);
1348
777
  });
1349
778
  }
1350
779
  /**
@@ -1356,36 +785,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1356
785
  */
1357
786
  visitTypeDeclaration(typeDeclaration, other) {
1358
787
  return __awaiter(this, void 0, void 0, function* () {
1359
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeDeclaration) {
1360
- return this.abort(typeDeclaration);
1361
- }
1362
- const otherTypeDeclaration = other;
1363
- // Compare modifiers
1364
- if (typeDeclaration.modifiers.length !== otherTypeDeclaration.modifiers.length) {
1365
- return this.abort(typeDeclaration);
1366
- }
1367
- // Visit modifiers in lock step
1368
- for (let i = 0; i < typeDeclaration.modifiers.length; i++) {
1369
- yield this.visit(typeDeclaration.modifiers[i], otherTypeDeclaration.modifiers[i]);
1370
- if (!this.match)
1371
- return typeDeclaration;
1372
- }
1373
- // Visit name
1374
- yield this.visit(typeDeclaration.name.element, otherTypeDeclaration.name.element);
1375
- if (!this.match)
1376
- return typeDeclaration;
1377
- // Compare type parameters
1378
- if (!!typeDeclaration.typeParameters !== !!otherTypeDeclaration.typeParameters) {
1379
- return this.abort(typeDeclaration);
1380
- }
1381
- if (typeDeclaration.typeParameters) {
1382
- yield this.visit(typeDeclaration.typeParameters, otherTypeDeclaration.typeParameters);
1383
- if (!this.match)
1384
- return typeDeclaration;
1385
- }
1386
- // Visit initializer
1387
- yield this.visit(typeDeclaration.initializer.element, otherTypeDeclaration.initializer.element);
1388
- return typeDeclaration;
788
+ return this.visitElement(typeDeclaration, other);
1389
789
  });
1390
790
  }
1391
791
  /**
@@ -1397,13 +797,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1397
797
  */
1398
798
  visitTypeOf(typeOf, other) {
1399
799
  return __awaiter(this, void 0, void 0, function* () {
1400
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeOf) {
1401
- return this.abort(typeOf);
1402
- }
1403
- const otherTypeOf = other;
1404
- // Visit expression
1405
- yield this.visit(typeOf.expression, otherTypeOf.expression);
1406
- return typeOf;
800
+ return this.visitElement(typeOf, other);
1407
801
  });
1408
802
  }
1409
803
  /**
@@ -1415,13 +809,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1415
809
  */
1416
810
  visitTypeTreeExpression(typeTreeExpression, other) {
1417
811
  return __awaiter(this, void 0, void 0, function* () {
1418
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeTreeExpression) {
1419
- return this.abort(typeTreeExpression);
1420
- }
1421
- const otherTypeTreeExpression = other;
1422
- // Visit expression
1423
- yield this.visit(typeTreeExpression.expression, otherTypeTreeExpression.expression);
1424
- return typeTreeExpression;
812
+ return this.visitElement(typeTreeExpression, other);
1425
813
  });
1426
814
  }
1427
815
  /**
@@ -1433,16 +821,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1433
821
  */
1434
822
  visitAs(as_, other) {
1435
823
  return __awaiter(this, void 0, void 0, function* () {
1436
- if (!this.match || other.kind !== tree_1.JS.Kind.As) {
1437
- return this.abort(as_);
1438
- }
1439
- const otherAs = other;
1440
- // Visit left and right operands in lock step
1441
- yield this.visit(as_.left.element, otherAs.left.element);
1442
- if (!this.match)
1443
- return as_;
1444
- yield this.visit(as_.right, otherAs.right);
1445
- return as_;
824
+ return this.visitElement(as_, other);
1446
825
  });
1447
826
  }
1448
827
  /**
@@ -1454,21 +833,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1454
833
  */
1455
834
  visitAssignmentOperationExtensions(assignmentOperation, other) {
1456
835
  return __awaiter(this, void 0, void 0, function* () {
1457
- if (!this.match || other.kind !== tree_1.JS.Kind.AssignmentOperation) {
1458
- return this.abort(assignmentOperation);
1459
- }
1460
- const otherAssignmentOperation = other;
1461
- // Visit variable
1462
- yield this.visit(assignmentOperation.variable, otherAssignmentOperation.variable);
1463
- if (!this.match)
1464
- return assignmentOperation;
1465
- // Compare operator
1466
- if (assignmentOperation.operator.element !== otherAssignmentOperation.operator.element) {
1467
- return this.abort(assignmentOperation);
1468
- }
1469
- // Visit assignment
1470
- yield this.visit(assignmentOperation.assignment, otherAssignmentOperation.assignment);
1471
- return assignmentOperation;
836
+ return this.visitElement(assignmentOperation, other);
1472
837
  });
1473
838
  }
1474
839
  /**
@@ -1480,17 +845,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1480
845
  */
1481
846
  visitIndexedAccessType(indexedAccessType, other) {
1482
847
  return __awaiter(this, void 0, void 0, function* () {
1483
- if (!this.match || other.kind !== tree_1.JS.Kind.IndexedAccessType) {
1484
- return this.abort(indexedAccessType);
1485
- }
1486
- const otherIndexedAccessType = other;
1487
- // Visit object type
1488
- yield this.visit(indexedAccessType.objectType, otherIndexedAccessType.objectType);
1489
- if (!this.match)
1490
- return indexedAccessType;
1491
- // Visit index type
1492
- yield this.visit(indexedAccessType.indexType, otherIndexedAccessType.indexType);
1493
- return indexedAccessType;
848
+ return this.visitElement(indexedAccessType, other);
1494
849
  });
1495
850
  }
1496
851
  /**
@@ -1502,13 +857,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1502
857
  */
1503
858
  visitIndexedAccessTypeIndexType(indexType, other) {
1504
859
  return __awaiter(this, void 0, void 0, function* () {
1505
- if (!this.match || other.kind !== tree_1.JS.Kind.IndexType) {
1506
- return this.abort(indexType);
1507
- }
1508
- const otherIndexType = other;
1509
- // Visit element
1510
- yield this.visit(indexType.element.element, otherIndexType.element.element);
1511
- return indexType;
860
+ return this.visitElement(indexType, other);
1512
861
  });
1513
862
  }
1514
863
  /**
@@ -1520,30 +869,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1520
869
  */
1521
870
  visitTypeQuery(typeQuery, other) {
1522
871
  return __awaiter(this, void 0, void 0, function* () {
1523
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeQuery) {
1524
- return this.abort(typeQuery);
1525
- }
1526
- const otherTypeQuery = other;
1527
- // Visit type expression
1528
- yield this.visit(typeQuery.typeExpression, otherTypeQuery.typeExpression);
1529
- if (!this.match)
1530
- return typeQuery;
1531
- // Compare type arguments
1532
- if (!!typeQuery.typeArguments !== !!otherTypeQuery.typeArguments) {
1533
- return this.abort(typeQuery);
1534
- }
1535
- if (typeQuery.typeArguments) {
1536
- if (typeQuery.typeArguments.elements.length !== otherTypeQuery.typeArguments.elements.length) {
1537
- return this.abort(typeQuery);
1538
- }
1539
- // Visit type arguments in lock step
1540
- for (let i = 0; i < typeQuery.typeArguments.elements.length; i++) {
1541
- yield this.visit(typeQuery.typeArguments.elements[i].element, otherTypeQuery.typeArguments.elements[i].element);
1542
- if (!this.match)
1543
- return typeQuery;
1544
- }
1545
- }
1546
- return typeQuery;
872
+ return this.visitElement(typeQuery, other);
1547
873
  });
1548
874
  }
1549
875
  /**
@@ -1555,13 +881,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1555
881
  */
1556
882
  visitTypeInfo(typeInfo, other) {
1557
883
  return __awaiter(this, void 0, void 0, function* () {
1558
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeInfo) {
1559
- return this.abort(typeInfo);
1560
- }
1561
- const otherTypeInfo = other;
1562
- // Visit type identifier
1563
- yield this.visit(typeInfo.typeIdentifier, otherTypeInfo.typeIdentifier);
1564
- return typeInfo;
884
+ return this.visitElement(typeInfo, other);
1565
885
  });
1566
886
  }
1567
887
  /**
@@ -1573,13 +893,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1573
893
  */
1574
894
  visitComputedPropertyName(computedPropertyName, other) {
1575
895
  return __awaiter(this, void 0, void 0, function* () {
1576
- if (!this.match || other.kind !== tree_1.JS.Kind.ComputedPropertyName) {
1577
- return this.abort(computedPropertyName);
1578
- }
1579
- const otherComputedPropertyName = other;
1580
- // Visit expression
1581
- yield this.visit(computedPropertyName.expression.element, otherComputedPropertyName.expression.element);
1582
- return computedPropertyName;
896
+ return this.visitElement(computedPropertyName, other);
1583
897
  });
1584
898
  }
1585
899
  /**
@@ -1591,13 +905,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1591
905
  */
1592
906
  visitTypeOperator(typeOperator, other) {
1593
907
  return __awaiter(this, void 0, void 0, function* () {
1594
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeOperator) {
1595
- return this.abort(typeOperator);
1596
- }
1597
- const otherTypeOperator = other;
1598
- // Visit expression
1599
- yield this.visit(typeOperator.expression.element, otherTypeOperator.expression.element);
1600
- return typeOperator;
908
+ return this.visitElement(typeOperator, other);
1601
909
  });
1602
910
  }
1603
911
  /**
@@ -1609,26 +917,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1609
917
  */
1610
918
  visitTypePredicate(typePredicate, other) {
1611
919
  return __awaiter(this, void 0, void 0, function* () {
1612
- if (!this.match || other.kind !== tree_1.JS.Kind.TypePredicate) {
1613
- return this.abort(typePredicate);
1614
- }
1615
- const otherTypePredicate = other;
1616
- // Compare asserts
1617
- if (typePredicate.asserts.element !== otherTypePredicate.asserts.element) {
1618
- return this.abort(typePredicate);
1619
- }
1620
- // Visit parameter name
1621
- yield this.visit(typePredicate.parameterName, otherTypePredicate.parameterName);
1622
- if (!this.match)
1623
- return typePredicate;
1624
- // Compare expression
1625
- if (!!typePredicate.expression !== !!otherTypePredicate.expression) {
1626
- return this.abort(typePredicate);
1627
- }
1628
- if (typePredicate.expression) {
1629
- yield this.visit(typePredicate.expression.element, otherTypePredicate.expression.element);
1630
- }
1631
- return typePredicate;
920
+ return this.visitElement(typePredicate, other);
1632
921
  });
1633
922
  }
1634
923
  /**
@@ -1640,21 +929,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1640
929
  */
1641
930
  visitUnion(union, other) {
1642
931
  return __awaiter(this, void 0, void 0, function* () {
1643
- if (!this.match || other.kind !== tree_1.JS.Kind.Union) {
1644
- return this.abort(union);
1645
- }
1646
- const otherUnion = other;
1647
- // Compare types
1648
- if (union.types.length !== otherUnion.types.length) {
1649
- return this.abort(union);
1650
- }
1651
- // Visit types in lock step
1652
- for (let i = 0; i < union.types.length; i++) {
1653
- yield this.visit(union.types[i].element, otherUnion.types[i].element);
1654
- if (!this.match)
1655
- return union;
1656
- }
1657
- return union;
932
+ return this.visitElement(union, other);
1658
933
  });
1659
934
  }
1660
935
  /**
@@ -1666,21 +941,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1666
941
  */
1667
942
  visitIntersection(intersection, other) {
1668
943
  return __awaiter(this, void 0, void 0, function* () {
1669
- if (!this.match || other.kind !== tree_1.JS.Kind.Intersection) {
1670
- return this.abort(intersection);
1671
- }
1672
- const otherIntersection = other;
1673
- // Compare types
1674
- if (intersection.types.length !== otherIntersection.types.length) {
1675
- return this.abort(intersection);
1676
- }
1677
- // Visit types in lock step
1678
- for (let i = 0; i < intersection.types.length; i++) {
1679
- yield this.visit(intersection.types[i].element, otherIntersection.types[i].element);
1680
- if (!this.match)
1681
- return intersection;
1682
- }
1683
- return intersection;
944
+ return this.visitElement(intersection, other);
1684
945
  });
1685
946
  }
1686
947
  /**
@@ -1692,23 +953,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1692
953
  */
1693
954
  visitAnnotatedType(annotatedType, other) {
1694
955
  return __awaiter(this, void 0, void 0, function* () {
1695
- if (!this.match || other.kind !== java_1.J.Kind.AnnotatedType) {
1696
- return this.abort(annotatedType);
1697
- }
1698
- const otherAnnotatedType = other;
1699
- // Compare annotations
1700
- if (annotatedType.annotations.length !== otherAnnotatedType.annotations.length) {
1701
- return this.abort(annotatedType);
1702
- }
1703
- // Visit each annotation in lock step
1704
- for (let i = 0; i < annotatedType.annotations.length; i++) {
1705
- yield this.visit(annotatedType.annotations[i], otherAnnotatedType.annotations[i]);
1706
- if (!this.match)
1707
- return annotatedType;
1708
- }
1709
- // Visit type expression
1710
- yield this.visit(annotatedType.typeExpression, otherAnnotatedType.typeExpression);
1711
- return annotatedType;
956
+ return this.visitElement(annotatedType, other);
1712
957
  });
1713
958
  }
1714
959
  /**
@@ -1720,31 +965,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1720
965
  */
1721
966
  visitAnnotation(annotation, other) {
1722
967
  return __awaiter(this, void 0, void 0, function* () {
1723
- if (!this.match || other.kind !== java_1.J.Kind.Annotation) {
1724
- return this.abort(annotation);
1725
- }
1726
- const otherAnnotation = other;
1727
- // Visit annotation type
1728
- yield this.visit(annotation.annotationType, otherAnnotation.annotationType);
1729
- if (!this.match)
1730
- return annotation;
1731
- // Compare arguments
1732
- if ((annotation.arguments === undefined) !== (otherAnnotation.arguments === undefined)) {
1733
- return this.abort(annotation);
1734
- }
1735
- // If both have arguments, visit them
1736
- if (annotation.arguments && otherAnnotation.arguments) {
1737
- if (annotation.arguments.elements.length !== otherAnnotation.arguments.elements.length) {
1738
- return this.abort(annotation);
1739
- }
1740
- // Visit each argument in lock step
1741
- for (let i = 0; i < annotation.arguments.elements.length; i++) {
1742
- yield this.visit(annotation.arguments.elements[i].element, otherAnnotation.arguments.elements[i].element);
1743
- if (!this.match)
1744
- return annotation;
1745
- }
1746
- }
1747
- return annotation;
968
+ return this.visitElement(annotation, other);
1748
969
  });
1749
970
  }
1750
971
  /**
@@ -1756,17 +977,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1756
977
  */
1757
978
  visitArrayAccess(arrayAccess, other) {
1758
979
  return __awaiter(this, void 0, void 0, function* () {
1759
- if (!this.match || other.kind !== java_1.J.Kind.ArrayAccess) {
1760
- return this.abort(arrayAccess);
1761
- }
1762
- const otherArrayAccess = other;
1763
- // Visit indexed expression
1764
- yield this.visit(arrayAccess.indexed, otherArrayAccess.indexed);
1765
- if (!this.match)
1766
- return arrayAccess;
1767
- // Visit dimension
1768
- yield this.visit(arrayAccess.dimension, otherArrayAccess.dimension);
1769
- return arrayAccess;
980
+ return this.visitElement(arrayAccess, other);
1770
981
  });
1771
982
  }
1772
983
  /**
@@ -1778,19 +989,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1778
989
  */
1779
990
  visitArrayDimension(arrayDimension, other) {
1780
991
  return __awaiter(this, void 0, void 0, function* () {
1781
- if (!this.match || other.kind !== java_1.J.Kind.ArrayDimension) {
1782
- return this.abort(arrayDimension);
1783
- }
1784
- const otherArrayDimension = other;
1785
- // Visit index
1786
- if (arrayDimension.index && otherArrayDimension.index) {
1787
- yield this.visit(arrayDimension.index.element, otherArrayDimension.index.element);
1788
- }
1789
- else if (arrayDimension.index !== otherArrayDimension.index) {
1790
- // One has an index and the other doesn't
1791
- return this.abort(arrayDimension);
1792
- }
1793
- return arrayDimension;
992
+ return this.visitElement(arrayDimension, other);
1794
993
  });
1795
994
  }
1796
995
  /**
@@ -1802,28 +1001,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1802
1001
  */
1803
1002
  visitArrayType(arrayType, other) {
1804
1003
  return __awaiter(this, void 0, void 0, function* () {
1805
- var _a, _b;
1806
- if (!this.match || other.kind !== java_1.J.Kind.ArrayType) {
1807
- return this.abort(arrayType);
1808
- }
1809
- const otherArrayType = other;
1810
- // Visit element type
1811
- yield this.visit(arrayType.elementType, otherArrayType.elementType);
1812
- if (!this.match)
1813
- return arrayType;
1814
- // Compare annotations
1815
- if ((((_a = arrayType.annotations) === null || _a === void 0 ? void 0 : _a.length) || 0) !== (((_b = otherArrayType.annotations) === null || _b === void 0 ? void 0 : _b.length) || 0)) {
1816
- return this.abort(arrayType);
1817
- }
1818
- // Visit annotations if they exist
1819
- if (arrayType.annotations && otherArrayType.annotations) {
1820
- for (let i = 0; i < arrayType.annotations.length; i++) {
1821
- yield this.visit(arrayType.annotations[i], otherArrayType.annotations[i]);
1822
- if (!this.match)
1823
- return arrayType;
1824
- }
1825
- }
1826
- return arrayType;
1004
+ return this.visitElement(arrayType, other);
1827
1005
  });
1828
1006
  }
1829
1007
  /**
@@ -1835,23 +1013,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1835
1013
  */
1836
1014
  visitAssert(anAssert, other) {
1837
1015
  return __awaiter(this, void 0, void 0, function* () {
1838
- if (!this.match || other.kind !== java_1.J.Kind.Assert) {
1839
- return this.abort(anAssert);
1840
- }
1841
- const otherAssert = other;
1842
- // Visit condition
1843
- yield this.visit(anAssert.condition, otherAssert.condition);
1844
- if (!this.match)
1845
- return anAssert;
1846
- // Compare detail
1847
- if ((anAssert.detail !== undefined) !== (otherAssert.detail !== undefined)) {
1848
- return this.abort(anAssert);
1849
- }
1850
- // Visit detail if it exists
1851
- if (anAssert.detail && otherAssert.detail) {
1852
- yield this.visit(anAssert.detail.element, otherAssert.detail.element);
1853
- }
1854
- return anAssert;
1016
+ return this.visitElement(anAssert, other);
1855
1017
  });
1856
1018
  }
1857
1019
  /**
@@ -1863,23 +1025,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1863
1025
  */
1864
1026
  visitAssignment(assignment, other) {
1865
1027
  return __awaiter(this, void 0, void 0, function* () {
1866
- if (!this.match || other.kind !== java_1.J.Kind.Assignment) {
1867
- return this.abort(assignment);
1868
- }
1869
- const otherAssignment = other;
1870
- // Visit variable
1871
- yield this.visit(assignment.variable, otherAssignment.variable);
1872
- if (!this.match)
1873
- return assignment;
1874
- // Visit assignment
1875
- if (assignment.assignment && otherAssignment.assignment) {
1876
- yield this.visit(assignment.assignment.element, otherAssignment.assignment.element);
1877
- }
1878
- else if (assignment.assignment !== otherAssignment.assignment) {
1879
- // One has an assignment and the other doesn't
1880
- return this.abort(assignment);
1881
- }
1882
- return assignment;
1028
+ return this.visitElement(assignment, other);
1883
1029
  });
1884
1030
  }
1885
1031
  /**
@@ -1891,21 +1037,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1891
1037
  */
1892
1038
  visitAssignmentOperation(assignOp, other) {
1893
1039
  return __awaiter(this, void 0, void 0, function* () {
1894
- if (!this.match || other.kind !== java_1.J.Kind.AssignmentOperation) {
1895
- return this.abort(assignOp);
1896
- }
1897
- const otherAssignOp = other;
1898
- // Visit variable
1899
- yield this.visit(assignOp.variable, otherAssignOp.variable);
1900
- if (!this.match)
1901
- return assignOp;
1902
- // Compare operator
1903
- if (assignOp.operator.element !== otherAssignOp.operator.element) {
1904
- return this.abort(assignOp);
1905
- }
1906
- // Visit assignment
1907
- yield this.visit(assignOp.assignment, otherAssignOp.assignment);
1908
- return assignOp;
1040
+ return this.visitElement(assignOp, other);
1909
1041
  });
1910
1042
  }
1911
1043
  /**
@@ -1917,19 +1049,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1917
1049
  */
1918
1050
  visitBreak(breakStatement, other) {
1919
1051
  return __awaiter(this, void 0, void 0, function* () {
1920
- if (!this.match || other.kind !== java_1.J.Kind.Break) {
1921
- return this.abort(breakStatement);
1922
- }
1923
- const otherBreak = other;
1924
- // Compare label presence
1925
- if ((breakStatement.label !== undefined) !== (otherBreak.label !== undefined)) {
1926
- return this.abort(breakStatement);
1927
- }
1928
- // Visit label if it exists
1929
- if (breakStatement.label && otherBreak.label) {
1930
- yield this.visit(breakStatement.label, otherBreak.label);
1931
- }
1932
- return breakStatement;
1052
+ return this.visitElement(breakStatement, other);
1933
1053
  });
1934
1054
  }
1935
1055
  /**
@@ -1941,49 +1061,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1941
1061
  */
1942
1062
  visitCase(aCase, other) {
1943
1063
  return __awaiter(this, void 0, void 0, function* () {
1944
- if (!this.match || other.kind !== java_1.J.Kind.Case) {
1945
- return this.abort(aCase);
1946
- }
1947
- const otherCase = other;
1948
- // Compare case labels
1949
- if (aCase.caseLabels.elements.length !== otherCase.caseLabels.elements.length) {
1950
- return this.abort(aCase);
1951
- }
1952
- // Visit each case label in lock step
1953
- for (let i = 0; i < aCase.caseLabels.elements.length; i++) {
1954
- yield this.visit(aCase.caseLabels.elements[i].element, otherCase.caseLabels.elements[i].element);
1955
- if (!this.match)
1956
- return aCase;
1957
- }
1958
- // Compare statements
1959
- if (aCase.statements.elements.length !== otherCase.statements.elements.length) {
1960
- return this.abort(aCase);
1961
- }
1962
- // Visit each statement in lock step
1963
- for (let i = 0; i < aCase.statements.elements.length; i++) {
1964
- yield this.visit(aCase.statements.elements[i].element, otherCase.statements.elements[i].element);
1965
- if (!this.match)
1966
- return aCase;
1967
- }
1968
- // Compare body presence
1969
- if ((aCase.body !== undefined) !== (otherCase.body !== undefined)) {
1970
- return this.abort(aCase);
1971
- }
1972
- // Visit body if it exists
1973
- if (aCase.body && otherCase.body) {
1974
- yield this.visit(aCase.body.element, otherCase.body.element);
1975
- if (!this.match)
1976
- return aCase;
1977
- }
1978
- // Compare guard presence
1979
- if ((aCase.guard !== undefined) !== (otherCase.guard !== undefined)) {
1980
- return this.abort(aCase);
1981
- }
1982
- // Visit guard if it exists
1983
- if (aCase.guard && otherCase.guard) {
1984
- yield this.visit(aCase.guard, otherCase.guard);
1985
- }
1986
- return aCase;
1064
+ return this.visitElement(aCase, other);
1987
1065
  });
1988
1066
  }
1989
1067
  /**
@@ -1995,115 +1073,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
1995
1073
  */
1996
1074
  visitClassDeclaration(classDecl, other) {
1997
1075
  return __awaiter(this, void 0, void 0, function* () {
1998
- if (!this.match || other.kind !== java_1.J.Kind.ClassDeclaration) {
1999
- return this.abort(classDecl);
2000
- }
2001
- const otherClassDecl = other;
2002
- // Compare leading annotations
2003
- if (classDecl.leadingAnnotations.length !== otherClassDecl.leadingAnnotations.length) {
2004
- return this.abort(classDecl);
2005
- }
2006
- // Visit each leading annotation in lock step
2007
- for (let i = 0; i < classDecl.leadingAnnotations.length; i++) {
2008
- yield this.visit(classDecl.leadingAnnotations[i], otherClassDecl.leadingAnnotations[i]);
2009
- if (!this.match)
2010
- return classDecl;
2011
- }
2012
- // Compare modifiers
2013
- if (classDecl.modifiers.length !== otherClassDecl.modifiers.length) {
2014
- return this.abort(classDecl);
2015
- }
2016
- // Visit each modifier in lock step
2017
- for (let i = 0; i < classDecl.modifiers.length; i++) {
2018
- yield this.visit(classDecl.modifiers[i], otherClassDecl.modifiers[i]);
2019
- if (!this.match)
2020
- return classDecl;
2021
- }
2022
- // Visit class kind
2023
- yield this.visit(classDecl.classKind, otherClassDecl.classKind);
2024
- if (!this.match)
2025
- return classDecl;
2026
- // Visit name
2027
- yield this.visit(classDecl.name, otherClassDecl.name);
2028
- if (!this.match)
2029
- return classDecl;
2030
- // Compare type parameters presence
2031
- if ((classDecl.typeParameters !== undefined) !== (otherClassDecl.typeParameters !== undefined)) {
2032
- return this.abort(classDecl);
2033
- }
2034
- // Visit type parameters if they exist
2035
- if (classDecl.typeParameters && otherClassDecl.typeParameters) {
2036
- if (classDecl.typeParameters.elements.length !== otherClassDecl.typeParameters.elements.length) {
2037
- return this.abort(classDecl);
2038
- }
2039
- // Visit each type parameter in lock step
2040
- for (let i = 0; i < classDecl.typeParameters.elements.length; i++) {
2041
- yield this.visit(classDecl.typeParameters.elements[i].element, otherClassDecl.typeParameters.elements[i].element);
2042
- if (!this.match)
2043
- return classDecl;
2044
- }
2045
- }
2046
- // Compare primary constructor presence
2047
- if ((classDecl.primaryConstructor !== undefined) !== (otherClassDecl.primaryConstructor !== undefined)) {
2048
- return this.abort(classDecl);
2049
- }
2050
- // Visit primary constructor if it exists
2051
- if (classDecl.primaryConstructor && otherClassDecl.primaryConstructor) {
2052
- if (classDecl.primaryConstructor.elements.length !== otherClassDecl.primaryConstructor.elements.length) {
2053
- return this.abort(classDecl);
2054
- }
2055
- // Visit each primary constructor element in lock step
2056
- for (let i = 0; i < classDecl.primaryConstructor.elements.length; i++) {
2057
- yield this.visit(classDecl.primaryConstructor.elements[i].element, otherClassDecl.primaryConstructor.elements[i].element);
2058
- if (!this.match)
2059
- return classDecl;
2060
- }
2061
- }
2062
- // Compare extends presence
2063
- if ((classDecl.extends !== undefined) !== (otherClassDecl.extends !== undefined)) {
2064
- return this.abort(classDecl);
2065
- }
2066
- // Visit extends if it exists
2067
- if (classDecl.extends && otherClassDecl.extends) {
2068
- yield this.visit(classDecl.extends.element, otherClassDecl.extends.element);
2069
- if (!this.match)
2070
- return classDecl;
2071
- }
2072
- // Compare implements presence
2073
- if ((classDecl.implements !== undefined) !== (otherClassDecl.implements !== undefined)) {
2074
- return this.abort(classDecl);
2075
- }
2076
- // Visit implements if it exists
2077
- if (classDecl.implements && otherClassDecl.implements) {
2078
- if (classDecl.implements.elements.length !== otherClassDecl.implements.elements.length) {
2079
- return this.abort(classDecl);
2080
- }
2081
- // Visit each implements element in lock step
2082
- for (let i = 0; i < classDecl.implements.elements.length; i++) {
2083
- yield this.visit(classDecl.implements.elements[i].element, otherClassDecl.implements.elements[i].element);
2084
- if (!this.match)
2085
- return classDecl;
2086
- }
2087
- }
2088
- // Compare permitting presence
2089
- if ((classDecl.permitting !== undefined) !== (otherClassDecl.permitting !== undefined)) {
2090
- return this.abort(classDecl);
2091
- }
2092
- // Visit permitting if it exists
2093
- if (classDecl.permitting && otherClassDecl.permitting) {
2094
- if (classDecl.permitting.elements.length !== otherClassDecl.permitting.elements.length) {
2095
- return this.abort(classDecl);
2096
- }
2097
- // Visit each permitting element in lock step
2098
- for (let i = 0; i < classDecl.permitting.elements.length; i++) {
2099
- yield this.visit(classDecl.permitting.elements[i].element, otherClassDecl.permitting.elements[i].element);
2100
- if (!this.match)
2101
- return classDecl;
2102
- }
2103
- }
2104
- // Visit body
2105
- yield this.visit(classDecl.body, otherClassDecl.body);
2106
- return classDecl;
1076
+ return this.visitElement(classDecl, other);
2107
1077
  });
2108
1078
  }
2109
1079
  /**
@@ -2115,21 +1085,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2115
1085
  */
2116
1086
  visitClassDeclarationKind(kind, other) {
2117
1087
  return __awaiter(this, void 0, void 0, function* () {
2118
- if (!this.match || other.kind !== java_1.J.Kind.ClassDeclarationKind) {
2119
- return this.abort(kind);
2120
- }
2121
- const otherKind = other;
2122
- // Compare annotations
2123
- if (kind.annotations.length !== otherKind.annotations.length) {
2124
- return this.abort(kind);
2125
- }
2126
- // Visit each annotation in lock step
2127
- for (let i = 0; i < kind.annotations.length; i++) {
2128
- yield this.visit(kind.annotations[i], otherKind.annotations[i]);
2129
- if (!this.match)
2130
- return kind;
2131
- }
2132
- return kind;
1088
+ return this.visitElement(kind, other);
2133
1089
  });
2134
1090
  }
2135
1091
  /**
@@ -2141,41 +1097,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2141
1097
  */
2142
1098
  visitCompilationUnit(compilationUnit, other) {
2143
1099
  return __awaiter(this, void 0, void 0, function* () {
2144
- if (!this.match || other.kind !== java_1.J.Kind.CompilationUnit) {
2145
- return this.abort(compilationUnit);
2146
- }
2147
- const otherCompilationUnit = other;
2148
- // Compare package declaration presence
2149
- if ((compilationUnit.packageDeclaration !== undefined) !== (otherCompilationUnit.packageDeclaration !== undefined)) {
2150
- return this.abort(compilationUnit);
2151
- }
2152
- // Visit package declaration if it exists
2153
- if (compilationUnit.packageDeclaration && otherCompilationUnit.packageDeclaration) {
2154
- yield this.visit(compilationUnit.packageDeclaration.element, otherCompilationUnit.packageDeclaration.element);
2155
- if (!this.match)
2156
- return compilationUnit;
2157
- }
2158
- // Compare imports
2159
- if (compilationUnit.imports.length !== otherCompilationUnit.imports.length) {
2160
- return this.abort(compilationUnit);
2161
- }
2162
- // Visit each import in lock step
2163
- for (let i = 0; i < compilationUnit.imports.length; i++) {
2164
- yield this.visit(compilationUnit.imports[i].element, otherCompilationUnit.imports[i].element);
2165
- if (!this.match)
2166
- return compilationUnit;
2167
- }
2168
- // Compare classes
2169
- if (compilationUnit.classes.length !== otherCompilationUnit.classes.length) {
2170
- return this.abort(compilationUnit);
2171
- }
2172
- // Visit each class in lock step
2173
- for (let i = 0; i < compilationUnit.classes.length; i++) {
2174
- yield this.visit(compilationUnit.classes[i], otherCompilationUnit.classes[i]);
2175
- if (!this.match)
2176
- return compilationUnit;
2177
- }
2178
- return compilationUnit;
1100
+ return this.visitElement(compilationUnit, other);
2179
1101
  });
2180
1102
  }
2181
1103
  /**
@@ -2187,19 +1109,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2187
1109
  */
2188
1110
  visitContinue(continueStatement, other) {
2189
1111
  return __awaiter(this, void 0, void 0, function* () {
2190
- if (!this.match || other.kind !== java_1.J.Kind.Continue) {
2191
- return this.abort(continueStatement);
2192
- }
2193
- const otherContinue = other;
2194
- // Compare label presence
2195
- if ((continueStatement.label !== undefined) !== (otherContinue.label !== undefined)) {
2196
- return this.abort(continueStatement);
2197
- }
2198
- // Visit label if it exists
2199
- if (continueStatement.label && otherContinue.label) {
2200
- yield this.visit(continueStatement.label, otherContinue.label);
2201
- }
2202
- return continueStatement;
1112
+ return this.visitElement(continueStatement, other);
2203
1113
  });
2204
1114
  }
2205
1115
  /**
@@ -2211,13 +1121,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2211
1121
  */
2212
1122
  visitControlParentheses(controlParens, other) {
2213
1123
  return __awaiter(this, void 0, void 0, function* () {
2214
- if (!this.match || other.kind !== java_1.J.Kind.ControlParentheses) {
2215
- return this.abort(controlParens);
2216
- }
2217
- const otherControlParens = other;
2218
- // Visit tree
2219
- yield this.visit(controlParens.tree.element, otherControlParens.tree.element);
2220
- return controlParens;
1124
+ return this.visitElement(controlParens, other);
2221
1125
  });
2222
1126
  }
2223
1127
  /**
@@ -2229,25 +1133,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2229
1133
  */
2230
1134
  visitDeconstructionPattern(pattern, other) {
2231
1135
  return __awaiter(this, void 0, void 0, function* () {
2232
- if (!this.match || other.kind !== java_1.J.Kind.DeconstructionPattern) {
2233
- return this.abort(pattern);
2234
- }
2235
- const otherPattern = other;
2236
- // Visit deconstructor
2237
- yield this.visit(pattern.deconstructor, otherPattern.deconstructor);
2238
- if (!this.match)
2239
- return pattern;
2240
- // Compare nested elements
2241
- if (pattern.nested.elements.length !== otherPattern.nested.elements.length) {
2242
- return this.abort(pattern);
2243
- }
2244
- // Visit each nested element in lock step
2245
- for (let i = 0; i < pattern.nested.elements.length; i++) {
2246
- yield this.visit(pattern.nested.elements[i].element, otherPattern.nested.elements[i].element);
2247
- if (!this.match)
2248
- return pattern;
2249
- }
2250
- return pattern;
1136
+ return this.visitElement(pattern, other);
2251
1137
  });
2252
1138
  }
2253
1139
  /**
@@ -2259,17 +1145,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2259
1145
  */
2260
1146
  visitDoWhileLoop(doWhileLoop, other) {
2261
1147
  return __awaiter(this, void 0, void 0, function* () {
2262
- if (!this.match || other.kind !== java_1.J.Kind.DoWhileLoop) {
2263
- return this.abort(doWhileLoop);
2264
- }
2265
- const otherDoWhileLoop = other;
2266
- // Visit body
2267
- yield this.visit(doWhileLoop.body.element, otherDoWhileLoop.body.element);
2268
- if (!this.match)
2269
- return doWhileLoop;
2270
- // Visit while condition
2271
- yield this.visit(doWhileLoop.whileCondition.element, otherDoWhileLoop.whileCondition.element);
2272
- return doWhileLoop;
1148
+ return this.visitElement(doWhileLoop, other);
2273
1149
  });
2274
1150
  }
2275
1151
  /**
@@ -2281,11 +1157,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2281
1157
  */
2282
1158
  visitEmpty(empty, other) {
2283
1159
  return __awaiter(this, void 0, void 0, function* () {
2284
- if (!this.match || other.kind !== java_1.J.Kind.Empty) {
2285
- return this.abort(empty);
2286
- }
2287
- // Empty statements have no properties to compare, so we just check the kind
2288
- return empty;
1160
+ return this.visitElement(empty, other);
2289
1161
  });
2290
1162
  }
2291
1163
  /**
@@ -2297,33 +1169,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2297
1169
  */
2298
1170
  visitEnumValue(enumValue, other) {
2299
1171
  return __awaiter(this, void 0, void 0, function* () {
2300
- if (!this.match || other.kind !== java_1.J.Kind.EnumValue) {
2301
- return this.abort(enumValue);
2302
- }
2303
- const otherEnumValue = other;
2304
- // Compare annotations
2305
- if (enumValue.annotations.length !== otherEnumValue.annotations.length) {
2306
- return this.abort(enumValue);
2307
- }
2308
- // Visit each annotation in lock step
2309
- for (let i = 0; i < enumValue.annotations.length; i++) {
2310
- yield this.visit(enumValue.annotations[i], otherEnumValue.annotations[i]);
2311
- if (!this.match)
2312
- return enumValue;
2313
- }
2314
- // Visit name
2315
- yield this.visit(enumValue.name, otherEnumValue.name);
2316
- if (!this.match)
2317
- return enumValue;
2318
- // Compare initializer presence
2319
- if ((enumValue.initializer !== undefined) !== (otherEnumValue.initializer !== undefined)) {
2320
- return this.abort(enumValue);
2321
- }
2322
- // Visit initializer if it exists
2323
- if (enumValue.initializer && otherEnumValue.initializer) {
2324
- yield this.visit(enumValue.initializer, otherEnumValue.initializer);
2325
- }
2326
- return enumValue;
1172
+ return this.visitElement(enumValue, other);
2327
1173
  });
2328
1174
  }
2329
1175
  /**
@@ -2335,21 +1181,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2335
1181
  */
2336
1182
  visitEnumValueSet(enumValueSet, other) {
2337
1183
  return __awaiter(this, void 0, void 0, function* () {
2338
- if (!this.match || other.kind !== java_1.J.Kind.EnumValueSet) {
2339
- return this.abort(enumValueSet);
2340
- }
2341
- const otherEnumValueSet = other;
2342
- // Compare enums
2343
- if (enumValueSet.enums.length !== otherEnumValueSet.enums.length) {
2344
- return this.abort(enumValueSet);
2345
- }
2346
- // Visit each enum in lock step
2347
- for (let i = 0; i < enumValueSet.enums.length; i++) {
2348
- yield this.visit(enumValueSet.enums[i].element, otherEnumValueSet.enums[i].element);
2349
- if (!this.match)
2350
- return enumValueSet;
2351
- }
2352
- return enumValueSet;
1184
+ return this.visitElement(enumValueSet, other);
2353
1185
  });
2354
1186
  }
2355
1187
  /**
@@ -2361,15 +1193,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2361
1193
  */
2362
1194
  visitErroneous(erroneous, other) {
2363
1195
  return __awaiter(this, void 0, void 0, function* () {
2364
- if (!this.match || other.kind !== java_1.J.Kind.Erroneous) {
2365
- return this.abort(erroneous);
2366
- }
2367
- const otherErroneous = other;
2368
- // Compare text
2369
- if (erroneous.text !== otherErroneous.text) {
2370
- return this.abort(erroneous);
2371
- }
2372
- return erroneous;
1196
+ return this.visitElement(erroneous, other);
2373
1197
  });
2374
1198
  }
2375
1199
  /**
@@ -2381,19 +1205,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2381
1205
  */
2382
1206
  visitFieldAccess(fieldAccess, other) {
2383
1207
  return __awaiter(this, void 0, void 0, function* () {
2384
- if (!this.match || other.kind !== java_1.J.Kind.FieldAccess) {
2385
- return this.abort(fieldAccess);
2386
- }
2387
- const otherFieldAccess = other;
2388
- // Visit target
2389
- yield this.visit(fieldAccess.target, otherFieldAccess.target);
2390
- if (!this.match)
2391
- return fieldAccess;
2392
- // Visit name
2393
- yield this.visit(fieldAccess.name.element, otherFieldAccess.name.element);
2394
- if (!this.match)
2395
- return fieldAccess;
2396
- return fieldAccess;
1208
+ return this.visitElement(fieldAccess, other);
2397
1209
  });
2398
1210
  }
2399
1211
  /**
@@ -2405,19 +1217,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2405
1217
  */
2406
1218
  visitForEachLoop(forEachLoop, other) {
2407
1219
  return __awaiter(this, void 0, void 0, function* () {
2408
- if (!this.match || other.kind !== java_1.J.Kind.ForEachLoop) {
2409
- return this.abort(forEachLoop);
2410
- }
2411
- const otherForEachLoop = other;
2412
- // Visit control
2413
- yield this.visit(forEachLoop.control, otherForEachLoop.control);
2414
- if (!this.match)
2415
- return forEachLoop;
2416
- // Visit body
2417
- yield this.visit(forEachLoop.body.element, otherForEachLoop.body.element);
2418
- if (!this.match)
2419
- return forEachLoop;
2420
- return forEachLoop;
1220
+ return this.visitElement(forEachLoop, other);
2421
1221
  });
2422
1222
  }
2423
1223
  /**
@@ -2429,19 +1229,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2429
1229
  */
2430
1230
  visitForEachLoopControl(control, other) {
2431
1231
  return __awaiter(this, void 0, void 0, function* () {
2432
- if (!this.match || other.kind !== java_1.J.Kind.ForEachLoopControl) {
2433
- return this.abort(control);
2434
- }
2435
- const otherControl = other;
2436
- // Visit variable
2437
- yield this.visit(control.variable.element, otherControl.variable.element);
2438
- if (!this.match)
2439
- return control;
2440
- // Visit iterable
2441
- yield this.visit(control.iterable.element, otherControl.iterable.element);
2442
- if (!this.match)
2443
- return control;
2444
- return control;
1232
+ return this.visitElement(control, other);
2445
1233
  });
2446
1234
  }
2447
1235
  /**
@@ -2453,19 +1241,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2453
1241
  */
2454
1242
  visitForLoop(forLoop, other) {
2455
1243
  return __awaiter(this, void 0, void 0, function* () {
2456
- if (!this.match || other.kind !== java_1.J.Kind.ForLoop) {
2457
- return this.abort(forLoop);
2458
- }
2459
- const otherForLoop = other;
2460
- // Visit control
2461
- yield this.visit(forLoop.control, otherForLoop.control);
2462
- if (!this.match)
2463
- return forLoop;
2464
- // Visit body
2465
- yield this.visit(forLoop.body.element, otherForLoop.body.element);
2466
- if (!this.match)
2467
- return forLoop;
2468
- return forLoop;
1244
+ return this.visitElement(forLoop, other);
2469
1245
  });
2470
1246
  }
2471
1247
  /**
@@ -2477,41 +1253,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2477
1253
  */
2478
1254
  visitForLoopControl(control, other) {
2479
1255
  return __awaiter(this, void 0, void 0, function* () {
2480
- if (!this.match || other.kind !== java_1.J.Kind.ForLoopControl) {
2481
- return this.abort(control);
2482
- }
2483
- const otherControl = other;
2484
- // Compare init statements
2485
- if (control.init.length !== otherControl.init.length) {
2486
- return this.abort(control);
2487
- }
2488
- // Visit each init statement in lock step
2489
- for (let i = 0; i < control.init.length; i++) {
2490
- yield this.visit(control.init[i].element, otherControl.init[i].element);
2491
- if (!this.match)
2492
- return control;
2493
- }
2494
- // Compare condition
2495
- if ((control.condition === undefined) !== (otherControl.condition === undefined)) {
2496
- return this.abort(control);
2497
- }
2498
- // Visit condition if present
2499
- if (control.condition && otherControl.condition) {
2500
- yield this.visit(control.condition.element, otherControl.condition.element);
2501
- if (!this.match)
2502
- return control;
2503
- }
2504
- // Compare update statements
2505
- if (control.update.length !== otherControl.update.length) {
2506
- return this.abort(control);
2507
- }
2508
- // Visit each update statement in lock step
2509
- for (let i = 0; i < control.update.length; i++) {
2510
- yield this.visit(control.update[i].element, otherControl.update[i].element);
2511
- if (!this.match)
2512
- return control;
2513
- }
2514
- return control;
1256
+ return this.visitElement(control, other);
2515
1257
  });
2516
1258
  }
2517
1259
  /**
@@ -2523,29 +1265,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2523
1265
  */
2524
1266
  visitIf(ifStatement, other) {
2525
1267
  return __awaiter(this, void 0, void 0, function* () {
2526
- if (!this.match || other.kind !== java_1.J.Kind.If) {
2527
- return this.abort(ifStatement);
2528
- }
2529
- const otherIfStatement = other;
2530
- // Visit condition
2531
- yield this.visit(ifStatement.ifCondition, otherIfStatement.ifCondition);
2532
- if (!this.match)
2533
- return ifStatement;
2534
- // Visit then part
2535
- yield this.visit(ifStatement.thenPart.element, otherIfStatement.thenPart.element);
2536
- if (!this.match)
2537
- return ifStatement;
2538
- // Compare else part
2539
- if ((ifStatement.elsePart === undefined) !== (otherIfStatement.elsePart === undefined)) {
2540
- return this.abort(ifStatement);
2541
- }
2542
- // Visit else part if present
2543
- if (ifStatement.elsePart && otherIfStatement.elsePart) {
2544
- yield this.visit(ifStatement.elsePart, otherIfStatement.elsePart);
2545
- if (!this.match)
2546
- return ifStatement;
2547
- }
2548
- return ifStatement;
1268
+ return this.visitElement(ifStatement, other);
2549
1269
  });
2550
1270
  }
2551
1271
  /**
@@ -2557,15 +1277,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2557
1277
  */
2558
1278
  visitElse(elseStatement, other) {
2559
1279
  return __awaiter(this, void 0, void 0, function* () {
2560
- if (!this.match || other.kind !== java_1.J.Kind.IfElse) {
2561
- return this.abort(elseStatement);
2562
- }
2563
- const otherElseStatement = other;
2564
- // Visit body
2565
- yield this.visit(elseStatement.body.element, otherElseStatement.body.element);
2566
- if (!this.match)
2567
- return elseStatement;
2568
- return elseStatement;
1280
+ return this.visitElement(elseStatement, other);
2569
1281
  });
2570
1282
  }
2571
1283
  /**
@@ -2577,29 +1289,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2577
1289
  */
2578
1290
  visitImport(importStatement, other) {
2579
1291
  return __awaiter(this, void 0, void 0, function* () {
2580
- if (!this.match || other.kind !== java_1.J.Kind.Import) {
2581
- return this.abort(importStatement);
2582
- }
2583
- const otherImportStatement = other;
2584
- // Compare static
2585
- if (importStatement.static.element !== otherImportStatement.static.element) {
2586
- return this.abort(importStatement);
2587
- }
2588
- // Visit qualid
2589
- yield this.visit(importStatement.qualid, otherImportStatement.qualid);
2590
- if (!this.match)
2591
- return importStatement;
2592
- // Compare alias
2593
- if ((importStatement.alias === undefined) !== (otherImportStatement.alias === undefined)) {
2594
- return this.abort(importStatement);
2595
- }
2596
- // Visit alias if present
2597
- if (importStatement.alias && otherImportStatement.alias) {
2598
- yield this.visit(importStatement.alias.element, otherImportStatement.alias.element);
2599
- if (!this.match)
2600
- return importStatement;
2601
- }
2602
- return importStatement;
1292
+ return this.visitElement(importStatement, other);
2603
1293
  });
2604
1294
  }
2605
1295
  /**
@@ -2611,39 +1301,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2611
1301
  */
2612
1302
  visitInstanceOf(instanceOf, other) {
2613
1303
  return __awaiter(this, void 0, void 0, function* () {
2614
- if (!this.match || other.kind !== java_1.J.Kind.InstanceOf) {
2615
- return this.abort(instanceOf);
2616
- }
2617
- const otherInstanceOf = other;
2618
- // Visit expression
2619
- yield this.visit(instanceOf.expression.element, otherInstanceOf.expression.element);
2620
- if (!this.match)
2621
- return instanceOf;
2622
- // Visit class
2623
- yield this.visit(instanceOf.class, otherInstanceOf.class);
2624
- if (!this.match)
2625
- return instanceOf;
2626
- // Compare pattern
2627
- if ((instanceOf.pattern === undefined) !== (otherInstanceOf.pattern === undefined)) {
2628
- return this.abort(instanceOf);
2629
- }
2630
- // Visit pattern if present
2631
- if (instanceOf.pattern && otherInstanceOf.pattern) {
2632
- yield this.visit(instanceOf.pattern, otherInstanceOf.pattern);
2633
- if (!this.match)
2634
- return instanceOf;
2635
- }
2636
- // Compare modifier
2637
- if ((instanceOf.modifier === undefined) !== (otherInstanceOf.modifier === undefined)) {
2638
- return this.abort(instanceOf);
2639
- }
2640
- // Visit modifier if present
2641
- if (instanceOf.modifier && otherInstanceOf.modifier) {
2642
- yield this.visit(instanceOf.modifier, otherInstanceOf.modifier);
2643
- if (!this.match)
2644
- return instanceOf;
2645
- }
2646
- return instanceOf;
1304
+ return this.visitElement(instanceOf, other);
2647
1305
  });
2648
1306
  }
2649
1307
  /**
@@ -2655,21 +1313,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2655
1313
  */
2656
1314
  visitIntersectionType(intersectionType, other) {
2657
1315
  return __awaiter(this, void 0, void 0, function* () {
2658
- if (!this.match || other.kind !== java_1.J.Kind.IntersectionType) {
2659
- return this.abort(intersectionType);
2660
- }
2661
- const otherIntersectionType = other;
2662
- // Compare bounds
2663
- if (intersectionType.bounds.elements.length !== otherIntersectionType.bounds.elements.length) {
2664
- return this.abort(intersectionType);
2665
- }
2666
- // Visit each bound in lock step
2667
- for (let i = 0; i < intersectionType.bounds.elements.length; i++) {
2668
- yield this.visit(intersectionType.bounds.elements[i].element, otherIntersectionType.bounds.elements[i].element);
2669
- if (!this.match)
2670
- return intersectionType;
2671
- }
2672
- return intersectionType;
1316
+ return this.visitElement(intersectionType, other);
2673
1317
  });
2674
1318
  }
2675
1319
  /**
@@ -2681,19 +1325,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2681
1325
  */
2682
1326
  visitLabel(label, other) {
2683
1327
  return __awaiter(this, void 0, void 0, function* () {
2684
- if (!this.match || other.kind !== java_1.J.Kind.Label) {
2685
- return this.abort(label);
2686
- }
2687
- const otherLabel = other;
2688
- // Visit label identifier
2689
- yield this.visit(label.label.element, otherLabel.label.element);
2690
- if (!this.match)
2691
- return label;
2692
- // Visit statement
2693
- yield this.visit(label.statement, otherLabel.statement);
2694
- if (!this.match)
2695
- return label;
2696
- return label;
1328
+ return this.visitElement(label, other);
2697
1329
  });
2698
1330
  }
2699
1331
  /**
@@ -2705,19 +1337,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2705
1337
  */
2706
1338
  visitLambda(lambda, other) {
2707
1339
  return __awaiter(this, void 0, void 0, function* () {
2708
- if (!this.match || other.kind !== java_1.J.Kind.Lambda) {
2709
- return this.abort(lambda);
2710
- }
2711
- const otherLambda = other;
2712
- // Visit parameters
2713
- yield this.visit(lambda.parameters, otherLambda.parameters);
2714
- if (!this.match)
2715
- return lambda;
2716
- // Visit body
2717
- yield this.visit(lambda.body, otherLambda.body);
2718
- if (!this.match)
2719
- return lambda;
2720
- return lambda;
1340
+ return this.visitElement(lambda, other);
2721
1341
  });
2722
1342
  }
2723
1343
  /**
@@ -2729,25 +1349,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2729
1349
  */
2730
1350
  visitLambdaParameters(parameters, other) {
2731
1351
  return __awaiter(this, void 0, void 0, function* () {
2732
- if (!this.match || other.kind !== java_1.J.Kind.LambdaParameters) {
2733
- return this.abort(parameters);
2734
- }
2735
- const otherParameters = other;
2736
- // Compare parenthesized
2737
- if (parameters.parenthesized !== otherParameters.parenthesized) {
2738
- return this.abort(parameters);
2739
- }
2740
- // Compare parameters
2741
- if (parameters.parameters.length !== otherParameters.parameters.length) {
2742
- return this.abort(parameters);
2743
- }
2744
- // Visit each parameter in lock step
2745
- for (let i = 0; i < parameters.parameters.length; i++) {
2746
- yield this.visit(parameters.parameters[i].element, otherParameters.parameters[i].element);
2747
- if (!this.match)
2748
- return parameters;
2749
- }
2750
- return parameters;
1352
+ return this.visitElement(parameters, other);
2751
1353
  });
2752
1354
  }
2753
1355
  /**
@@ -2759,35 +1361,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2759
1361
  */
2760
1362
  visitMemberReference(memberReference, other) {
2761
1363
  return __awaiter(this, void 0, void 0, function* () {
2762
- if (!this.match || other.kind !== java_1.J.Kind.MemberReference) {
2763
- return this.abort(memberReference);
2764
- }
2765
- const otherMemberReference = other;
2766
- // Visit containing
2767
- yield this.visit(memberReference.containing.element, otherMemberReference.containing.element);
2768
- if (!this.match)
2769
- return memberReference;
2770
- // Compare typeParameters
2771
- if ((memberReference.typeParameters === undefined) !== (otherMemberReference.typeParameters === undefined)) {
2772
- return this.abort(memberReference);
2773
- }
2774
- // Visit typeParameters if present
2775
- if (memberReference.typeParameters && otherMemberReference.typeParameters) {
2776
- if (memberReference.typeParameters.elements.length !== otherMemberReference.typeParameters.elements.length) {
2777
- return this.abort(memberReference);
2778
- }
2779
- // Visit each type parameter in lock step
2780
- for (let i = 0; i < memberReference.typeParameters.elements.length; i++) {
2781
- yield this.visit(memberReference.typeParameters.elements[i].element, otherMemberReference.typeParameters.elements[i].element);
2782
- if (!this.match)
2783
- return memberReference;
2784
- }
2785
- }
2786
- // Visit reference
2787
- yield this.visit(memberReference.reference.element, otherMemberReference.reference.element);
2788
- if (!this.match)
2789
- return memberReference;
2790
- return memberReference;
1364
+ return this.visitElement(memberReference, other);
2791
1365
  });
2792
1366
  }
2793
1367
  /**
@@ -2799,111 +1373,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2799
1373
  */
2800
1374
  visitMethodDeclaration(methodDeclaration, other) {
2801
1375
  return __awaiter(this, void 0, void 0, function* () {
2802
- if (!this.match || other.kind !== java_1.J.Kind.MethodDeclaration) {
2803
- return this.abort(methodDeclaration);
2804
- }
2805
- const otherMethodDeclaration = other;
2806
- // Compare leadingAnnotations
2807
- if (methodDeclaration.leadingAnnotations.length !== otherMethodDeclaration.leadingAnnotations.length) {
2808
- return this.abort(methodDeclaration);
2809
- }
2810
- // Visit each leading annotation in lock step
2811
- for (let i = 0; i < methodDeclaration.leadingAnnotations.length; i++) {
2812
- yield this.visit(methodDeclaration.leadingAnnotations[i], otherMethodDeclaration.leadingAnnotations[i]);
2813
- if (!this.match)
2814
- return methodDeclaration;
2815
- }
2816
- // Compare modifiers
2817
- if (methodDeclaration.modifiers.length !== otherMethodDeclaration.modifiers.length) {
2818
- return this.abort(methodDeclaration);
2819
- }
2820
- // Visit each modifier in lock step
2821
- for (let i = 0; i < methodDeclaration.modifiers.length; i++) {
2822
- yield this.visit(methodDeclaration.modifiers[i], otherMethodDeclaration.modifiers[i]);
2823
- if (!this.match)
2824
- return methodDeclaration;
2825
- }
2826
- // Compare typeParameters
2827
- if ((methodDeclaration.typeParameters === undefined) !== (otherMethodDeclaration.typeParameters === undefined)) {
2828
- return this.abort(methodDeclaration);
2829
- }
2830
- // Visit typeParameters if present
2831
- if (methodDeclaration.typeParameters && otherMethodDeclaration.typeParameters) {
2832
- yield this.visit(methodDeclaration.typeParameters, otherMethodDeclaration.typeParameters);
2833
- if (!this.match)
2834
- return methodDeclaration;
2835
- }
2836
- // Compare returnTypeExpression
2837
- if ((methodDeclaration.returnTypeExpression === undefined) !== (otherMethodDeclaration.returnTypeExpression === undefined)) {
2838
- return this.abort(methodDeclaration);
2839
- }
2840
- // Visit returnTypeExpression if present
2841
- if (methodDeclaration.returnTypeExpression && otherMethodDeclaration.returnTypeExpression) {
2842
- yield this.visit(methodDeclaration.returnTypeExpression, otherMethodDeclaration.returnTypeExpression);
2843
- if (!this.match)
2844
- return methodDeclaration;
2845
- }
2846
- // Compare nameAnnotations
2847
- if (methodDeclaration.nameAnnotations.length !== otherMethodDeclaration.nameAnnotations.length) {
2848
- return this.abort(methodDeclaration);
2849
- }
2850
- // Visit each name annotation in lock step
2851
- for (let i = 0; i < methodDeclaration.nameAnnotations.length; i++) {
2852
- yield this.visit(methodDeclaration.nameAnnotations[i], otherMethodDeclaration.nameAnnotations[i]);
2853
- if (!this.match)
2854
- return methodDeclaration;
2855
- }
2856
- // Visit name
2857
- yield this.visit(methodDeclaration.name, otherMethodDeclaration.name);
2858
- if (!this.match)
2859
- return methodDeclaration;
2860
- // Compare parameters
2861
- if (methodDeclaration.parameters.elements.length !== otherMethodDeclaration.parameters.elements.length) {
2862
- return this.abort(methodDeclaration);
2863
- }
2864
- // Visit each parameter in lock step
2865
- for (let i = 0; i < methodDeclaration.parameters.elements.length; i++) {
2866
- yield this.visit(methodDeclaration.parameters.elements[i].element, otherMethodDeclaration.parameters.elements[i].element);
2867
- if (!this.match)
2868
- return methodDeclaration;
2869
- }
2870
- // Compare throws
2871
- if ((methodDeclaration.throws === undefined) !== (otherMethodDeclaration.throws === undefined)) {
2872
- return this.abort(methodDeclaration);
2873
- }
2874
- // Visit throws if present
2875
- if (methodDeclaration.throws && otherMethodDeclaration.throws) {
2876
- if (methodDeclaration.throws.elements.length !== otherMethodDeclaration.throws.elements.length) {
2877
- return this.abort(methodDeclaration);
2878
- }
2879
- // Visit each throw in lock step
2880
- for (let i = 0; i < methodDeclaration.throws.elements.length; i++) {
2881
- yield this.visit(methodDeclaration.throws.elements[i].element, otherMethodDeclaration.throws.elements[i].element);
2882
- if (!this.match)
2883
- return methodDeclaration;
2884
- }
2885
- }
2886
- // Compare body
2887
- if ((methodDeclaration.body === undefined) !== (otherMethodDeclaration.body === undefined)) {
2888
- return this.abort(methodDeclaration);
2889
- }
2890
- // Visit body if present
2891
- if (methodDeclaration.body && otherMethodDeclaration.body) {
2892
- yield this.visit(methodDeclaration.body, otherMethodDeclaration.body);
2893
- if (!this.match)
2894
- return methodDeclaration;
2895
- }
2896
- // Compare defaultValue
2897
- if ((methodDeclaration.defaultValue === undefined) !== (otherMethodDeclaration.defaultValue === undefined)) {
2898
- return this.abort(methodDeclaration);
2899
- }
2900
- // Visit defaultValue if present
2901
- if (methodDeclaration.defaultValue && otherMethodDeclaration.defaultValue) {
2902
- yield this.visit(methodDeclaration.defaultValue.element, otherMethodDeclaration.defaultValue.element);
2903
- if (!this.match)
2904
- return methodDeclaration;
2905
- }
2906
- return methodDeclaration;
1376
+ return this.visitElement(methodDeclaration, other);
2907
1377
  });
2908
1378
  }
2909
1379
  /**
@@ -2915,51 +1385,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2915
1385
  */
2916
1386
  visitMethodInvocation(methodInvocation, other) {
2917
1387
  return __awaiter(this, void 0, void 0, function* () {
2918
- if (!this.match || other.kind !== java_1.J.Kind.MethodInvocation) {
2919
- return this.abort(methodInvocation);
2920
- }
2921
- const otherMethodInvocation = other;
2922
- // Compare select
2923
- if ((methodInvocation.select === undefined) !== (otherMethodInvocation.select === undefined)) {
2924
- return this.abort(methodInvocation);
2925
- }
2926
- // Visit select if present
2927
- if (methodInvocation.select && otherMethodInvocation.select) {
2928
- yield this.visit(methodInvocation.select.element, otherMethodInvocation.select.element);
2929
- if (!this.match)
2930
- return methodInvocation;
2931
- }
2932
- // Compare typeParameters
2933
- if ((methodInvocation.typeParameters === undefined) !== (otherMethodInvocation.typeParameters === undefined)) {
2934
- return this.abort(methodInvocation);
2935
- }
2936
- // Visit typeParameters if present
2937
- if (methodInvocation.typeParameters && otherMethodInvocation.typeParameters) {
2938
- if (methodInvocation.typeParameters.elements.length !== otherMethodInvocation.typeParameters.elements.length) {
2939
- return this.abort(methodInvocation);
2940
- }
2941
- // Visit each type parameter in lock step
2942
- for (let i = 0; i < methodInvocation.typeParameters.elements.length; i++) {
2943
- yield this.visit(methodInvocation.typeParameters.elements[i].element, otherMethodInvocation.typeParameters.elements[i].element);
2944
- if (!this.match)
2945
- return methodInvocation;
2946
- }
2947
- }
2948
- // Visit name
2949
- yield this.visit(methodInvocation.name, otherMethodInvocation.name);
2950
- if (!this.match)
2951
- return methodInvocation;
2952
- // Compare arguments
2953
- if (methodInvocation.arguments.elements.length !== otherMethodInvocation.arguments.elements.length) {
2954
- return this.abort(methodInvocation);
2955
- }
2956
- // Visit each argument in lock step
2957
- for (let i = 0; i < methodInvocation.arguments.elements.length; i++) {
2958
- yield this.visit(methodInvocation.arguments.elements[i].element, otherMethodInvocation.arguments.elements[i].element);
2959
- if (!this.match)
2960
- return methodInvocation;
2961
- }
2962
- return methodInvocation;
1388
+ return this.visitElement(methodInvocation, other);
2963
1389
  });
2964
1390
  }
2965
1391
  /**
@@ -2971,29 +1397,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
2971
1397
  */
2972
1398
  visitModifier(modifier, other) {
2973
1399
  return __awaiter(this, void 0, void 0, function* () {
2974
- if (!this.match || other.kind !== java_1.J.Kind.Modifier) {
2975
- return this.abort(modifier);
2976
- }
2977
- const otherModifier = other;
2978
- // Compare keyword
2979
- if (modifier.keyword !== otherModifier.keyword) {
2980
- return this.abort(modifier);
2981
- }
2982
- // Compare type
2983
- if (modifier.type !== otherModifier.type) {
2984
- return this.abort(modifier);
2985
- }
2986
- // Compare annotations
2987
- if (modifier.annotations.length !== otherModifier.annotations.length) {
2988
- return this.abort(modifier);
2989
- }
2990
- // Visit each annotation in lock step
2991
- for (let i = 0; i < modifier.annotations.length; i++) {
2992
- yield this.visit(modifier.annotations[i], otherModifier.annotations[i]);
2993
- if (!this.match)
2994
- return modifier;
2995
- }
2996
- return modifier;
1400
+ return this.visitElement(modifier, other);
2997
1401
  });
2998
1402
  }
2999
1403
  /**
@@ -3005,21 +1409,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3005
1409
  */
3006
1410
  visitMultiCatch(multiCatch, other) {
3007
1411
  return __awaiter(this, void 0, void 0, function* () {
3008
- if (!this.match || other.kind !== java_1.J.Kind.MultiCatch) {
3009
- return this.abort(multiCatch);
3010
- }
3011
- const otherMultiCatch = other;
3012
- // Compare alternatives
3013
- if (multiCatch.alternatives.length !== otherMultiCatch.alternatives.length) {
3014
- return this.abort(multiCatch);
3015
- }
3016
- // Visit each alternative in lock step
3017
- for (let i = 0; i < multiCatch.alternatives.length; i++) {
3018
- yield this.visit(multiCatch.alternatives[i].element, otherMultiCatch.alternatives[i].element);
3019
- if (!this.match)
3020
- return multiCatch;
3021
- }
3022
- return multiCatch;
1412
+ return this.visitElement(multiCatch, other);
3023
1413
  });
3024
1414
  }
3025
1415
  /**
@@ -3031,47 +1421,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3031
1421
  */
3032
1422
  visitNewArray(newArray, other) {
3033
1423
  return __awaiter(this, void 0, void 0, function* () {
3034
- if (!this.match || other.kind !== java_1.J.Kind.NewArray) {
3035
- return this.abort(newArray);
3036
- }
3037
- const otherNewArray = other;
3038
- // Compare typeExpression
3039
- if ((newArray.typeExpression === undefined) !== (otherNewArray.typeExpression === undefined)) {
3040
- return this.abort(newArray);
3041
- }
3042
- // Visit typeExpression if present
3043
- if (newArray.typeExpression && otherNewArray.typeExpression) {
3044
- yield this.visit(newArray.typeExpression, otherNewArray.typeExpression);
3045
- if (!this.match)
3046
- return newArray;
3047
- }
3048
- // Compare dimensions
3049
- if (newArray.dimensions.length !== otherNewArray.dimensions.length) {
3050
- return this.abort(newArray);
3051
- }
3052
- // Visit each dimension in lock step
3053
- for (let i = 0; i < newArray.dimensions.length; i++) {
3054
- yield this.visit(newArray.dimensions[i], otherNewArray.dimensions[i]);
3055
- if (!this.match)
3056
- return newArray;
3057
- }
3058
- // Compare initializer
3059
- if ((newArray.initializer === undefined) !== (otherNewArray.initializer === undefined)) {
3060
- return this.abort(newArray);
3061
- }
3062
- // Visit initializer if present
3063
- if (newArray.initializer && otherNewArray.initializer) {
3064
- if (newArray.initializer.elements.length !== otherNewArray.initializer.elements.length) {
3065
- return this.abort(newArray);
3066
- }
3067
- // Visit each initializer element in lock step
3068
- for (let i = 0; i < newArray.initializer.elements.length; i++) {
3069
- yield this.visit(newArray.initializer.elements[i].element, otherNewArray.initializer.elements[i].element);
3070
- if (!this.match)
3071
- return newArray;
3072
- }
3073
- }
3074
- return newArray;
1424
+ return this.visitElement(newArray, other);
3075
1425
  });
3076
1426
  }
3077
1427
  /**
@@ -3083,51 +1433,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3083
1433
  */
3084
1434
  visitNewClass(newClass, other) {
3085
1435
  return __awaiter(this, void 0, void 0, function* () {
3086
- if (!this.match || other.kind !== java_1.J.Kind.NewClass) {
3087
- return this.abort(newClass);
3088
- }
3089
- const otherNewClass = other;
3090
- // Compare enclosing
3091
- if ((newClass.enclosing === undefined) !== (otherNewClass.enclosing === undefined)) {
3092
- return this.abort(newClass);
3093
- }
3094
- // Visit enclosing if present
3095
- if (newClass.enclosing && otherNewClass.enclosing) {
3096
- yield this.visit(newClass.enclosing.element, otherNewClass.enclosing.element);
3097
- if (!this.match)
3098
- return newClass;
3099
- }
3100
- // Compare class
3101
- if ((newClass.class === undefined) !== (otherNewClass.class === undefined)) {
3102
- return this.abort(newClass);
3103
- }
3104
- // Visit class if present
3105
- if (newClass.class && otherNewClass.class) {
3106
- yield this.visit(newClass.class, otherNewClass.class);
3107
- if (!this.match)
3108
- return newClass;
3109
- }
3110
- // Compare arguments
3111
- if (newClass.arguments.elements.length !== otherNewClass.arguments.elements.length) {
3112
- return this.abort(newClass);
3113
- }
3114
- // Visit each argument in lock step
3115
- for (let i = 0; i < newClass.arguments.elements.length; i++) {
3116
- yield this.visit(newClass.arguments.elements[i].element, otherNewClass.arguments.elements[i].element);
3117
- if (!this.match)
3118
- return newClass;
3119
- }
3120
- // Compare body
3121
- if ((newClass.body === undefined) !== (otherNewClass.body === undefined)) {
3122
- return this.abort(newClass);
3123
- }
3124
- // Visit body if present
3125
- if (newClass.body && otherNewClass.body) {
3126
- yield this.visit(newClass.body, otherNewClass.body);
3127
- if (!this.match)
3128
- return newClass;
3129
- }
3130
- return newClass;
1436
+ return this.visitElement(newClass, other);
3131
1437
  });
3132
1438
  }
3133
1439
  /**
@@ -3139,25 +1445,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3139
1445
  */
3140
1446
  visitNullableType(nullableType, other) {
3141
1447
  return __awaiter(this, void 0, void 0, function* () {
3142
- if (!this.match || other.kind !== java_1.J.Kind.NullableType) {
3143
- return this.abort(nullableType);
3144
- }
3145
- const otherNullableType = other;
3146
- // Compare annotations
3147
- if (nullableType.annotations.length !== otherNullableType.annotations.length) {
3148
- return this.abort(nullableType);
3149
- }
3150
- // Visit each annotation in lock step
3151
- for (let i = 0; i < nullableType.annotations.length; i++) {
3152
- yield this.visit(nullableType.annotations[i], otherNullableType.annotations[i]);
3153
- if (!this.match)
3154
- return nullableType;
3155
- }
3156
- // Visit typeTree
3157
- yield this.visit(nullableType.typeTree.element, otherNullableType.typeTree.element);
3158
- if (!this.match)
3159
- return nullableType;
3160
- return nullableType;
1448
+ return this.visitElement(nullableType, other);
3161
1449
  });
3162
1450
  }
3163
1451
  /**
@@ -3169,31 +1457,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3169
1457
  */
3170
1458
  visitPackage(packageDeclaration, other) {
3171
1459
  return __awaiter(this, void 0, void 0, function* () {
3172
- if (!this.match || other.kind !== java_1.J.Kind.Package) {
3173
- return this.abort(packageDeclaration);
3174
- }
3175
- const otherPackageDeclaration = other;
3176
- // Visit expression
3177
- yield this.visit(packageDeclaration.expression, otherPackageDeclaration.expression);
3178
- if (!this.match)
3179
- return packageDeclaration;
3180
- // Compare annotations
3181
- if ((packageDeclaration.annotations === undefined) !== (otherPackageDeclaration.annotations === undefined)) {
3182
- return this.abort(packageDeclaration);
3183
- }
3184
- // Visit annotations if present
3185
- if (packageDeclaration.annotations && otherPackageDeclaration.annotations) {
3186
- if (packageDeclaration.annotations.length !== otherPackageDeclaration.annotations.length) {
3187
- return this.abort(packageDeclaration);
3188
- }
3189
- // Visit each annotation in lock step
3190
- for (let i = 0; i < packageDeclaration.annotations.length; i++) {
3191
- yield this.visit(packageDeclaration.annotations[i], otherPackageDeclaration.annotations[i]);
3192
- if (!this.match)
3193
- return packageDeclaration;
3194
- }
3195
- }
3196
- return packageDeclaration;
1460
+ return this.visitElement(packageDeclaration, other);
3197
1461
  });
3198
1462
  }
3199
1463
  /**
@@ -3205,31 +1469,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3205
1469
  */
3206
1470
  visitParameterizedType(parameterizedType, other) {
3207
1471
  return __awaiter(this, void 0, void 0, function* () {
3208
- if (!this.match || other.kind !== java_1.J.Kind.ParameterizedType) {
3209
- return this.abort(parameterizedType);
3210
- }
3211
- const otherParameterizedType = other;
3212
- // Visit class
3213
- yield this.visit(parameterizedType.class, otherParameterizedType.class);
3214
- if (!this.match)
3215
- return parameterizedType;
3216
- // Compare typeParameters
3217
- if ((parameterizedType.typeParameters === undefined) !== (otherParameterizedType.typeParameters === undefined)) {
3218
- return this.abort(parameterizedType);
3219
- }
3220
- // Visit typeParameters if present
3221
- if (parameterizedType.typeParameters && otherParameterizedType.typeParameters) {
3222
- if (parameterizedType.typeParameters.elements.length !== otherParameterizedType.typeParameters.elements.length) {
3223
- return this.abort(parameterizedType);
3224
- }
3225
- // Visit each type parameter in lock step
3226
- for (let i = 0; i < parameterizedType.typeParameters.elements.length; i++) {
3227
- yield this.visit(parameterizedType.typeParameters.elements[i].element, otherParameterizedType.typeParameters.elements[i].element);
3228
- if (!this.match)
3229
- return parameterizedType;
3230
- }
3231
- }
3232
- return parameterizedType;
1472
+ return this.visitElement(parameterizedType, other);
3233
1473
  });
3234
1474
  }
3235
1475
  /**
@@ -3241,15 +1481,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3241
1481
  */
3242
1482
  visitParentheses(parentheses, other) {
3243
1483
  return __awaiter(this, void 0, void 0, function* () {
3244
- if (!this.match || other.kind !== java_1.J.Kind.Parentheses) {
3245
- return this.abort(parentheses);
3246
- }
3247
- const otherParentheses = other;
3248
- // Visit tree
3249
- yield this.visit(parentheses.tree.element, otherParentheses.tree.element);
3250
- if (!this.match)
3251
- return parentheses;
3252
- return parentheses;
1484
+ return this.visitElement(parentheses, other);
3253
1485
  });
3254
1486
  }
3255
1487
  /**
@@ -3261,25 +1493,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3261
1493
  */
3262
1494
  visitParenthesizedTypeTree(parenthesizedTypeTree, other) {
3263
1495
  return __awaiter(this, void 0, void 0, function* () {
3264
- if (!this.match || other.kind !== java_1.J.Kind.ParenthesizedTypeTree) {
3265
- return this.abort(parenthesizedTypeTree);
3266
- }
3267
- const otherParenthesizedTypeTree = other;
3268
- // Compare annotations
3269
- if (parenthesizedTypeTree.annotations.length !== otherParenthesizedTypeTree.annotations.length) {
3270
- return this.abort(parenthesizedTypeTree);
3271
- }
3272
- // Visit each annotation in lock step
3273
- for (let i = 0; i < parenthesizedTypeTree.annotations.length; i++) {
3274
- yield this.visit(parenthesizedTypeTree.annotations[i], otherParenthesizedTypeTree.annotations[i]);
3275
- if (!this.match)
3276
- return parenthesizedTypeTree;
3277
- }
3278
- // Visit parenthesizedType
3279
- yield this.visit(parenthesizedTypeTree.parenthesizedType, otherParenthesizedTypeTree.parenthesizedType);
3280
- if (!this.match)
3281
- return parenthesizedTypeTree;
3282
- return parenthesizedTypeTree;
1496
+ return this.visitElement(parenthesizedTypeTree, other);
3283
1497
  });
3284
1498
  }
3285
1499
  /**
@@ -3291,15 +1505,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3291
1505
  */
3292
1506
  visitPrimitive(primitive, other) {
3293
1507
  return __awaiter(this, void 0, void 0, function* () {
3294
- if (!this.match || other.kind !== java_1.J.Kind.Primitive) {
3295
- return this.abort(primitive);
3296
- }
3297
- const otherPrimitive = other;
3298
- // Compare type
3299
- if (primitive.type.kind !== otherPrimitive.type.kind) {
3300
- return this.abort(primitive);
3301
- }
3302
- return primitive;
1508
+ return this.visitElement(primitive, other);
3303
1509
  });
3304
1510
  }
3305
1511
  /**
@@ -3311,21 +1517,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3311
1517
  */
3312
1518
  visitReturn(returnStatement, other) {
3313
1519
  return __awaiter(this, void 0, void 0, function* () {
3314
- if (!this.match || other.kind !== java_1.J.Kind.Return) {
3315
- return this.abort(returnStatement);
3316
- }
3317
- const otherReturnStatement = other;
3318
- // Compare expression
3319
- if ((returnStatement.expression === undefined) !== (otherReturnStatement.expression === undefined)) {
3320
- return this.abort(returnStatement);
3321
- }
3322
- // Visit expression if present
3323
- if (returnStatement.expression && otherReturnStatement.expression) {
3324
- yield this.visit(returnStatement.expression, otherReturnStatement.expression);
3325
- if (!this.match)
3326
- return returnStatement;
3327
- }
3328
- return returnStatement;
1520
+ return this.visitElement(returnStatement, other);
3329
1521
  });
3330
1522
  }
3331
1523
  /**
@@ -3337,19 +1529,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3337
1529
  */
3338
1530
  visitSwitch(switchStatement, other) {
3339
1531
  return __awaiter(this, void 0, void 0, function* () {
3340
- if (!this.match || other.kind !== java_1.J.Kind.Switch) {
3341
- return this.abort(switchStatement);
3342
- }
3343
- const otherSwitchStatement = other;
3344
- // Visit selector
3345
- yield this.visit(switchStatement.selector, otherSwitchStatement.selector);
3346
- if (!this.match)
3347
- return switchStatement;
3348
- // Visit cases
3349
- yield this.visit(switchStatement.cases, otherSwitchStatement.cases);
3350
- if (!this.match)
3351
- return switchStatement;
3352
- return switchStatement;
1532
+ return this.visitElement(switchStatement, other);
3353
1533
  });
3354
1534
  }
3355
1535
  /**
@@ -3361,19 +1541,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3361
1541
  */
3362
1542
  visitSwitchExpression(switchExpression, other) {
3363
1543
  return __awaiter(this, void 0, void 0, function* () {
3364
- if (!this.match || other.kind !== java_1.J.Kind.SwitchExpression) {
3365
- return this.abort(switchExpression);
3366
- }
3367
- const otherSwitchExpression = other;
3368
- // Visit selector
3369
- yield this.visit(switchExpression.selector, otherSwitchExpression.selector);
3370
- if (!this.match)
3371
- return switchExpression;
3372
- // Visit cases
3373
- yield this.visit(switchExpression.cases, otherSwitchExpression.cases);
3374
- if (!this.match)
3375
- return switchExpression;
3376
- return switchExpression;
1544
+ return this.visitElement(switchExpression, other);
3377
1545
  });
3378
1546
  }
3379
1547
  /**
@@ -3385,19 +1553,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3385
1553
  */
3386
1554
  visitSynchronized(synchronizedStatement, other) {
3387
1555
  return __awaiter(this, void 0, void 0, function* () {
3388
- if (!this.match || other.kind !== java_1.J.Kind.Synchronized) {
3389
- return this.abort(synchronizedStatement);
3390
- }
3391
- const otherSynchronizedStatement = other;
3392
- // Visit lock
3393
- yield this.visit(synchronizedStatement.lock, otherSynchronizedStatement.lock);
3394
- if (!this.match)
3395
- return synchronizedStatement;
3396
- // Visit body
3397
- yield this.visit(synchronizedStatement.body, otherSynchronizedStatement.body);
3398
- if (!this.match)
3399
- return synchronizedStatement;
3400
- return synchronizedStatement;
1556
+ return this.visitElement(synchronizedStatement, other);
3401
1557
  });
3402
1558
  }
3403
1559
  /**
@@ -3409,23 +1565,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3409
1565
  */
3410
1566
  visitTernary(ternary, other) {
3411
1567
  return __awaiter(this, void 0, void 0, function* () {
3412
- if (!this.match || other.kind !== java_1.J.Kind.Ternary) {
3413
- return this.abort(ternary);
3414
- }
3415
- const otherTernary = other;
3416
- // Visit condition
3417
- yield this.visit(ternary.condition, otherTernary.condition);
3418
- if (!this.match)
3419
- return ternary;
3420
- // Visit truePart
3421
- yield this.visit(ternary.truePart.element, otherTernary.truePart.element);
3422
- if (!this.match)
3423
- return ternary;
3424
- // Visit falsePart
3425
- yield this.visit(ternary.falsePart.element, otherTernary.falsePart.element);
3426
- if (!this.match)
3427
- return ternary;
3428
- return ternary;
1568
+ return this.visitElement(ternary, other);
3429
1569
  });
3430
1570
  }
3431
1571
  /**
@@ -3437,15 +1577,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3437
1577
  */
3438
1578
  visitThrow(throwStatement, other) {
3439
1579
  return __awaiter(this, void 0, void 0, function* () {
3440
- if (!this.match || other.kind !== java_1.J.Kind.Throw) {
3441
- return this.abort(throwStatement);
3442
- }
3443
- const otherThrowStatement = other;
3444
- // Visit exception
3445
- yield this.visit(throwStatement.exception, otherThrowStatement.exception);
3446
- if (!this.match)
3447
- return throwStatement;
3448
- return throwStatement;
1580
+ return this.visitElement(throwStatement, other);
3449
1581
  });
3450
1582
  }
3451
1583
  /**
@@ -3457,51 +1589,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3457
1589
  */
3458
1590
  visitTry(tryStatement, other) {
3459
1591
  return __awaiter(this, void 0, void 0, function* () {
3460
- if (!this.match || other.kind !== java_1.J.Kind.Try) {
3461
- return this.abort(tryStatement);
3462
- }
3463
- const otherTryStatement = other;
3464
- // Compare resources
3465
- if ((tryStatement.resources === undefined) !== (otherTryStatement.resources === undefined)) {
3466
- return this.abort(tryStatement);
3467
- }
3468
- // Visit resources if present
3469
- if (tryStatement.resources && otherTryStatement.resources) {
3470
- if (tryStatement.resources.elements.length !== otherTryStatement.resources.elements.length) {
3471
- return this.abort(tryStatement);
3472
- }
3473
- // Visit each resource in lock step
3474
- for (let i = 0; i < tryStatement.resources.elements.length; i++) {
3475
- yield this.visit(tryStatement.resources.elements[i].element, otherTryStatement.resources.elements[i].element);
3476
- if (!this.match)
3477
- return tryStatement;
3478
- }
3479
- }
3480
- // Visit body
3481
- yield this.visit(tryStatement.body, otherTryStatement.body);
3482
- if (!this.match)
3483
- return tryStatement;
3484
- // Compare catches
3485
- if (tryStatement.catches.length !== otherTryStatement.catches.length) {
3486
- return this.abort(tryStatement);
3487
- }
3488
- // Visit each catch in lock step
3489
- for (let i = 0; i < tryStatement.catches.length; i++) {
3490
- yield this.visit(tryStatement.catches[i], otherTryStatement.catches[i]);
3491
- if (!this.match)
3492
- return tryStatement;
3493
- }
3494
- // Compare finally
3495
- if ((tryStatement.finally === undefined) !== (otherTryStatement.finally === undefined)) {
3496
- return this.abort(tryStatement);
3497
- }
3498
- // Visit finally if present
3499
- if (tryStatement.finally && otherTryStatement.finally) {
3500
- yield this.visit(tryStatement.finally.element, otherTryStatement.finally.element);
3501
- if (!this.match)
3502
- return tryStatement;
3503
- }
3504
- return tryStatement;
1592
+ return this.visitElement(tryStatement, other);
3505
1593
  });
3506
1594
  }
3507
1595
  /**
@@ -3513,19 +1601,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3513
1601
  */
3514
1602
  visitTryResource(resource, other) {
3515
1603
  return __awaiter(this, void 0, void 0, function* () {
3516
- if (!this.match || other.kind !== java_1.J.Kind.TryResource) {
3517
- return this.abort(resource);
3518
- }
3519
- const otherResource = other;
3520
- // Visit variableDeclarations
3521
- yield this.visit(resource.variableDeclarations, otherResource.variableDeclarations);
3522
- if (!this.match)
3523
- return resource;
3524
- // Compare terminatedWithSemicolon
3525
- if (resource.terminatedWithSemicolon !== otherResource.terminatedWithSemicolon) {
3526
- return this.abort(resource);
3527
- }
3528
- return resource;
1604
+ return this.visitElement(resource, other);
3529
1605
  });
3530
1606
  }
3531
1607
  /**
@@ -3537,19 +1613,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3537
1613
  */
3538
1614
  visitTryCatch(tryCatch, other) {
3539
1615
  return __awaiter(this, void 0, void 0, function* () {
3540
- if (!this.match || other.kind !== java_1.J.Kind.TryCatch) {
3541
- return this.abort(tryCatch);
3542
- }
3543
- const otherTryCatch = other;
3544
- // Visit parameter
3545
- yield this.visit(tryCatch.parameter, otherTryCatch.parameter);
3546
- if (!this.match)
3547
- return tryCatch;
3548
- // Visit body
3549
- yield this.visit(tryCatch.body, otherTryCatch.body);
3550
- if (!this.match)
3551
- return tryCatch;
3552
- return tryCatch;
1616
+ return this.visitElement(tryCatch, other);
3553
1617
  });
3554
1618
  }
3555
1619
  /**
@@ -3561,19 +1625,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3561
1625
  */
3562
1626
  visitTypeCast(typeCast, other) {
3563
1627
  return __awaiter(this, void 0, void 0, function* () {
3564
- if (!this.match || other.kind !== java_1.J.Kind.TypeCast) {
3565
- return this.abort(typeCast);
3566
- }
3567
- const otherTypeCast = other;
3568
- // Visit class
3569
- yield this.visit(typeCast.class, otherTypeCast.class);
3570
- if (!this.match)
3571
- return typeCast;
3572
- // Visit expression
3573
- yield this.visit(typeCast.expression, otherTypeCast.expression);
3574
- if (!this.match)
3575
- return typeCast;
3576
- return typeCast;
1628
+ return this.visitElement(typeCast, other);
3577
1629
  });
3578
1630
  }
3579
1631
  /**
@@ -3585,51 +1637,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3585
1637
  */
3586
1638
  visitTypeParameter(typeParameter, other) {
3587
1639
  return __awaiter(this, void 0, void 0, function* () {
3588
- if (!this.match || other.kind !== java_1.J.Kind.TypeParameter) {
3589
- return this.abort(typeParameter);
3590
- }
3591
- const otherTypeParameter = other;
3592
- // Compare annotations
3593
- if (typeParameter.annotations.length !== otherTypeParameter.annotations.length) {
3594
- return this.abort(typeParameter);
3595
- }
3596
- // Visit each annotation in lock step
3597
- for (let i = 0; i < typeParameter.annotations.length; i++) {
3598
- yield this.visit(typeParameter.annotations[i], otherTypeParameter.annotations[i]);
3599
- if (!this.match)
3600
- return typeParameter;
3601
- }
3602
- // Compare modifiers
3603
- if (typeParameter.modifiers.length !== otherTypeParameter.modifiers.length) {
3604
- return this.abort(typeParameter);
3605
- }
3606
- // Visit each modifier in lock step
3607
- for (let i = 0; i < typeParameter.modifiers.length; i++) {
3608
- yield this.visit(typeParameter.modifiers[i], otherTypeParameter.modifiers[i]);
3609
- if (!this.match)
3610
- return typeParameter;
3611
- }
3612
- // Visit name
3613
- yield this.visit(typeParameter.name, otherTypeParameter.name);
3614
- if (!this.match)
3615
- return typeParameter;
3616
- // Compare bounds
3617
- if ((typeParameter.bounds === undefined) !== (otherTypeParameter.bounds === undefined)) {
3618
- return this.abort(typeParameter);
3619
- }
3620
- // Visit bounds if present
3621
- if (typeParameter.bounds && otherTypeParameter.bounds) {
3622
- if (typeParameter.bounds.elements.length !== otherTypeParameter.bounds.elements.length) {
3623
- return this.abort(typeParameter);
3624
- }
3625
- // Visit each bound in lock step
3626
- for (let i = 0; i < typeParameter.bounds.elements.length; i++) {
3627
- yield this.visit(typeParameter.bounds.elements[i].element, otherTypeParameter.bounds.elements[i].element);
3628
- if (!this.match)
3629
- return typeParameter;
3630
- }
3631
- }
3632
- return typeParameter;
1640
+ return this.visitElement(typeParameter, other);
3633
1641
  });
3634
1642
  }
3635
1643
  /**
@@ -3641,31 +1649,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3641
1649
  */
3642
1650
  visitTypeParameters(typeParameters, other) {
3643
1651
  return __awaiter(this, void 0, void 0, function* () {
3644
- if (!this.match || other.kind !== java_1.J.Kind.TypeParameters) {
3645
- return this.abort(typeParameters);
3646
- }
3647
- const otherTypeParameters = other;
3648
- // Compare annotations
3649
- if (typeParameters.annotations.length !== otherTypeParameters.annotations.length) {
3650
- return this.abort(typeParameters);
3651
- }
3652
- // Visit each annotation in lock step
3653
- for (let i = 0; i < typeParameters.annotations.length; i++) {
3654
- yield this.visit(typeParameters.annotations[i], otherTypeParameters.annotations[i]);
3655
- if (!this.match)
3656
- return typeParameters;
3657
- }
3658
- // Compare typeParameters
3659
- if (typeParameters.typeParameters.length !== otherTypeParameters.typeParameters.length) {
3660
- return this.abort(typeParameters);
3661
- }
3662
- // Visit each type parameter in lock step
3663
- for (let i = 0; i < typeParameters.typeParameters.length; i++) {
3664
- yield this.visit(typeParameters.typeParameters[i].element, otherTypeParameters.typeParameters[i].element);
3665
- if (!this.match)
3666
- return typeParameters;
3667
- }
3668
- return typeParameters;
1652
+ return this.visitElement(typeParameters, other);
3669
1653
  });
3670
1654
  }
3671
1655
  /**
@@ -3677,19 +1661,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3677
1661
  */
3678
1662
  visitUnary(unary, other) {
3679
1663
  return __awaiter(this, void 0, void 0, function* () {
3680
- if (!this.match || other.kind !== java_1.J.Kind.Unary) {
3681
- return this.abort(unary);
3682
- }
3683
- const otherUnary = other;
3684
- // Compare operator
3685
- if (unary.operator.element !== otherUnary.operator.element) {
3686
- return this.abort(unary);
3687
- }
3688
- // Visit expression
3689
- yield this.visit(unary.expression, otherUnary.expression);
3690
- if (!this.match)
3691
- return unary;
3692
- return unary;
1664
+ return this.visitElement(unary, other);
3693
1665
  });
3694
1666
  }
3695
1667
  /**
@@ -3701,15 +1673,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3701
1673
  */
3702
1674
  visitUnknown(unknown, other) {
3703
1675
  return __awaiter(this, void 0, void 0, function* () {
3704
- if (!this.match || other.kind !== java_1.J.Kind.Unknown) {
3705
- return this.abort(unknown);
3706
- }
3707
- const otherUnknown = other;
3708
- // Visit source
3709
- yield this.visit(unknown.source, otherUnknown.source);
3710
- if (!this.match)
3711
- return unknown;
3712
- return unknown;
1676
+ return this.visitElement(unknown, other);
3713
1677
  });
3714
1678
  }
3715
1679
  /**
@@ -3721,75 +1685,19 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3721
1685
  */
3722
1686
  visitUnknownSource(unknownSource, other) {
3723
1687
  return __awaiter(this, void 0, void 0, function* () {
3724
- if (!this.match || other.kind !== java_1.J.Kind.UnknownSource) {
3725
- return this.abort(unknownSource);
3726
- }
3727
- const otherUnknownSource = other;
3728
- // Compare text
3729
- if (unknownSource.text !== otherUnknownSource.text) {
3730
- return this.abort(unknownSource);
3731
- }
3732
- return unknownSource;
1688
+ return this.visitElement(unknownSource, other);
3733
1689
  });
3734
1690
  }
3735
1691
  /**
3736
1692
  * Overrides the visitVariableDeclarations method to compare variable declarations.
3737
1693
  *
3738
- * @param variableDeclarations The variable declarations to visit
3739
- * @param other The other variable declarations to compare with
3740
- * @returns The visited variable declarations, or undefined if the visit was aborted
3741
- */
3742
- visitVariableDeclarations(variableDeclarations, other) {
3743
- return __awaiter(this, void 0, void 0, function* () {
3744
- if (!this.match || other.kind !== java_1.J.Kind.VariableDeclarations) {
3745
- return this.abort(variableDeclarations);
3746
- }
3747
- const otherVariableDeclarations = other;
3748
- // Compare leadingAnnotations
3749
- if (variableDeclarations.leadingAnnotations.length !== otherVariableDeclarations.leadingAnnotations.length) {
3750
- return this.abort(variableDeclarations);
3751
- }
3752
- // Visit each leading annotation in lock step
3753
- for (let i = 0; i < variableDeclarations.leadingAnnotations.length; i++) {
3754
- yield this.visit(variableDeclarations.leadingAnnotations[i], otherVariableDeclarations.leadingAnnotations[i]);
3755
- if (!this.match)
3756
- return variableDeclarations;
3757
- }
3758
- // Compare modifiers
3759
- if (variableDeclarations.modifiers.length !== otherVariableDeclarations.modifiers.length) {
3760
- return this.abort(variableDeclarations);
3761
- }
3762
- // Visit each modifier in lock step
3763
- for (let i = 0; i < variableDeclarations.modifiers.length; i++) {
3764
- yield this.visit(variableDeclarations.modifiers[i], otherVariableDeclarations.modifiers[i]);
3765
- if (!this.match)
3766
- return variableDeclarations;
3767
- }
3768
- // Compare typeExpression
3769
- if ((variableDeclarations.typeExpression === undefined) !== (otherVariableDeclarations.typeExpression === undefined)) {
3770
- return this.abort(variableDeclarations);
3771
- }
3772
- // Visit typeExpression if present
3773
- if (variableDeclarations.typeExpression && otherVariableDeclarations.typeExpression) {
3774
- yield this.visit(variableDeclarations.typeExpression, otherVariableDeclarations.typeExpression);
3775
- if (!this.match)
3776
- return variableDeclarations;
3777
- }
3778
- // Compare varargs
3779
- if ((variableDeclarations.varargs === undefined) !== (otherVariableDeclarations.varargs === undefined)) {
3780
- return this.abort(variableDeclarations);
3781
- }
3782
- // Compare variables
3783
- if (variableDeclarations.variables.length !== otherVariableDeclarations.variables.length) {
3784
- return this.abort(variableDeclarations);
3785
- }
3786
- // Visit each variable in lock step
3787
- for (let i = 0; i < variableDeclarations.variables.length; i++) {
3788
- yield this.visit(variableDeclarations.variables[i].element, otherVariableDeclarations.variables[i].element);
3789
- if (!this.match)
3790
- return variableDeclarations;
3791
- }
3792
- return variableDeclarations;
1694
+ * @param variableDeclarations The variable declarations to visit
1695
+ * @param other The other variable declarations to compare with
1696
+ * @returns The visited variable declarations, or undefined if the visit was aborted
1697
+ */
1698
+ visitVariableDeclarations(variableDeclarations, other) {
1699
+ return __awaiter(this, void 0, void 0, function* () {
1700
+ return this.visitElement(variableDeclarations, other);
3793
1701
  });
3794
1702
  }
3795
1703
  /**
@@ -3801,29 +1709,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3801
1709
  */
3802
1710
  visitVariable(variable, other) {
3803
1711
  return __awaiter(this, void 0, void 0, function* () {
3804
- if (!this.match || other.kind !== java_1.J.Kind.NamedVariable) {
3805
- return this.abort(variable);
3806
- }
3807
- const otherVariable = other;
3808
- // Visit name
3809
- yield this.visit(variable.name, otherVariable.name);
3810
- if (!this.match)
3811
- return variable;
3812
- // Compare dimensionsAfterName
3813
- if (variable.dimensionsAfterName.length !== otherVariable.dimensionsAfterName.length) {
3814
- return this.abort(variable);
3815
- }
3816
- // Compare initializer
3817
- if ((variable.initializer === undefined) !== (otherVariable.initializer === undefined)) {
3818
- return this.abort(variable);
3819
- }
3820
- // Visit initializer if present
3821
- if (variable.initializer && otherVariable.initializer) {
3822
- yield this.visit(variable.initializer.element, otherVariable.initializer.element);
3823
- if (!this.match)
3824
- return variable;
3825
- }
3826
- return variable;
1712
+ return this.visitElement(variable, other);
3827
1713
  });
3828
1714
  }
3829
1715
  /**
@@ -3835,19 +1721,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3835
1721
  */
3836
1722
  visitWhileLoop(whileLoop, other) {
3837
1723
  return __awaiter(this, void 0, void 0, function* () {
3838
- if (!this.match || other.kind !== java_1.J.Kind.WhileLoop) {
3839
- return this.abort(whileLoop);
3840
- }
3841
- const otherWhileLoop = other;
3842
- // Visit condition
3843
- yield this.visit(whileLoop.condition, otherWhileLoop.condition);
3844
- if (!this.match)
3845
- return whileLoop;
3846
- // Visit body
3847
- yield this.visit(whileLoop.body.element, otherWhileLoop.body.element);
3848
- if (!this.match)
3849
- return whileLoop;
3850
- return whileLoop;
1724
+ return this.visitElement(whileLoop, other);
3851
1725
  });
3852
1726
  }
3853
1727
  /**
@@ -3859,31 +1733,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3859
1733
  */
3860
1734
  visitWildcard(wildcard, other) {
3861
1735
  return __awaiter(this, void 0, void 0, function* () {
3862
- if (!this.match || other.kind !== java_1.J.Kind.Wildcard) {
3863
- return this.abort(wildcard);
3864
- }
3865
- const otherWildcard = other;
3866
- // Compare bound
3867
- if ((wildcard.bound === undefined) !== (otherWildcard.bound === undefined)) {
3868
- return this.abort(wildcard);
3869
- }
3870
- // Compare bound if present
3871
- if (wildcard.bound && otherWildcard.bound) {
3872
- if (wildcard.bound.element !== otherWildcard.bound.element) {
3873
- return this.abort(wildcard);
3874
- }
3875
- }
3876
- // Compare boundedType
3877
- if ((wildcard.boundedType === undefined) !== (otherWildcard.boundedType === undefined)) {
3878
- return this.abort(wildcard);
3879
- }
3880
- // Visit boundedType if present
3881
- if (wildcard.boundedType && otherWildcard.boundedType) {
3882
- yield this.visit(wildcard.boundedType, otherWildcard.boundedType);
3883
- if (!this.match)
3884
- return wildcard;
3885
- }
3886
- return wildcard;
1736
+ return this.visitElement(wildcard, other);
3887
1737
  });
3888
1738
  }
3889
1739
  /**
@@ -3895,19 +1745,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3895
1745
  */
3896
1746
  visitYield(yieldStatement, other) {
3897
1747
  return __awaiter(this, void 0, void 0, function* () {
3898
- if (!this.match || other.kind !== java_1.J.Kind.Yield) {
3899
- return this.abort(yieldStatement);
3900
- }
3901
- const otherYieldStatement = other;
3902
- // Compare implicit
3903
- if (yieldStatement.implicit !== otherYieldStatement.implicit) {
3904
- return this.abort(yieldStatement);
3905
- }
3906
- // Visit value
3907
- yield this.visit(yieldStatement.value, otherYieldStatement.value);
3908
- if (!this.match)
3909
- return yieldStatement;
3910
- return yieldStatement;
1748
+ return this.visitElement(yieldStatement, other);
3911
1749
  });
3912
1750
  }
3913
1751
  /**
@@ -3919,13 +1757,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3919
1757
  */
3920
1758
  visitVoid(void_, other) {
3921
1759
  return __awaiter(this, void 0, void 0, function* () {
3922
- if (!this.match || other.kind !== tree_1.JS.Kind.Void) {
3923
- return this.abort(void_);
3924
- }
3925
- const otherVoid = other;
3926
- // Visit expression
3927
- yield this.visit(void_.expression, otherVoid.expression);
3928
- return void_;
1760
+ return this.visitElement(void_, other);
3929
1761
  });
3930
1762
  }
3931
1763
  /**
@@ -3937,17 +1769,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3937
1769
  */
3938
1770
  visitWithStatement(withStatement, other) {
3939
1771
  return __awaiter(this, void 0, void 0, function* () {
3940
- if (!this.match || other.kind !== tree_1.JS.Kind.WithStatement) {
3941
- return this.abort(withStatement);
3942
- }
3943
- const otherWithStatement = other;
3944
- // Visit expression
3945
- yield this.visit(withStatement.expression, otherWithStatement.expression);
3946
- if (!this.match)
3947
- return withStatement;
3948
- // Visit body
3949
- yield this.visit(withStatement.body.element, otherWithStatement.body.element);
3950
- return withStatement;
1772
+ return this.visitElement(withStatement, other);
3951
1773
  });
3952
1774
  }
3953
1775
  /**
@@ -3959,33 +1781,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3959
1781
  */
3960
1782
  visitIndexSignatureDeclaration(indexSignatureDeclaration, other) {
3961
1783
  return __awaiter(this, void 0, void 0, function* () {
3962
- if (!this.match || other.kind !== tree_1.JS.Kind.IndexSignatureDeclaration) {
3963
- return this.abort(indexSignatureDeclaration);
3964
- }
3965
- const otherIndexSignatureDeclaration = other;
3966
- // Compare modifiers
3967
- if (indexSignatureDeclaration.modifiers.length !== otherIndexSignatureDeclaration.modifiers.length) {
3968
- return this.abort(indexSignatureDeclaration);
3969
- }
3970
- // Visit modifiers in lock step
3971
- for (let i = 0; i < indexSignatureDeclaration.modifiers.length; i++) {
3972
- yield this.visit(indexSignatureDeclaration.modifiers[i], otherIndexSignatureDeclaration.modifiers[i]);
3973
- if (!this.match)
3974
- return indexSignatureDeclaration;
3975
- }
3976
- // Compare parameters
3977
- if (indexSignatureDeclaration.parameters.elements.length !== otherIndexSignatureDeclaration.parameters.elements.length) {
3978
- return this.abort(indexSignatureDeclaration);
3979
- }
3980
- // Visit parameters in lock step
3981
- for (let i = 0; i < indexSignatureDeclaration.parameters.elements.length; i++) {
3982
- yield this.visit(indexSignatureDeclaration.parameters.elements[i].element, otherIndexSignatureDeclaration.parameters.elements[i].element);
3983
- if (!this.match)
3984
- return indexSignatureDeclaration;
3985
- }
3986
- // Visit type expression
3987
- yield this.visit(indexSignatureDeclaration.typeExpression.element, otherIndexSignatureDeclaration.typeExpression.element);
3988
- return indexSignatureDeclaration;
1784
+ return this.visitElement(indexSignatureDeclaration, other);
3989
1785
  });
3990
1786
  }
3991
1787
  /**
@@ -3997,19 +1793,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
3997
1793
  */
3998
1794
  visitForOfLoop(forOfLoop, other) {
3999
1795
  return __awaiter(this, void 0, void 0, function* () {
4000
- if (!this.match || other.kind !== tree_1.JS.Kind.ForOfLoop) {
4001
- return this.abort(forOfLoop);
4002
- }
4003
- const otherForOfLoop = other;
4004
- // Compare await
4005
- if ((forOfLoop.await === undefined) !== (otherForOfLoop.await === undefined)) {
4006
- return this.abort(forOfLoop);
4007
- }
4008
- // Visit loop
4009
- yield this.visit(forOfLoop.loop, otherForOfLoop.loop);
4010
- if (!this.match)
4011
- return forOfLoop;
4012
- return forOfLoop;
1796
+ return this.visitElement(forOfLoop, other);
4013
1797
  });
4014
1798
  }
4015
1799
  /**
@@ -4021,19 +1805,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4021
1805
  */
4022
1806
  visitForInLoop(forInLoop, other) {
4023
1807
  return __awaiter(this, void 0, void 0, function* () {
4024
- if (!this.match || other.kind !== tree_1.JS.Kind.ForInLoop) {
4025
- return this.abort(forInLoop);
4026
- }
4027
- const otherForInLoop = other;
4028
- // Visit control
4029
- yield this.visit(forInLoop.control, otherForInLoop.control);
4030
- if (!this.match)
4031
- return forInLoop;
4032
- // Visit body
4033
- yield this.visit(forInLoop.body.element, otherForInLoop.body.element);
4034
- if (!this.match)
4035
- return forInLoop;
4036
- return forInLoop;
1808
+ return this.visitElement(forInLoop, other);
4037
1809
  });
4038
1810
  }
4039
1811
  /**
@@ -4045,39 +1817,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4045
1817
  */
4046
1818
  visitNamespaceDeclaration(namespaceDeclaration, other) {
4047
1819
  return __awaiter(this, void 0, void 0, function* () {
4048
- if (!this.match || other.kind !== tree_1.JS.Kind.NamespaceDeclaration) {
4049
- return this.abort(namespaceDeclaration);
4050
- }
4051
- const otherNamespaceDeclaration = other;
4052
- // Compare modifiers
4053
- if (namespaceDeclaration.modifiers.length !== otherNamespaceDeclaration.modifiers.length) {
4054
- return this.abort(namespaceDeclaration);
4055
- }
4056
- // Visit each modifier in lock step
4057
- for (let i = 0; i < namespaceDeclaration.modifiers.length; i++) {
4058
- yield this.visit(namespaceDeclaration.modifiers[i], otherNamespaceDeclaration.modifiers[i]);
4059
- if (!this.match)
4060
- return namespaceDeclaration;
4061
- }
4062
- // Compare keywordType
4063
- if (namespaceDeclaration.keywordType.element !== otherNamespaceDeclaration.keywordType.element) {
4064
- return this.abort(namespaceDeclaration);
4065
- }
4066
- // Visit name
4067
- yield this.visit(namespaceDeclaration.name.element, otherNamespaceDeclaration.name.element);
4068
- if (!this.match)
4069
- return namespaceDeclaration;
4070
- // Compare body
4071
- if ((namespaceDeclaration.body === undefined) !== (otherNamespaceDeclaration.body === undefined)) {
4072
- return this.abort(namespaceDeclaration);
4073
- }
4074
- // Visit body if present
4075
- if (namespaceDeclaration.body && otherNamespaceDeclaration.body) {
4076
- yield this.visit(namespaceDeclaration.body, otherNamespaceDeclaration.body);
4077
- if (!this.match)
4078
- return namespaceDeclaration;
4079
- }
4080
- return namespaceDeclaration;
1820
+ return this.visitElement(namespaceDeclaration, other);
4081
1821
  });
4082
1822
  }
4083
1823
  /**
@@ -4089,15 +1829,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4089
1829
  */
4090
1830
  visitTypeLiteral(typeLiteral, other) {
4091
1831
  return __awaiter(this, void 0, void 0, function* () {
4092
- if (!this.match || other.kind !== tree_1.JS.Kind.TypeLiteral) {
4093
- return this.abort(typeLiteral);
4094
- }
4095
- const otherTypeLiteral = other;
4096
- // Visit members
4097
- yield this.visit(typeLiteral.members, otherTypeLiteral.members);
4098
- if (!this.match)
4099
- return typeLiteral;
4100
- return typeLiteral;
1832
+ return this.visitElement(typeLiteral, other);
4101
1833
  });
4102
1834
  }
4103
1835
  /**
@@ -4109,35 +1841,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4109
1841
  */
4110
1842
  visitBindingElement(bindingElement, other) {
4111
1843
  return __awaiter(this, void 0, void 0, function* () {
4112
- if (!this.match || other.kind !== tree_1.JS.Kind.BindingElement) {
4113
- return this.abort(bindingElement);
4114
- }
4115
- const otherBindingElement = other;
4116
- // Compare propertyName
4117
- if ((bindingElement.propertyName === undefined) !== (otherBindingElement.propertyName === undefined)) {
4118
- return this.abort(bindingElement);
4119
- }
4120
- // Visit propertyName if present
4121
- if (bindingElement.propertyName && otherBindingElement.propertyName) {
4122
- yield this.visit(bindingElement.propertyName.element, otherBindingElement.propertyName.element);
4123
- if (!this.match)
4124
- return bindingElement;
4125
- }
4126
- // Visit name
4127
- yield this.visit(bindingElement.name, otherBindingElement.name);
4128
- if (!this.match)
4129
- return bindingElement;
4130
- // Compare initializer
4131
- if ((bindingElement.initializer === undefined) !== (otherBindingElement.initializer === undefined)) {
4132
- return this.abort(bindingElement);
4133
- }
4134
- // Visit initializer if present
4135
- if (bindingElement.initializer && otherBindingElement.initializer) {
4136
- yield this.visit(bindingElement.initializer.element, otherBindingElement.initializer.element);
4137
- if (!this.match)
4138
- return bindingElement;
4139
- }
4140
- return bindingElement;
1844
+ return this.visitElement(bindingElement, other);
4141
1845
  });
4142
1846
  }
4143
1847
  /**
@@ -4149,21 +1853,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4149
1853
  */
4150
1854
  visitArrayBindingPattern(arrayBindingPattern, other) {
4151
1855
  return __awaiter(this, void 0, void 0, function* () {
4152
- if (!this.match || other.kind !== tree_1.JS.Kind.ArrayBindingPattern) {
4153
- return this.abort(arrayBindingPattern);
4154
- }
4155
- const otherArrayBindingPattern = other;
4156
- // Compare elements
4157
- if (arrayBindingPattern.elements.elements.length !== otherArrayBindingPattern.elements.elements.length) {
4158
- return this.abort(arrayBindingPattern);
4159
- }
4160
- // Visit each element in lock step
4161
- for (let i = 0; i < arrayBindingPattern.elements.elements.length; i++) {
4162
- yield this.visit(arrayBindingPattern.elements.elements[i].element, otherArrayBindingPattern.elements.elements[i].element);
4163
- if (!this.match)
4164
- return arrayBindingPattern;
4165
- }
4166
- return arrayBindingPattern;
1856
+ return this.visitElement(arrayBindingPattern, other);
4167
1857
  });
4168
1858
  }
4169
1859
  /**
@@ -4175,55 +1865,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4175
1865
  */
4176
1866
  visitExportDeclaration(exportDeclaration, other) {
4177
1867
  return __awaiter(this, void 0, void 0, function* () {
4178
- if (!this.match || other.kind !== tree_1.JS.Kind.ExportDeclaration) {
4179
- return this.abort(exportDeclaration);
4180
- }
4181
- const otherExportDeclaration = other;
4182
- // Compare modifiers
4183
- if (exportDeclaration.modifiers.length !== otherExportDeclaration.modifiers.length) {
4184
- return this.abort(exportDeclaration);
4185
- }
4186
- // Visit each modifier in lock step
4187
- for (let i = 0; i < exportDeclaration.modifiers.length; i++) {
4188
- yield this.visit(exportDeclaration.modifiers[i], otherExportDeclaration.modifiers[i]);
4189
- if (!this.match)
4190
- return exportDeclaration;
4191
- }
4192
- // Compare typeOnly
4193
- if (exportDeclaration.typeOnly.element !== otherExportDeclaration.typeOnly.element) {
4194
- return this.abort(exportDeclaration);
4195
- }
4196
- // Compare exportClause
4197
- if ((exportDeclaration.exportClause === undefined) !== (otherExportDeclaration.exportClause === undefined)) {
4198
- return this.abort(exportDeclaration);
4199
- }
4200
- // Visit exportClause if present
4201
- if (exportDeclaration.exportClause && otherExportDeclaration.exportClause) {
4202
- yield this.visit(exportDeclaration.exportClause, otherExportDeclaration.exportClause);
4203
- if (!this.match)
4204
- return exportDeclaration;
4205
- }
4206
- // Compare moduleSpecifier
4207
- if ((exportDeclaration.moduleSpecifier === undefined) !== (otherExportDeclaration.moduleSpecifier === undefined)) {
4208
- return this.abort(exportDeclaration);
4209
- }
4210
- // Visit moduleSpecifier if present
4211
- if (exportDeclaration.moduleSpecifier && otherExportDeclaration.moduleSpecifier) {
4212
- yield this.visit(exportDeclaration.moduleSpecifier.element, otherExportDeclaration.moduleSpecifier.element);
4213
- if (!this.match)
4214
- return exportDeclaration;
4215
- }
4216
- // Compare attributes
4217
- if ((exportDeclaration.attributes === undefined) !== (otherExportDeclaration.attributes === undefined)) {
4218
- return this.abort(exportDeclaration);
4219
- }
4220
- // Visit attributes if present
4221
- if (exportDeclaration.attributes && otherExportDeclaration.attributes) {
4222
- yield this.visit(exportDeclaration.attributes, otherExportDeclaration.attributes);
4223
- if (!this.match)
4224
- return exportDeclaration;
4225
- }
4226
- return exportDeclaration;
1868
+ return this.visitElement(exportDeclaration, other);
4227
1869
  });
4228
1870
  }
4229
1871
  /**
@@ -4235,19 +1877,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4235
1877
  */
4236
1878
  visitExportAssignment(exportAssignment, other) {
4237
1879
  return __awaiter(this, void 0, void 0, function* () {
4238
- if (!this.match || other.kind !== tree_1.JS.Kind.ExportAssignment) {
4239
- return this.abort(exportAssignment);
4240
- }
4241
- const otherExportAssignment = other;
4242
- // Compare exportEquals
4243
- if (exportAssignment.exportEquals !== otherExportAssignment.exportEquals) {
4244
- return this.abort(exportAssignment);
4245
- }
4246
- // Visit expression
4247
- yield this.visit(exportAssignment.expression.element, otherExportAssignment.expression.element);
4248
- if (!this.match)
4249
- return exportAssignment;
4250
- return exportAssignment;
1880
+ return this.visitElement(exportAssignment, other);
4251
1881
  });
4252
1882
  }
4253
1883
  /**
@@ -4259,21 +1889,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4259
1889
  */
4260
1890
  visitNamedExports(namedExports, other) {
4261
1891
  return __awaiter(this, void 0, void 0, function* () {
4262
- if (!this.match || other.kind !== tree_1.JS.Kind.NamedExports) {
4263
- return this.abort(namedExports);
4264
- }
4265
- const otherNamedExports = other;
4266
- // Compare elements
4267
- if (namedExports.elements.elements.length !== otherNamedExports.elements.elements.length) {
4268
- return this.abort(namedExports);
4269
- }
4270
- // Visit each element in lock step
4271
- for (let i = 0; i < namedExports.elements.elements.length; i++) {
4272
- yield this.visit(namedExports.elements.elements[i].element, otherNamedExports.elements.elements[i].element);
4273
- if (!this.match)
4274
- return namedExports;
4275
- }
4276
- return namedExports;
1892
+ return this.visitElement(namedExports, other);
4277
1893
  });
4278
1894
  }
4279
1895
  /**
@@ -4285,19 +1901,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4285
1901
  */
4286
1902
  visitExportSpecifier(exportSpecifier, other) {
4287
1903
  return __awaiter(this, void 0, void 0, function* () {
4288
- if (!this.match || other.kind !== tree_1.JS.Kind.ExportSpecifier) {
4289
- return this.abort(exportSpecifier);
4290
- }
4291
- const otherExportSpecifier = other;
4292
- // Compare typeOnly
4293
- if (exportSpecifier.typeOnly.element !== otherExportSpecifier.typeOnly.element) {
4294
- return this.abort(exportSpecifier);
4295
- }
4296
- // Visit specifier
4297
- yield this.visit(exportSpecifier.specifier, otherExportSpecifier.specifier);
4298
- if (!this.match)
4299
- return exportSpecifier;
4300
- return exportSpecifier;
1904
+ return this.visitElement(exportSpecifier, other);
4301
1905
  });
4302
1906
  }
4303
1907
  /**
@@ -4309,70 +1913,7 @@ class JavaScriptComparatorVisitor extends visitor_1.JavaScriptVisitor {
4309
1913
  */
4310
1914
  visitComputedPropertyMethodDeclaration(computedPropMethod, other) {
4311
1915
  return __awaiter(this, void 0, void 0, function* () {
4312
- if (!this.match || other.kind !== tree_1.JS.Kind.ComputedPropertyMethodDeclaration) {
4313
- return this.abort(computedPropMethod);
4314
- }
4315
- const otherComputedPropMethod = other;
4316
- // Compare leading annotations
4317
- if (computedPropMethod.leadingAnnotations.length !== otherComputedPropMethod.leadingAnnotations.length) {
4318
- return this.abort(computedPropMethod);
4319
- }
4320
- // Visit leading annotations in lock step
4321
- for (let i = 0; i < computedPropMethod.leadingAnnotations.length; i++) {
4322
- yield this.visit(computedPropMethod.leadingAnnotations[i], otherComputedPropMethod.leadingAnnotations[i]);
4323
- if (!this.match)
4324
- return computedPropMethod;
4325
- }
4326
- // Compare modifiers
4327
- if (computedPropMethod.modifiers.length !== otherComputedPropMethod.modifiers.length) {
4328
- return this.abort(computedPropMethod);
4329
- }
4330
- // Visit modifiers in lock step
4331
- for (let i = 0; i < computedPropMethod.modifiers.length; i++) {
4332
- yield this.visit(computedPropMethod.modifiers[i], otherComputedPropMethod.modifiers[i]);
4333
- if (!this.match)
4334
- return computedPropMethod;
4335
- }
4336
- // Compare type parameters
4337
- if (!!computedPropMethod.typeParameters !== !!otherComputedPropMethod.typeParameters) {
4338
- return this.abort(computedPropMethod);
4339
- }
4340
- if (computedPropMethod.typeParameters) {
4341
- yield this.visit(computedPropMethod.typeParameters, otherComputedPropMethod.typeParameters);
4342
- if (!this.match)
4343
- return computedPropMethod;
4344
- }
4345
- // Compare return type expression
4346
- if (!!computedPropMethod.returnTypeExpression !== !!otherComputedPropMethod.returnTypeExpression) {
4347
- return this.abort(computedPropMethod);
4348
- }
4349
- if (computedPropMethod.returnTypeExpression) {
4350
- yield this.visit(computedPropMethod.returnTypeExpression, otherComputedPropMethod.returnTypeExpression);
4351
- if (!this.match)
4352
- return computedPropMethod;
4353
- }
4354
- // Visit name
4355
- yield this.visit(computedPropMethod.name, otherComputedPropMethod.name);
4356
- if (!this.match)
4357
- return computedPropMethod;
4358
- // Compare parameters
4359
- if (computedPropMethod.parameters.elements.length !== otherComputedPropMethod.parameters.elements.length) {
4360
- return this.abort(computedPropMethod);
4361
- }
4362
- // Visit parameters in lock step
4363
- for (let i = 0; i < computedPropMethod.parameters.elements.length; i++) {
4364
- yield this.visit(computedPropMethod.parameters.elements[i].element, otherComputedPropMethod.parameters.elements[i].element);
4365
- if (!this.match)
4366
- return computedPropMethod;
4367
- }
4368
- // Compare body
4369
- if (!!computedPropMethod.body !== !!otherComputedPropMethod.body) {
4370
- return this.abort(computedPropMethod);
4371
- }
4372
- if (computedPropMethod.body) {
4373
- yield this.visit(computedPropMethod.body, otherComputedPropMethod.body);
4374
- }
4375
- return computedPropMethod;
1916
+ return this.visitElement(computedPropMethod, other);
4376
1917
  });
4377
1918
  }
4378
1919
  }
@@ -4384,13 +1925,52 @@ exports.JavaScriptComparatorVisitor = JavaScriptComparatorVisitor;
4384
1925
  * when both refer to the same method).
4385
1926
  */
4386
1927
  class JavaScriptSemanticComparatorVisitor extends JavaScriptComparatorVisitor {
1928
+ /**
1929
+ * Creates a new semantic comparator visitor.
1930
+ *
1931
+ * @param lenientTypeMatching If true, allows matching between nodes with and without type annotations
1932
+ */
1933
+ constructor(lenientTypeMatching = false) {
1934
+ super();
1935
+ this.lenientTypeMatching = lenientTypeMatching;
1936
+ }
1937
+ /**
1938
+ * Override visitProperty to allow lenient type matching.
1939
+ * When lenientTypeMatching is enabled, null vs Type comparisons are allowed
1940
+ * (where one value is null/undefined and the other is a Type object).
1941
+ */
1942
+ visitProperty(j, other) {
1943
+ const _super = Object.create(null, {
1944
+ visitProperty: { get: () => super.visitProperty }
1945
+ });
1946
+ return __awaiter(this, void 0, void 0, function* () {
1947
+ // Handle null/undefined with lenient type matching
1948
+ if (this.lenientTypeMatching && (j == null || other == null)) {
1949
+ if (j !== other) {
1950
+ // Don't abort if one is null and the other is a Type
1951
+ const jKind = j === null || j === void 0 ? void 0 : j.kind;
1952
+ const otherKind = other === null || other === void 0 ? void 0 : other.kind;
1953
+ const isTypeComparison = (jKind && typeof jKind === 'string' && jKind.startsWith('org.openrewrite.java.tree.JavaType$')) ||
1954
+ (otherKind && typeof otherKind === 'string' && otherKind.startsWith('org.openrewrite.java.tree.JavaType$'));
1955
+ if (!isTypeComparison) {
1956
+ this.abort(j);
1957
+ }
1958
+ }
1959
+ return j;
1960
+ }
1961
+ // Otherwise, use base class behavior
1962
+ return _super.visitProperty.call(this, j, other);
1963
+ });
1964
+ }
4387
1965
  /**
4388
1966
  * Checks if two types are semantically equal.
4389
1967
  * For method types, this checks that the declaring type and method name match.
1968
+ * With lenient type matching, undefined types on either side are considered compatible.
4390
1969
  */
4391
1970
  isOfType(target, source) {
4392
1971
  if (!target || !source) {
4393
- return target === source;
1972
+ // Lenient mode: if either type is undefined, allow the match
1973
+ return this.lenientTypeMatching ? true : target === source;
4394
1974
  }
4395
1975
  if (target.kind !== source.kind) {
4396
1976
  return false;
@@ -4468,7 +2048,11 @@ class JavaScriptSemanticComparatorVisitor extends JavaScriptComparatorVisitor {
4468
2048
  // Check type attribution
4469
2049
  // Both must have method types for semantic equality
4470
2050
  if (!method.methodType || !otherMethod.methodType) {
4471
- // If template has type but target doesn't, they don't match
2051
+ // Lenient mode: if either has no type, allow structural matching
2052
+ if (this.lenientTypeMatching) {
2053
+ return _super.visitMethodInvocation.call(this, method, other);
2054
+ }
2055
+ // Strict mode: if one has type but the other doesn't, they don't match
4472
2056
  if (method.methodType || otherMethod.methodType) {
4473
2057
  return this.abort(method);
4474
2058
  }
@@ -4496,9 +2080,6 @@ class JavaScriptSemanticComparatorVisitor extends JavaScriptComparatorVisitor {
4496
2080
  }
4497
2081
  if (method.select && otherMethod.select) {
4498
2082
  yield this.visit(method.select.element, otherMethod.select.element);
4499
- if (!this.match) {
4500
- return this.abort(method);
4501
- }
4502
2083
  }
4503
2084
  }
4504
2085
  // Compare type parameters
@@ -4554,12 +2135,160 @@ class JavaScriptSemanticComparatorVisitor extends JavaScriptComparatorVisitor {
4554
2135
  }
4555
2136
  }
4556
2137
  else if (identifier.fieldType || otherIdentifier.fieldType) {
4557
- // If only one has a type, they don't match
4558
- return this.abort(identifier);
2138
+ // Lenient mode: if either has no type, allow structural matching
2139
+ if (!this.lenientTypeMatching) {
2140
+ // Strict mode: if only one has a type, they don't match
2141
+ return this.abort(identifier);
2142
+ }
4559
2143
  }
4560
2144
  return _super.visitIdentifier.call(this, identifier, other);
4561
2145
  });
4562
2146
  }
2147
+ /**
2148
+ * Override variable declarations comparison to handle lenient type matching.
2149
+ * When lenientTypeMatching is true, patterns without typeExpression can match
2150
+ * code with typeExpression.
2151
+ */
2152
+ visitVariableDeclarations(variableDeclarations, other) {
2153
+ return __awaiter(this, void 0, void 0, function* () {
2154
+ const otherVariableDeclarations = other;
2155
+ // Visit leading annotations
2156
+ if (variableDeclarations.leadingAnnotations.length !== otherVariableDeclarations.leadingAnnotations.length) {
2157
+ return this.abort(variableDeclarations);
2158
+ }
2159
+ for (let i = 0; i < variableDeclarations.leadingAnnotations.length; i++) {
2160
+ yield this.visit(variableDeclarations.leadingAnnotations[i], otherVariableDeclarations.leadingAnnotations[i]);
2161
+ if (!this.match)
2162
+ return variableDeclarations;
2163
+ }
2164
+ // Visit modifiers
2165
+ if (variableDeclarations.modifiers.length !== otherVariableDeclarations.modifiers.length) {
2166
+ return this.abort(variableDeclarations);
2167
+ }
2168
+ for (let i = 0; i < variableDeclarations.modifiers.length; i++) {
2169
+ yield this.visit(variableDeclarations.modifiers[i], otherVariableDeclarations.modifiers[i]);
2170
+ if (!this.match)
2171
+ return variableDeclarations;
2172
+ }
2173
+ // Compare typeExpression - lenient matching allows one to be undefined
2174
+ if ((variableDeclarations.typeExpression === undefined) !== (otherVariableDeclarations.typeExpression === undefined)) {
2175
+ if (!this.lenientTypeMatching) {
2176
+ return this.abort(variableDeclarations);
2177
+ }
2178
+ // In lenient mode, skip type comparison and continue
2179
+ }
2180
+ else if (variableDeclarations.typeExpression && otherVariableDeclarations.typeExpression) {
2181
+ // Both have typeExpression, visit them
2182
+ yield this.visit(variableDeclarations.typeExpression, otherVariableDeclarations.typeExpression);
2183
+ if (!this.match)
2184
+ return variableDeclarations;
2185
+ }
2186
+ // Compare varargs
2187
+ if ((variableDeclarations.varargs === undefined) !== (otherVariableDeclarations.varargs === undefined)) {
2188
+ return this.abort(variableDeclarations);
2189
+ }
2190
+ // Compare variables
2191
+ if (variableDeclarations.variables.length !== otherVariableDeclarations.variables.length) {
2192
+ return this.abort(variableDeclarations);
2193
+ }
2194
+ // Visit each variable in lock step
2195
+ for (let i = 0; i < variableDeclarations.variables.length; i++) {
2196
+ yield this.visit(variableDeclarations.variables[i].element, otherVariableDeclarations.variables[i].element);
2197
+ if (!this.match)
2198
+ return variableDeclarations;
2199
+ }
2200
+ return variableDeclarations;
2201
+ });
2202
+ }
2203
+ /**
2204
+ * Override method declaration comparison to handle lenient type matching.
2205
+ * When lenientTypeMatching is true, patterns without returnTypeExpression can match
2206
+ * code with returnTypeExpression.
2207
+ */
2208
+ visitMethodDeclaration(methodDeclaration, other) {
2209
+ return __awaiter(this, void 0, void 0, function* () {
2210
+ const otherMethodDeclaration = other;
2211
+ // Visit leading annotations
2212
+ if (methodDeclaration.leadingAnnotations.length !== otherMethodDeclaration.leadingAnnotations.length) {
2213
+ return this.abort(methodDeclaration);
2214
+ }
2215
+ for (let i = 0; i < methodDeclaration.leadingAnnotations.length; i++) {
2216
+ yield this.visit(methodDeclaration.leadingAnnotations[i], otherMethodDeclaration.leadingAnnotations[i]);
2217
+ if (!this.match)
2218
+ return methodDeclaration;
2219
+ }
2220
+ // Visit modifiers
2221
+ if (methodDeclaration.modifiers.length !== otherMethodDeclaration.modifiers.length) {
2222
+ return this.abort(methodDeclaration);
2223
+ }
2224
+ for (let i = 0; i < methodDeclaration.modifiers.length; i++) {
2225
+ yield this.visit(methodDeclaration.modifiers[i], otherMethodDeclaration.modifiers[i]);
2226
+ if (!this.match)
2227
+ return methodDeclaration;
2228
+ }
2229
+ // Visit type parameters if present
2230
+ if (!!methodDeclaration.typeParameters !== !!otherMethodDeclaration.typeParameters) {
2231
+ return this.abort(methodDeclaration);
2232
+ }
2233
+ if (methodDeclaration.typeParameters && otherMethodDeclaration.typeParameters) {
2234
+ yield this.visit(methodDeclaration.typeParameters, otherMethodDeclaration.typeParameters);
2235
+ if (!this.match)
2236
+ return methodDeclaration;
2237
+ }
2238
+ // Compare returnTypeExpression - lenient matching allows one to be undefined
2239
+ if ((methodDeclaration.returnTypeExpression === undefined) !== (otherMethodDeclaration.returnTypeExpression === undefined)) {
2240
+ if (!this.lenientTypeMatching) {
2241
+ return this.abort(methodDeclaration);
2242
+ }
2243
+ // In lenient mode, skip type comparison and continue
2244
+ }
2245
+ else if (methodDeclaration.returnTypeExpression && otherMethodDeclaration.returnTypeExpression) {
2246
+ // Both have returnTypeExpression, visit them
2247
+ yield this.visit(methodDeclaration.returnTypeExpression, otherMethodDeclaration.returnTypeExpression);
2248
+ if (!this.match)
2249
+ return methodDeclaration;
2250
+ }
2251
+ // Visit name
2252
+ yield this.visit(methodDeclaration.name, otherMethodDeclaration.name);
2253
+ if (!this.match)
2254
+ return methodDeclaration;
2255
+ // Compare parameters
2256
+ if (methodDeclaration.parameters.elements.length !== otherMethodDeclaration.parameters.elements.length) {
2257
+ return this.abort(methodDeclaration);
2258
+ }
2259
+ // Visit each parameter in lock step
2260
+ for (let i = 0; i < methodDeclaration.parameters.elements.length; i++) {
2261
+ yield this.visit(methodDeclaration.parameters.elements[i].element, otherMethodDeclaration.parameters.elements[i].element);
2262
+ if (!this.match)
2263
+ return methodDeclaration;
2264
+ }
2265
+ // Visit throws if present
2266
+ if (!!methodDeclaration.throws !== !!otherMethodDeclaration.throws) {
2267
+ return this.abort(methodDeclaration);
2268
+ }
2269
+ if (methodDeclaration.throws && otherMethodDeclaration.throws) {
2270
+ // Visit each throws expression in lock step
2271
+ if (methodDeclaration.throws.elements.length !== otherMethodDeclaration.throws.elements.length) {
2272
+ return this.abort(methodDeclaration);
2273
+ }
2274
+ for (let i = 0; i < methodDeclaration.throws.elements.length; i++) {
2275
+ yield this.visit(methodDeclaration.throws.elements[i].element, otherMethodDeclaration.throws.elements[i].element);
2276
+ if (!this.match)
2277
+ return methodDeclaration;
2278
+ }
2279
+ }
2280
+ // Visit body if present
2281
+ if (!!methodDeclaration.body !== !!otherMethodDeclaration.body) {
2282
+ return this.abort(methodDeclaration);
2283
+ }
2284
+ if (methodDeclaration.body && otherMethodDeclaration.body) {
2285
+ yield this.visit(methodDeclaration.body, otherMethodDeclaration.body);
2286
+ if (!this.match)
2287
+ return methodDeclaration;
2288
+ }
2289
+ return methodDeclaration;
2290
+ });
2291
+ }
4563
2292
  }
4564
2293
  exports.JavaScriptSemanticComparatorVisitor = JavaScriptSemanticComparatorVisitor;
4565
2294
  //# sourceMappingURL=comparator.js.map