@openrewrite/rewrite 8.67.0-20251104-084009 → 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 (71) 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/format.d.ts.map +1 -1
  6. package/dist/javascript/format.js +3 -2
  7. package/dist/javascript/format.js.map +1 -1
  8. package/dist/javascript/index.d.ts +1 -1
  9. package/dist/javascript/index.d.ts.map +1 -1
  10. package/dist/javascript/index.js +1 -1
  11. package/dist/javascript/index.js.map +1 -1
  12. package/dist/javascript/templating/capture.d.ts +226 -0
  13. package/dist/javascript/templating/capture.d.ts.map +1 -0
  14. package/dist/javascript/templating/capture.js +371 -0
  15. package/dist/javascript/templating/capture.js.map +1 -0
  16. package/dist/javascript/templating/comparator.d.ts +61 -0
  17. package/dist/javascript/templating/comparator.d.ts.map +1 -0
  18. package/dist/javascript/templating/comparator.js +393 -0
  19. package/dist/javascript/templating/comparator.js.map +1 -0
  20. package/dist/javascript/templating/engine.d.ts +75 -0
  21. package/dist/javascript/templating/engine.d.ts.map +1 -0
  22. package/dist/javascript/templating/engine.js +228 -0
  23. package/dist/javascript/templating/engine.js.map +1 -0
  24. package/dist/javascript/templating/index.d.ts +6 -0
  25. package/dist/javascript/templating/index.d.ts.map +1 -0
  26. package/dist/javascript/templating/index.js +42 -0
  27. package/dist/javascript/templating/index.js.map +1 -0
  28. package/dist/javascript/templating/pattern.d.ts +171 -0
  29. package/dist/javascript/templating/pattern.d.ts.map +1 -0
  30. package/dist/javascript/templating/pattern.js +681 -0
  31. package/dist/javascript/templating/pattern.js.map +1 -0
  32. package/dist/javascript/templating/placeholder-replacement.d.ts +58 -0
  33. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
  34. package/dist/javascript/templating/placeholder-replacement.js +365 -0
  35. package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
  36. package/dist/javascript/templating/rewrite.d.ts +39 -0
  37. package/dist/javascript/templating/rewrite.d.ts.map +1 -0
  38. package/dist/javascript/templating/rewrite.js +81 -0
  39. package/dist/javascript/templating/rewrite.js.map +1 -0
  40. package/dist/javascript/templating/template.d.ts +204 -0
  41. package/dist/javascript/templating/template.d.ts.map +1 -0
  42. package/dist/javascript/templating/template.js +293 -0
  43. package/dist/javascript/templating/template.js.map +1 -0
  44. package/dist/javascript/templating/types.d.ts +263 -0
  45. package/dist/javascript/templating/types.d.ts.map +1 -0
  46. package/dist/javascript/templating/types.js +3 -0
  47. package/dist/javascript/templating/types.js.map +1 -0
  48. package/dist/javascript/templating/utils.d.ts +118 -0
  49. package/dist/javascript/templating/utils.d.ts.map +1 -0
  50. package/dist/javascript/templating/utils.js +253 -0
  51. package/dist/javascript/templating/utils.js.map +1 -0
  52. package/dist/version.txt +1 -1
  53. package/package.json +2 -1
  54. package/src/javascript/comparator.ts +554 -3323
  55. package/src/javascript/format.ts +2 -1
  56. package/src/javascript/index.ts +1 -1
  57. package/src/javascript/templating/capture.ts +503 -0
  58. package/src/javascript/templating/comparator.ts +430 -0
  59. package/src/javascript/templating/engine.ts +252 -0
  60. package/src/javascript/templating/index.ts +60 -0
  61. package/src/javascript/templating/pattern.ts +727 -0
  62. package/src/javascript/templating/placeholder-replacement.ts +372 -0
  63. package/src/javascript/templating/rewrite.ts +95 -0
  64. package/src/javascript/templating/template.ts +326 -0
  65. package/src/javascript/templating/types.ts +300 -0
  66. package/src/javascript/templating/utils.ts +284 -0
  67. package/dist/javascript/templating.d.ts +0 -265
  68. package/dist/javascript/templating.d.ts.map +0 -1
  69. package/dist/javascript/templating.js +0 -1027
  70. package/dist/javascript/templating.js.map +0 -1
  71. package/src/javascript/templating.ts +0 -1226
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._ = exports.CaptureValue = exports.TemplateParamImpl = exports.CaptureImpl = exports.CAPTURE_CAPTURING_SYMBOL = exports.CAPTURE_CONSTRAINT_SYMBOL = exports.CAPTURE_VARIADIC_SYMBOL = exports.CAPTURE_NAME_SYMBOL = void 0;
4
+ exports.and = and;
5
+ exports.or = or;
6
+ exports.not = not;
7
+ exports.capture = capture;
8
+ exports.any = any;
9
+ exports.param = param;
10
+ /**
11
+ * Combines multiple constraints with AND logic.
12
+ * All constraints must return true for the combined constraint to pass.
13
+ *
14
+ * @example
15
+ * const largeEvenNumber = capture('n', {
16
+ * constraint: and(
17
+ * (node) => typeof node.value === 'number',
18
+ * (node) => node.value > 100,
19
+ * (node) => node.value % 2 === 0
20
+ * )
21
+ * });
22
+ */
23
+ function and(...constraints) {
24
+ return (node) => constraints.every(c => c(node));
25
+ }
26
+ /**
27
+ * Combines multiple constraints with OR logic.
28
+ * At least one constraint must return true for the combined constraint to pass.
29
+ *
30
+ * @example
31
+ * const stringOrNumber = capture('value', {
32
+ * constraint: or(
33
+ * (node) => node.kind === J.Kind.Literal && typeof node.value === 'string',
34
+ * (node) => node.kind === J.Kind.Literal && typeof node.value === 'number'
35
+ * )
36
+ * });
37
+ */
38
+ function or(...constraints) {
39
+ return (node) => constraints.some(c => c(node));
40
+ }
41
+ /**
42
+ * Negates a constraint.
43
+ * Returns true when the constraint returns false, and vice versa.
44
+ *
45
+ * @example
46
+ * const notString = capture('value', {
47
+ * constraint: not((node) => typeof node.value === 'string')
48
+ * });
49
+ */
50
+ function not(constraint) {
51
+ return (node) => !constraint(node);
52
+ }
53
+ // Symbol to access the internal capture name without triggering Proxy
54
+ exports.CAPTURE_NAME_SYMBOL = Symbol('captureName');
55
+ // Symbol to access variadic options without triggering Proxy
56
+ exports.CAPTURE_VARIADIC_SYMBOL = Symbol('captureVariadic');
57
+ // Symbol to access constraint function without triggering Proxy
58
+ exports.CAPTURE_CONSTRAINT_SYMBOL = Symbol('captureConstraint');
59
+ // Symbol to access capturing flag without triggering Proxy
60
+ exports.CAPTURE_CAPTURING_SYMBOL = Symbol('captureCapturing');
61
+ class CaptureImpl {
62
+ constructor(name, options, capturing = true) {
63
+ this.name = name;
64
+ this[exports.CAPTURE_NAME_SYMBOL] = name;
65
+ this[exports.CAPTURE_CAPTURING_SYMBOL] = capturing;
66
+ // Normalize variadic options
67
+ if (options === null || options === void 0 ? void 0 : options.variadic) {
68
+ if (typeof options.variadic === 'boolean') {
69
+ this[exports.CAPTURE_VARIADIC_SYMBOL] = {};
70
+ }
71
+ else {
72
+ this[exports.CAPTURE_VARIADIC_SYMBOL] = {
73
+ min: options.variadic.min,
74
+ max: options.variadic.max
75
+ };
76
+ }
77
+ }
78
+ // Store constraint if provided
79
+ if (options === null || options === void 0 ? void 0 : options.constraint) {
80
+ this[exports.CAPTURE_CONSTRAINT_SYMBOL] = options.constraint;
81
+ }
82
+ }
83
+ getName() {
84
+ return this[exports.CAPTURE_NAME_SYMBOL];
85
+ }
86
+ isVariadic() {
87
+ return this[exports.CAPTURE_VARIADIC_SYMBOL] !== undefined;
88
+ }
89
+ getVariadicOptions() {
90
+ return this[exports.CAPTURE_VARIADIC_SYMBOL];
91
+ }
92
+ getConstraint() {
93
+ return this[exports.CAPTURE_CONSTRAINT_SYMBOL];
94
+ }
95
+ isCapturing() {
96
+ return this[exports.CAPTURE_CAPTURING_SYMBOL];
97
+ }
98
+ }
99
+ exports.CaptureImpl = CaptureImpl;
100
+ class TemplateParamImpl {
101
+ constructor(name) {
102
+ this.name = name;
103
+ }
104
+ getName() {
105
+ return this.name;
106
+ }
107
+ }
108
+ exports.TemplateParamImpl = TemplateParamImpl;
109
+ /**
110
+ * Represents a property access on a captured value.
111
+ * When you access a property on a Capture (e.g., method.name), you get a CaptureValue
112
+ * that knows how to resolve that property from the matched values.
113
+ */
114
+ class CaptureValue {
115
+ constructor(rootCapture, propertyPath, arrayOperation) {
116
+ this.rootCapture = rootCapture;
117
+ this.propertyPath = propertyPath;
118
+ this.arrayOperation = arrayOperation;
119
+ }
120
+ /**
121
+ * Resolves this capture value by looking up the root capture in the values map
122
+ * and navigating through the property path.
123
+ */
124
+ resolve(values) {
125
+ const rootName = this.rootCapture.getName();
126
+ let current = values.get(rootName);
127
+ // Handle array operations on variadic captures
128
+ if (this.arrayOperation && Array.isArray(current)) {
129
+ switch (this.arrayOperation.type) {
130
+ case 'index':
131
+ current = current[this.arrayOperation.args[0]];
132
+ break;
133
+ case 'slice':
134
+ current = current.slice(...this.arrayOperation.args);
135
+ break;
136
+ case 'length':
137
+ current = current.length;
138
+ break;
139
+ }
140
+ }
141
+ // Navigate through property path
142
+ for (const prop of this.propertyPath) {
143
+ if (current === null || current === undefined || typeof current === 'number') {
144
+ return undefined;
145
+ }
146
+ current = current[prop];
147
+ }
148
+ return current;
149
+ }
150
+ /**
151
+ * Checks if this CaptureValue will resolve to an array that should be expanded.
152
+ */
153
+ isArrayExpansion() {
154
+ var _a, _b, _c;
155
+ // Only slice operations and the root variadic capture return arrays
156
+ return ((_a = this.arrayOperation) === null || _a === void 0 ? void 0 : _a.type) === 'slice' ||
157
+ (this.arrayOperation === undefined && this.propertyPath.length === 0 &&
158
+ ((_c = (_b = this.rootCapture).isVariadic) === null || _c === void 0 ? void 0 : _c.call(_b)));
159
+ }
160
+ }
161
+ exports.CaptureValue = CaptureValue;
162
+ /**
163
+ * Creates a Proxy around a CaptureValue that allows further property access.
164
+ * This enables chaining like method.name.simpleName
165
+ */
166
+ function createCaptureValueProxy(rootCapture, propertyPath, arrayOperation) {
167
+ const captureValue = new CaptureValue(rootCapture, propertyPath, arrayOperation);
168
+ return new Proxy(captureValue, {
169
+ get(target, prop) {
170
+ // Allow access to the CaptureValue instance itself and its methods
171
+ if (prop === 'resolve' || prop === 'rootCapture' || prop === 'propertyPath' ||
172
+ prop === 'arrayOperation' || prop === 'isArrayExpansion') {
173
+ const value = target[prop];
174
+ return typeof value === 'function' ? value.bind(target) : value;
175
+ }
176
+ // For string property access, extend the property path
177
+ if (typeof prop === 'string') {
178
+ return createCaptureValueProxy(target.rootCapture, [...target.propertyPath, prop], target.arrayOperation);
179
+ }
180
+ return undefined;
181
+ }
182
+ });
183
+ }
184
+ /**
185
+ * Creates a capture specification for use in template patterns.
186
+ *
187
+ * @template T The expected type of the captured AST node (for TypeScript autocomplete only)
188
+ * @returns A Capture object that supports property access for use in templates
189
+ *
190
+ * @remarks
191
+ * **Pattern Matching is Structural:**
192
+ *
193
+ * What a capture matches is determined by the pattern structure, not the type parameter:
194
+ * - `pattern`${capture('x')}`` matches ANY single expression (identifier, literal, call, binary, etc.)
195
+ * - `pattern`foo(${capture('x')})`` matches only expressions inside `foo()` calls
196
+ * - `pattern`${capture('x')} + ${capture('y')}`` matches only binary `+` expressions
197
+ *
198
+ * The TypeScript type parameter `<T>` provides IDE autocomplete but doesn't enforce runtime types.
199
+ *
200
+ * @example
201
+ * // Named inline captures
202
+ * const pat = pattern`${capture('left')} + ${capture('right')}`;
203
+ * // Matches: <any expression> + <any expression>
204
+ *
205
+ * // Unnamed captures
206
+ * const {left, right} = {left: capture(), right: capture()};
207
+ * const pattern = pattern`${left} + ${right}`;
208
+ *
209
+ * @example
210
+ * // Type parameter is for IDE autocomplete only
211
+ * const method = capture<J.MethodInvocation>('method');
212
+ * const pat = pattern`foo(${method})`;
213
+ * // Matches: foo(<any expression>) - not restricted to method invocations!
214
+ * // Type <J.MethodInvocation> only helps with autocomplete in your code
215
+ *
216
+ * @example
217
+ * // Structural pattern determines what matches
218
+ * const arg = capture('arg');
219
+ * const pat = pattern`process(${arg})`;
220
+ * // Matches: process(42), process("text"), process(x + y), etc.
221
+ * // The 'arg' capture will bind to whatever expression is passed to process()
222
+ *
223
+ * @example
224
+ * // Repeated patterns using the same capture
225
+ * const expr = capture('expr');
226
+ * const redundantOr = pattern`${expr} || ${expr}`;
227
+ * // Matches expressions where both sides are identical: x || x, foo() || foo()
228
+ *
229
+ * @example
230
+ * // Property access in templates
231
+ * const method = capture<J.MethodInvocation>('method');
232
+ * template`console.log(${method.name.simpleName})` // Accesses properties of captured node
233
+ */
234
+ /**
235
+ * Creates a Proxy wrapper for CaptureImpl that intercepts property accesses.
236
+ * Shared logic between capture() and any() to avoid duplication.
237
+ */
238
+ function createCaptureProxy(impl) {
239
+ return new Proxy(impl, {
240
+ get(target, prop) {
241
+ // Allow access to internal symbols
242
+ if (prop === exports.CAPTURE_NAME_SYMBOL) {
243
+ return target[exports.CAPTURE_NAME_SYMBOL];
244
+ }
245
+ if (prop === exports.CAPTURE_VARIADIC_SYMBOL) {
246
+ return target[exports.CAPTURE_VARIADIC_SYMBOL];
247
+ }
248
+ if (prop === exports.CAPTURE_CONSTRAINT_SYMBOL) {
249
+ return target[exports.CAPTURE_CONSTRAINT_SYMBOL];
250
+ }
251
+ if (prop === exports.CAPTURE_CAPTURING_SYMBOL) {
252
+ return target[exports.CAPTURE_CAPTURING_SYMBOL];
253
+ }
254
+ // Allow methods to be called directly on the target
255
+ if (prop === 'getName' || prop === 'isVariadic' || prop === 'getVariadicOptions' || prop === 'getConstraint' || prop === 'isCapturing') {
256
+ return target[prop].bind(target);
257
+ }
258
+ // For variadic captures, support array-like operations
259
+ if (target.isVariadic() && typeof prop === 'string') {
260
+ // Numeric index access: args[0], args[1], etc.
261
+ const indexNum = Number(prop);
262
+ if (!isNaN(indexNum) && indexNum >= 0 && Number.isInteger(indexNum)) {
263
+ return createCaptureValueProxy(target, [], { type: 'index', args: [indexNum] });
264
+ }
265
+ // Array method: slice
266
+ if (prop === 'slice') {
267
+ return (...args) => {
268
+ return createCaptureValueProxy(target, [], { type: 'slice', args });
269
+ };
270
+ }
271
+ // Array property: length
272
+ if (prop === 'length') {
273
+ return createCaptureValueProxy(target, [], { type: 'length' });
274
+ }
275
+ }
276
+ // For string property access, create a CaptureValue with a property path
277
+ if (typeof prop === 'string') {
278
+ return createCaptureValueProxy(target, [prop]);
279
+ }
280
+ return undefined;
281
+ }
282
+ });
283
+ }
284
+ // Implementation
285
+ function capture(nameOrOptions) {
286
+ let name;
287
+ let options;
288
+ if (typeof nameOrOptions === 'string') {
289
+ // Simple named capture: capture('name')
290
+ name = nameOrOptions;
291
+ options = undefined;
292
+ }
293
+ else {
294
+ // Options-based API: capture({ name: 'name', ...options }) or capture()
295
+ options = nameOrOptions;
296
+ name = options === null || options === void 0 ? void 0 : options.name;
297
+ }
298
+ const captureName = name || `unnamed_${capture.nextUnnamedId++}`;
299
+ const impl = new CaptureImpl(captureName, options);
300
+ return createCaptureProxy(impl);
301
+ }
302
+ // Static counter for generating unique IDs for unnamed captures
303
+ capture.nextUnnamedId = 1;
304
+ // Implementation
305
+ function any(options) {
306
+ const anonName = `anon_${any.nextAnonId++}`;
307
+ const impl = new CaptureImpl(anonName, options, false); // capturing = false
308
+ return createCaptureProxy(impl);
309
+ }
310
+ // Static counter for generating unique IDs for anonymous (non-capturing) patterns
311
+ any.nextAnonId = 1;
312
+ /**
313
+ * Creates a parameter specification for use in standalone templates (not used with patterns).
314
+ *
315
+ * Use `param()` when creating templates that are not used with pattern matching.
316
+ * Use `capture()` when the template works with a pattern.
317
+ *
318
+ * @template T The expected type of the parameter value (for TypeScript autocomplete only)
319
+ * @param name Optional name for the parameter. If not provided, an auto-generated name is used.
320
+ * @returns A TemplateParam object (simpler than Capture, no property access support)
321
+ *
322
+ * @remarks
323
+ * **When to use `param()` vs `capture()`:**
324
+ *
325
+ * - Use `param()` in **standalone templates** (no pattern matching involved)
326
+ * - Use `capture()` in **patterns** and templates used with patterns
327
+ *
328
+ * **Key Differences:**
329
+ * - `TemplateParam` is simpler - no property access proxy overhead
330
+ * - `Capture` supports property access (e.g., `capture('x').name.simpleName`)
331
+ * - Both work in templates, but `param()` makes intent clearer for standalone use
332
+ *
333
+ * @example
334
+ * // ✅ GOOD: Use param() for standalone templates
335
+ * const value = param<J.Literal>('value');
336
+ * const tmpl = template`return ${value} * 2;`;
337
+ * await tmpl.apply(cursor, node, new Map([['value', someLiteral]]));
338
+ *
339
+ * @example
340
+ * // ✅ GOOD: Use capture() with patterns
341
+ * const value = capture('value');
342
+ * const pat = pattern`foo(${value})`;
343
+ * const tmpl = template`bar(${value})`; // capture() makes sense here
344
+ *
345
+ * @example
346
+ * // ⚠️ CONFUSING: Using capture() in standalone template
347
+ * const value = capture('value');
348
+ * template`return ${value} * 2;`; // "Capturing" what? There's no pattern!
349
+ *
350
+ * @example
351
+ * // ❌ WRONG: param() doesn't support property access
352
+ * const node = param<J.MethodInvocation>('invocation');
353
+ * template`console.log(${node.name})` // Error! Use capture() for property access
354
+ */
355
+ function param(name) {
356
+ const paramName = name || `unnamed_${capture.nextUnnamedId++}`;
357
+ return new TemplateParamImpl(paramName);
358
+ }
359
+ /**
360
+ * Concise alias for `capture`. Works well for inline captures in patterns and templates.
361
+ *
362
+ * @param name Optional name for the capture. If not provided, an auto-generated name is used.
363
+ * @returns A Capture object
364
+ *
365
+ * @example
366
+ * // Inline captures with _ alias
367
+ * pattern`isDate(${_('dateArg')})`
368
+ * template`${_('dateArg')} instanceof Date`
369
+ */
370
+ exports._ = capture;
371
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/javascript/templating/capture.ts"],"names":[],"mappings":";;;AA+BA,kBAEC;AAcD,gBAEC;AAWD,kBAEC;AA0RD,0BAkBC;AAuED,kBAKC;AAgDD,sBAGC;AAvdD;;;;;;;;;;;;GAYG;AACH,SAAgB,GAAG,CAAI,GAAG,WAAqC;IAC3D,OAAO,CAAC,IAAO,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,EAAE,CAAI,GAAG,WAAqC;IAC1D,OAAO,CAAC,IAAO,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC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
+ import { JavaScriptSemanticComparatorVisitor } from '../comparator';
5
+ import { CaptureStorageValue } from './utils';
6
+ /**
7
+ * A comparator for pattern matching that is lenient about optional properties.
8
+ * Allows patterns without type annotations to match actual code with type annotations.
9
+ * Uses semantic comparison to match semantically equivalent code (e.g., isDate() and util.isDate()).
10
+ */
11
+ export declare class PatternMatchingComparator extends JavaScriptSemanticComparatorVisitor {
12
+ private readonly matcher;
13
+ constructor(matcher: {
14
+ handleCapture: (pattern: J, target: J, wrapper?: J.RightPadded<J>) => boolean;
15
+ handleVariadicCapture: (pattern: J, targets: J[], wrappers?: J.RightPadded<J>[]) => boolean;
16
+ saveState: () => Map<string, CaptureStorageValue>;
17
+ restoreState: (state: Map<string, CaptureStorageValue>) => void;
18
+ }, lenientTypeMatching?: boolean);
19
+ /**
20
+ * Extracts the wrapper from the cursor if the parent is a RightPadded.
21
+ */
22
+ private getWrapperFromCursor;
23
+ visit<R extends J>(j: Tree, p: J, parent?: Cursor): Promise<R | undefined>;
24
+ protected hasSameKind(j: J, other: J): boolean;
25
+ visitIdentifier(identifier: J.Identifier, other: J): Promise<J | undefined>;
26
+ visitMethodInvocation(methodInvocation: J.MethodInvocation, other: J): Promise<J | undefined>;
27
+ visitBlock(block: J.Block, other: J): Promise<J | undefined>;
28
+ visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, other: J): Promise<J | undefined>;
29
+ /**
30
+ * Matches argument lists, with special handling for variadic captures.
31
+ * A variadic capture can match zero or more consecutive arguments.
32
+ */
33
+ private matchArguments;
34
+ /**
35
+ * Generic sequence matching with variadic capture support.
36
+ * Works for any sequence of JRightPadded elements (arguments, statements, etc.).
37
+ * A variadic capture can match zero or more consecutive elements.
38
+ *
39
+ * Uses pivot detection to optimize matching, with backtracking as fallback.
40
+ *
41
+ * @param patternElements The pattern elements (JRightPadded)
42
+ * @param targetElements The target elements to match against (JRightPadded)
43
+ * @param filterEmpty Whether to filter out J.Empty elements when capturing (true for arguments, false for statements)
44
+ * @returns true if the sequence matches, false otherwise
45
+ */
46
+ private matchSequence;
47
+ /**
48
+ * Optimized sequence matcher with pivot detection and backtracking.
49
+ * For variadic patterns, tries to detect pivots (where next pattern matches) to avoid
50
+ * unnecessary backtracking. Falls back to full backtracking when pivots are ambiguous.
51
+ *
52
+ * @param patternElements The pattern elements (JRightPadded)
53
+ * @param targetElements The target elements to match against (JRightPadded)
54
+ * @param patternIdx Current position in pattern
55
+ * @param targetIdx Current position in target
56
+ * @param filterEmpty Whether to filter out J.Empty elements when capturing
57
+ * @returns true if the remaining sequence matches, false otherwise
58
+ */
59
+ private matchSequenceOptimized;
60
+ }
61
+ //# sourceMappingURL=comparator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/comparator.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,CAAC;AACnC,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAC;AAC5B,OAAO,EAAC,mCAAmC,EAAC,MAAM,eAAe,CAAC;AAClE,OAAO,EAAmB,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAE9D;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,mCAAmC;IAE1E,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE;QACtB,aAAa,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;QAC9E,qBAAqB,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC;QAC5F,SAAS,EAAE,MAAM,GAAG,CAAC,MA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