@openrewrite/rewrite 8.66.0 → 8.66.2

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 (113) hide show
  1. package/dist/java/tree.d.ts +10 -1
  2. package/dist/java/tree.d.ts.map +1 -1
  3. package/dist/java/tree.js +21 -5
  4. package/dist/java/tree.js.map +1 -1
  5. package/dist/java/type-visitor.d.ts +1 -1
  6. package/dist/java/type-visitor.d.ts.map +1 -1
  7. package/dist/java/visitor.d.ts +2 -2
  8. package/dist/java/visitor.d.ts.map +1 -1
  9. package/dist/java/visitor.js +8 -2
  10. package/dist/java/visitor.js.map +1 -1
  11. package/dist/javascript/assertions.d.ts +6 -0
  12. package/dist/javascript/assertions.d.ts.map +1 -1
  13. package/dist/javascript/assertions.js +14 -6
  14. package/dist/javascript/assertions.js.map +1 -1
  15. package/dist/javascript/comparator.d.ts +217 -7
  16. package/dist/javascript/comparator.d.ts.map +1 -1
  17. package/dist/javascript/comparator.js +1020 -2848
  18. package/dist/javascript/comparator.js.map +1 -1
  19. package/dist/javascript/format.d.ts +5 -3
  20. package/dist/javascript/format.d.ts.map +1 -1
  21. package/dist/javascript/format.js +87 -44
  22. package/dist/javascript/format.js.map +1 -1
  23. package/dist/javascript/index.d.ts +2 -1
  24. package/dist/javascript/index.d.ts.map +1 -1
  25. package/dist/javascript/index.js +2 -1
  26. package/dist/javascript/index.js.map +1 -1
  27. package/dist/javascript/parser.d.ts +2 -1
  28. package/dist/javascript/parser.d.ts.map +1 -1
  29. package/dist/javascript/parser.js +54 -43
  30. package/dist/javascript/parser.js.map +1 -1
  31. package/dist/javascript/templating/capture.d.ts +293 -0
  32. package/dist/javascript/templating/capture.d.ts.map +1 -0
  33. package/dist/javascript/templating/capture.js +461 -0
  34. package/dist/javascript/templating/capture.js.map +1 -0
  35. package/dist/javascript/templating/comparator.d.ts +171 -0
  36. package/dist/javascript/templating/comparator.d.ts.map +1 -0
  37. package/dist/javascript/templating/comparator.js +1221 -0
  38. package/dist/javascript/templating/comparator.js.map +1 -0
  39. package/dist/javascript/templating/engine.d.ts +108 -0
  40. package/dist/javascript/templating/engine.d.ts.map +1 -0
  41. package/dist/javascript/templating/engine.js +661 -0
  42. package/dist/javascript/templating/engine.js.map +1 -0
  43. package/dist/javascript/templating/index.d.ts +6 -0
  44. package/dist/javascript/templating/index.d.ts.map +1 -0
  45. package/dist/javascript/templating/index.js +44 -0
  46. package/dist/javascript/templating/index.js.map +1 -0
  47. package/dist/javascript/templating/pattern.d.ts +276 -0
  48. package/dist/javascript/templating/pattern.d.ts.map +1 -0
  49. package/dist/javascript/templating/pattern.js +952 -0
  50. package/dist/javascript/templating/pattern.js.map +1 -0
  51. package/dist/javascript/templating/placeholder-replacement.d.ts +83 -0
  52. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
  53. package/dist/javascript/templating/placeholder-replacement.js +467 -0
  54. package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
  55. package/dist/javascript/templating/rewrite.d.ts +84 -0
  56. package/dist/javascript/templating/rewrite.d.ts.map +1 -0
  57. package/dist/javascript/templating/rewrite.js +208 -0
  58. package/dist/javascript/templating/rewrite.js.map +1 -0
  59. package/dist/javascript/templating/template.d.ts +230 -0
  60. package/dist/javascript/templating/template.d.ts.map +1 -0
  61. package/dist/javascript/templating/template.js +367 -0
  62. package/dist/javascript/templating/template.js.map +1 -0
  63. package/dist/javascript/templating/types.d.ts +610 -0
  64. package/dist/javascript/templating/types.d.ts.map +1 -0
  65. package/dist/javascript/templating/types.js +3 -0
  66. package/dist/javascript/templating/types.js.map +1 -0
  67. package/dist/javascript/templating/utils.d.ts +135 -0
  68. package/dist/javascript/templating/utils.d.ts.map +1 -0
  69. package/dist/javascript/templating/utils.js +251 -0
  70. package/dist/javascript/templating/utils.js.map +1 -0
  71. package/dist/javascript/type-mapping.d.ts.map +1 -1
  72. package/dist/javascript/type-mapping.js +21 -11
  73. package/dist/javascript/type-mapping.js.map +1 -1
  74. package/dist/json/rpc.js +2 -2
  75. package/dist/json/rpc.js.map +1 -1
  76. package/dist/recipe/order-imports.js.map +1 -1
  77. package/dist/test/rewrite-test.d.ts.map +1 -1
  78. package/dist/test/rewrite-test.js +10 -6
  79. package/dist/test/rewrite-test.js.map +1 -1
  80. package/dist/version.txt +1 -1
  81. package/dist/visitor.d.ts +4 -4
  82. package/dist/visitor.d.ts.map +1 -1
  83. package/dist/visitor.js +8 -3
  84. package/dist/visitor.js.map +1 -1
  85. package/package.json +5 -2
  86. package/src/java/tree.ts +10 -3
  87. package/src/java/type-visitor.ts +1 -1
  88. package/src/java/visitor.ts +11 -5
  89. package/src/javascript/assertions.ts +9 -3
  90. package/src/javascript/comparator.ts +1095 -3373
  91. package/src/javascript/format.ts +72 -33
  92. package/src/javascript/index.ts +2 -1
  93. package/src/javascript/parser.ts +67 -45
  94. package/src/javascript/templating/capture.ts +595 -0
  95. package/src/javascript/templating/comparator.ts +1383 -0
  96. package/src/javascript/templating/engine.ts +750 -0
  97. package/src/javascript/templating/index.ts +67 -0
  98. package/src/javascript/templating/pattern.ts +1101 -0
  99. package/src/javascript/templating/placeholder-replacement.ts +475 -0
  100. package/src/javascript/templating/rewrite.ts +229 -0
  101. package/src/javascript/templating/template.ts +414 -0
  102. package/src/javascript/templating/types.ts +674 -0
  103. package/src/javascript/templating/utils.ts +298 -0
  104. package/src/javascript/type-mapping.ts +20 -11
  105. package/src/json/rpc.ts +2 -2
  106. package/src/recipe/order-imports.ts +1 -1
  107. package/src/test/rewrite-test.ts +12 -7
  108. package/src/visitor.ts +14 -6
  109. package/dist/javascript/templating.d.ts +0 -265
  110. package/dist/javascript/templating.d.ts.map +0 -1
  111. package/dist/javascript/templating.js +0 -1027
  112. package/dist/javascript/templating.js.map +0 -1
  113. package/src/javascript/templating.ts +0 -1226
@@ -0,0 +1,461 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports._ = exports.RawCode = exports.CaptureValue = exports.TemplateParamImpl = exports.CaptureImpl = exports.RAW_CODE_SYMBOL = exports.CAPTURE_TYPE_SYMBOL = exports.CAPTURE_CAPTURING_SYMBOL = exports.CAPTURE_CONSTRAINT_SYMBOL = exports.CAPTURE_VARIADIC_SYMBOL = exports.CAPTURE_NAME_SYMBOL = void 0;
5
+ exports.and = and;
6
+ exports.or = or;
7
+ exports.not = not;
8
+ exports.capture = capture;
9
+ exports.any = any;
10
+ exports.param = param;
11
+ exports.raw = raw;
12
+ /**
13
+ * Combines multiple constraints with AND logic.
14
+ * All constraints must return true for the combined constraint to pass.
15
+ *
16
+ * @example
17
+ * const largeEvenNumber = capture('n', {
18
+ * constraint: and(
19
+ * (node) => typeof node.value === 'number',
20
+ * (node) => node.value > 100,
21
+ * (node) => node.value % 2 === 0
22
+ * )
23
+ * });
24
+ */
25
+ function and(...constraints) {
26
+ return (node, cursor) => constraints.every(c => c(node, cursor));
27
+ }
28
+ /**
29
+ * Combines multiple constraints with OR logic.
30
+ * At least one constraint must return true for the combined constraint to pass.
31
+ *
32
+ * @example
33
+ * const stringOrNumber = capture('value', {
34
+ * constraint: or(
35
+ * (node) => node.kind === J.Kind.Literal && typeof node.value === 'string',
36
+ * (node) => node.kind === J.Kind.Literal && typeof node.value === 'number'
37
+ * )
38
+ * });
39
+ */
40
+ function or(...constraints) {
41
+ return (node, cursor) => constraints.some(c => c(node, cursor));
42
+ }
43
+ /**
44
+ * Negates a constraint.
45
+ * Returns true when the constraint returns false, and vice versa.
46
+ *
47
+ * @example
48
+ * const notString = capture('value', {
49
+ * constraint: not((node) => typeof node.value === 'string')
50
+ * });
51
+ */
52
+ function not(constraint) {
53
+ return (node, cursor) => !constraint(node, cursor);
54
+ }
55
+ // Symbol to access the internal capture name without triggering Proxy
56
+ exports.CAPTURE_NAME_SYMBOL = Symbol('captureName');
57
+ // Symbol to access variadic options without triggering Proxy
58
+ exports.CAPTURE_VARIADIC_SYMBOL = Symbol('captureVariadic');
59
+ // Symbol to access constraint function without triggering Proxy
60
+ exports.CAPTURE_CONSTRAINT_SYMBOL = Symbol('captureConstraint');
61
+ // Symbol to access capturing flag without triggering Proxy
62
+ exports.CAPTURE_CAPTURING_SYMBOL = Symbol('captureCapturing');
63
+ // Symbol to access type information without triggering Proxy
64
+ exports.CAPTURE_TYPE_SYMBOL = Symbol('captureType');
65
+ // Symbol to identify RawCode instances
66
+ exports.RAW_CODE_SYMBOL = Symbol('rawCode');
67
+ class CaptureImpl {
68
+ constructor(name, options, capturing = true) {
69
+ this.name = name;
70
+ this[exports.CAPTURE_NAME_SYMBOL] = name;
71
+ this[exports.CAPTURE_CAPTURING_SYMBOL] = capturing;
72
+ // Normalize variadic options
73
+ if (options === null || options === void 0 ? void 0 : options.variadic) {
74
+ if (typeof options.variadic === 'boolean') {
75
+ this[exports.CAPTURE_VARIADIC_SYMBOL] = {};
76
+ }
77
+ else {
78
+ this[exports.CAPTURE_VARIADIC_SYMBOL] = {
79
+ min: options.variadic.min,
80
+ max: options.variadic.max
81
+ };
82
+ }
83
+ }
84
+ // Store constraint if provided
85
+ if (options === null || options === void 0 ? void 0 : options.constraint) {
86
+ this[exports.CAPTURE_CONSTRAINT_SYMBOL] = options.constraint;
87
+ }
88
+ // Store type if provided
89
+ if (options === null || options === void 0 ? void 0 : options.type) {
90
+ this[exports.CAPTURE_TYPE_SYMBOL] = options.type;
91
+ }
92
+ }
93
+ getName() {
94
+ return this[exports.CAPTURE_NAME_SYMBOL];
95
+ }
96
+ isVariadic() {
97
+ return this[exports.CAPTURE_VARIADIC_SYMBOL] !== undefined;
98
+ }
99
+ getVariadicOptions() {
100
+ return this[exports.CAPTURE_VARIADIC_SYMBOL];
101
+ }
102
+ getConstraint() {
103
+ return this[exports.CAPTURE_CONSTRAINT_SYMBOL];
104
+ }
105
+ isCapturing() {
106
+ return this[exports.CAPTURE_CAPTURING_SYMBOL];
107
+ }
108
+ getType() {
109
+ return this[exports.CAPTURE_TYPE_SYMBOL];
110
+ }
111
+ }
112
+ exports.CaptureImpl = CaptureImpl;
113
+ class TemplateParamImpl {
114
+ constructor(name) {
115
+ this.name = name;
116
+ }
117
+ getName() {
118
+ return this.name;
119
+ }
120
+ }
121
+ exports.TemplateParamImpl = TemplateParamImpl;
122
+ /**
123
+ * Represents a property access on a captured value.
124
+ * When you access a property on a Capture (e.g., method.name), you get a CaptureValue
125
+ * that knows how to resolve that property from the matched values.
126
+ */
127
+ class CaptureValue {
128
+ constructor(rootCapture, propertyPath, arrayOperation) {
129
+ this.rootCapture = rootCapture;
130
+ this.propertyPath = propertyPath;
131
+ this.arrayOperation = arrayOperation;
132
+ }
133
+ /**
134
+ * Resolves this capture value by looking up the root capture in the values map
135
+ * and navigating through the property path.
136
+ */
137
+ resolve(values) {
138
+ const rootName = this.rootCapture.getName();
139
+ let current = values.get(rootName);
140
+ // Handle array operations on variadic captures
141
+ if (this.arrayOperation && Array.isArray(current)) {
142
+ switch (this.arrayOperation.type) {
143
+ case 'index':
144
+ current = current[this.arrayOperation.args[0]];
145
+ break;
146
+ case 'slice':
147
+ current = current.slice(...this.arrayOperation.args);
148
+ break;
149
+ case 'length':
150
+ current = current.length;
151
+ break;
152
+ }
153
+ }
154
+ // Navigate through property path
155
+ for (const prop of this.propertyPath) {
156
+ if (current === null || current === undefined || typeof current === 'number') {
157
+ return undefined;
158
+ }
159
+ current = current[prop];
160
+ }
161
+ return current;
162
+ }
163
+ /**
164
+ * Checks if this CaptureValue will resolve to an array that should be expanded.
165
+ */
166
+ isArrayExpansion() {
167
+ var _b, _c, _d;
168
+ // Only slice operations and the root variadic capture return arrays
169
+ return ((_b = this.arrayOperation) === null || _b === void 0 ? void 0 : _b.type) === 'slice' ||
170
+ (this.arrayOperation === undefined && this.propertyPath.length === 0 &&
171
+ ((_d = (_c = this.rootCapture).isVariadic) === null || _d === void 0 ? void 0 : _d.call(_c)));
172
+ }
173
+ }
174
+ exports.CaptureValue = CaptureValue;
175
+ /**
176
+ * Creates a Proxy around a CaptureValue that allows further property access.
177
+ * This enables chaining like method.name.simpleName
178
+ */
179
+ function createCaptureValueProxy(rootCapture, propertyPath, arrayOperation) {
180
+ const captureValue = new CaptureValue(rootCapture, propertyPath, arrayOperation);
181
+ return new Proxy(captureValue, {
182
+ get(target, prop) {
183
+ // Allow access to the CaptureValue instance itself and its methods
184
+ if (prop === 'resolve' || prop === 'rootCapture' || prop === 'propertyPath' ||
185
+ prop === 'arrayOperation' || prop === 'isArrayExpansion') {
186
+ const value = target[prop];
187
+ return typeof value === 'function' ? value.bind(target) : value;
188
+ }
189
+ // For string property access, extend the property path
190
+ if (typeof prop === 'string') {
191
+ return createCaptureValueProxy(target.rootCapture, [...target.propertyPath, prop], target.arrayOperation);
192
+ }
193
+ return undefined;
194
+ }
195
+ });
196
+ }
197
+ /**
198
+ * Creates a capture specification for use in template patterns.
199
+ *
200
+ * @template T The expected type of the captured AST node (for TypeScript autocomplete only)
201
+ * @returns A Capture object that supports property access for use in templates
202
+ *
203
+ * @remarks
204
+ * **Pattern Matching is Structural:**
205
+ *
206
+ * What a capture matches is determined by the pattern structure, not the type parameter:
207
+ * - `pattern`${capture('x')}`` matches ANY single expression (identifier, literal, call, binary, etc.)
208
+ * - `pattern`foo(${capture('x')})`` matches only expressions inside `foo()` calls
209
+ * - `pattern`${capture('x')} + ${capture('y')}`` matches only binary `+` expressions
210
+ *
211
+ * The TypeScript type parameter `<T>` provides IDE autocomplete but doesn't enforce runtime types.
212
+ *
213
+ * @example
214
+ * // Named inline captures
215
+ * const pat = pattern`${capture('left')} + ${capture('right')}`;
216
+ * // Matches: <any expression> + <any expression>
217
+ *
218
+ * // Unnamed captures
219
+ * const {left, right} = {left: capture(), right: capture()};
220
+ * const pattern = pattern`${left} + ${right}`;
221
+ *
222
+ * @example
223
+ * // Type parameter is for IDE autocomplete only
224
+ * const method = capture<J.MethodInvocation>('method');
225
+ * const pat = pattern`foo(${method})`;
226
+ * // Matches: foo(<any expression>) - not restricted to method invocations!
227
+ * // Type <J.MethodInvocation> only helps with autocomplete in your code
228
+ *
229
+ * @example
230
+ * // Structural pattern determines what matches
231
+ * const arg = capture('arg');
232
+ * const pat = pattern`process(${arg})`;
233
+ * // Matches: process(42), process("text"), process(x + y), etc.
234
+ * // The 'arg' capture will bind to whatever expression is passed to process()
235
+ *
236
+ * @example
237
+ * // Repeated patterns using the same capture
238
+ * const expr = capture('expr');
239
+ * const redundantOr = pattern`${expr} || ${expr}`;
240
+ * // Matches expressions where both sides are identical: x || x, foo() || foo()
241
+ *
242
+ * @example
243
+ * // Property access in templates
244
+ * const method = capture<J.MethodInvocation>('method');
245
+ * template`console.log(${method.name.simpleName})` // Accesses properties of captured node
246
+ */
247
+ /**
248
+ * Creates a Proxy wrapper for CaptureImpl that intercepts property accesses.
249
+ * Shared logic between capture() and any() to avoid duplication.
250
+ */
251
+ function createCaptureProxy(impl) {
252
+ return new Proxy(impl, {
253
+ get(target, prop) {
254
+ // Allow access to internal symbols
255
+ if (prop === exports.CAPTURE_NAME_SYMBOL) {
256
+ return target[exports.CAPTURE_NAME_SYMBOL];
257
+ }
258
+ if (prop === exports.CAPTURE_VARIADIC_SYMBOL) {
259
+ return target[exports.CAPTURE_VARIADIC_SYMBOL];
260
+ }
261
+ if (prop === exports.CAPTURE_CONSTRAINT_SYMBOL) {
262
+ return target[exports.CAPTURE_CONSTRAINT_SYMBOL];
263
+ }
264
+ if (prop === exports.CAPTURE_CAPTURING_SYMBOL) {
265
+ return target[exports.CAPTURE_CAPTURING_SYMBOL];
266
+ }
267
+ if (prop === exports.CAPTURE_TYPE_SYMBOL) {
268
+ return target[exports.CAPTURE_TYPE_SYMBOL];
269
+ }
270
+ // Support using Capture as object key via computed properties {[x]: value}
271
+ if (prop === Symbol.toPrimitive || prop === 'toString' || prop === 'valueOf') {
272
+ return () => target[exports.CAPTURE_NAME_SYMBOL];
273
+ }
274
+ // Allow methods to be called directly on the target
275
+ if (prop === 'getName' || prop === 'isVariadic' || prop === 'getVariadicOptions' || prop === 'getConstraint' || prop === 'isCapturing' || prop === 'getType') {
276
+ return target[prop].bind(target);
277
+ }
278
+ // For variadic captures, support array-like operations
279
+ if (target.isVariadic() && typeof prop === 'string') {
280
+ // Numeric index access: args[0], args[1], etc.
281
+ const indexNum = Number(prop);
282
+ if (!isNaN(indexNum) && indexNum >= 0 && Number.isInteger(indexNum)) {
283
+ return createCaptureValueProxy(target, [], { type: 'index', args: [indexNum] });
284
+ }
285
+ // Array method: slice
286
+ if (prop === 'slice') {
287
+ return (...args) => {
288
+ return createCaptureValueProxy(target, [], { type: 'slice', args });
289
+ };
290
+ }
291
+ // Array property: length
292
+ if (prop === 'length') {
293
+ return createCaptureValueProxy(target, [], { type: 'length' });
294
+ }
295
+ }
296
+ // For string property access, create a CaptureValue with a property path
297
+ if (typeof prop === 'string') {
298
+ return createCaptureValueProxy(target, [prop]);
299
+ }
300
+ return undefined;
301
+ }
302
+ });
303
+ }
304
+ // Implementation
305
+ function capture(nameOrOptions) {
306
+ let name;
307
+ let options;
308
+ if (typeof nameOrOptions === 'string') {
309
+ // Simple named capture: capture('name')
310
+ name = nameOrOptions;
311
+ options = undefined;
312
+ }
313
+ else {
314
+ // Options-based API: capture({ name: 'name', ...options }) or capture()
315
+ options = nameOrOptions;
316
+ name = options === null || options === void 0 ? void 0 : options.name;
317
+ }
318
+ const captureName = name || `unnamed_${capture.nextUnnamedId++}`;
319
+ const impl = new CaptureImpl(captureName, options);
320
+ return createCaptureProxy(impl);
321
+ }
322
+ // Static counter for generating unique IDs for unnamed captures
323
+ capture.nextUnnamedId = 1;
324
+ // Implementation
325
+ function any(options) {
326
+ const anonName = `anon_${any.nextAnonId++}`;
327
+ const impl = new CaptureImpl(anonName, options, false); // capturing = false
328
+ return createCaptureProxy(impl);
329
+ }
330
+ // Static counter for generating unique IDs for anonymous (non-capturing) patterns
331
+ any.nextAnonId = 1;
332
+ /**
333
+ * Creates a parameter specification for use in standalone templates (not used with patterns).
334
+ *
335
+ * Use `param()` when creating templates that are not used with pattern matching.
336
+ * Use `capture()` when the template works with a pattern.
337
+ *
338
+ * @template T The expected type of the parameter value (for TypeScript autocomplete only)
339
+ * @param name Optional name for the parameter. If not provided, an auto-generated name is used.
340
+ * @returns A TemplateParam object (simpler than Capture, no property access support)
341
+ *
342
+ * @remarks
343
+ * **When to use `param()` vs `capture()`:**
344
+ *
345
+ * - Use `param()` in **standalone templates** (no pattern matching involved)
346
+ * - Use `capture()` in **patterns** and templates used with patterns
347
+ *
348
+ * **Key Differences:**
349
+ * - `TemplateParam` is simpler - no property access proxy overhead
350
+ * - `Capture` supports property access (e.g., `capture('x').name.simpleName`)
351
+ * - Both work in templates, but `param()` makes intent clearer for standalone use
352
+ *
353
+ * @example
354
+ * // ✅ GOOD: Use param() for standalone templates
355
+ * const value = param<J.Literal>('value');
356
+ * const tmpl = template`return ${value} * 2;`;
357
+ * await tmpl.apply(cursor, node, new Map([['value', someLiteral]]));
358
+ *
359
+ * @example
360
+ * // ✅ GOOD: Use capture() with patterns
361
+ * const value = capture('value');
362
+ * const pat = pattern`foo(${value})`;
363
+ * const tmpl = template`bar(${value})`; // capture() makes sense here
364
+ *
365
+ * @example
366
+ * // ⚠️ CONFUSING: Using capture() in standalone template
367
+ * const value = capture('value');
368
+ * template`return ${value} * 2;`; // "Capturing" what? There's no pattern!
369
+ *
370
+ * @example
371
+ * // ❌ WRONG: param() doesn't support property access
372
+ * const node = param<J.MethodInvocation>('invocation');
373
+ * template`console.log(${node.name})` // Error! Use capture() for property access
374
+ */
375
+ function param(name) {
376
+ const paramName = name || `unnamed_${capture.nextUnnamedId++}`;
377
+ return new TemplateParamImpl(paramName);
378
+ }
379
+ /**
380
+ * Represents raw code that should be inserted verbatim into templates at construction time.
381
+ * This is useful for dynamic code generation where the code structure is determined at runtime.
382
+ */
383
+ class RawCode {
384
+ constructor(code) {
385
+ this.code = code;
386
+ this[_a] = true;
387
+ }
388
+ }
389
+ exports.RawCode = RawCode;
390
+ _a = exports.RAW_CODE_SYMBOL;
391
+ /**
392
+ * Creates a raw code specification for inserting literal code strings into templates.
393
+ *
394
+ * Use `raw()` when you need to insert code that is generated dynamically (e.g., from recipe options,
395
+ * computed field names, or programmatic string manipulation) directly into a template at construction time.
396
+ *
397
+ * The string is spliced into the template before parsing, so it becomes part of the template's AST.
398
+ * This is different from `param()` or `capture()` which are placeholders replaced during application.
399
+ *
400
+ * @param code The code string to insert verbatim into the template
401
+ * @returns A RawCode object that will be spliced into the template
402
+ *
403
+ * @remarks
404
+ * **When to use `raw()` vs `param()` vs `capture()`:**
405
+ *
406
+ * - Use `raw()` when you have a **code string** to insert at **template construction time**
407
+ * - Use `param()` when you have an **AST node** to substitute at **template application time**
408
+ * - Use `capture()` when working with **pattern matching** and need to reference matched values
409
+ *
410
+ * **Safety Considerations:**
411
+ * - No validation is performed on the code string
412
+ * - The code must be syntactically valid at the position where it's inserted
413
+ * - Recipe authors are trusted to provide valid code
414
+ *
415
+ * @example
416
+ * // Recipe option determines the log level
417
+ * class MyRecipe extends Recipe {
418
+ * @Option
419
+ * logLevel: string = "info";
420
+ *
421
+ * getVisitor() {
422
+ * // Template constructed with dynamic method name
423
+ * const replacement = template`logger.${raw(this.logLevel)}(${_('msg')})`;
424
+ * // Produces: logger.info(...) or logger.warn(...) etc.
425
+ * }
426
+ * }
427
+ *
428
+ * @example
429
+ * // Build object literal from collected field names
430
+ * const fields = ["userId", "timestamp", "status"];
431
+ * template`{ ${raw(fields.join(', '))} }`
432
+ * // Produces: { userId, timestamp, status }
433
+ *
434
+ * @example
435
+ * // Dynamic import path
436
+ * const modulePath = "./utils";
437
+ * template`import { helper } from ${raw(`'${modulePath}'`)}`
438
+ * // Produces: import { helper } from './utils'
439
+ *
440
+ * @example
441
+ * // Configurable operator
442
+ * const operator = ">=";
443
+ * template`${_('value')} ${raw(operator)} threshold`
444
+ * // Produces: value >= threshold
445
+ */
446
+ function raw(code) {
447
+ return new RawCode(code);
448
+ }
449
+ /**
450
+ * Concise alias for `capture`. Works well for inline captures in patterns and templates.
451
+ *
452
+ * @param name Optional name for the capture. If not provided, an auto-generated name is used.
453
+ * @returns A Capture object
454
+ *
455
+ * @example
456
+ * // Inline captures with _ alias
457
+ * pattern`isDate(${_('dateArg')})`
458
+ * template`${_('dateArg')} instanceof Date`
459
+ */
460
+ exports._ = capture;
461
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/javascript/templating/capture.ts"],"names":[],"mappings":";;;;AAgCA,kBAEC;AAcD,gBAEC;AAWD,kBAEC;AAgTD,0BAkBC;AAuED,kBAKC;AAgDD,sBAGC;AAmED,kBAEC;AAljBD;;;;;;;;;;;;GAYG;AACH,SAAgB,GAAG,CAAI,GAAG,WAAsD;IAC5E,OAAO,CAAC,IAAO,EAAE,MAAe,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,EAAE,CAAI,GAAG,WAAsD;IAC3E,OAAO,CAAC,IAAO,EAAE,MAAe,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CAAI,UAAiD;IACpE,OAAO,CAAC,IAAO,EAAE,MAAe,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnE,CAAC;AAED,sEAAsE;AACzD,QAAA,mBAAmB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACzD,6DAA6D;AAChD,QAAA,uBAAuB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACjE,gEAAgE;AACnD,QAAA,yBAAyB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACrE,2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AAU,IAAa;IACxC,MAAM,SAAS,GAAG,IAAI,IAAI,WAAW,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAC/D,OAAO,IAAI,iBAAiB,CAAI,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAa,OAAO;IAGhB,YAA4B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFxC,QAAiB,GAAG,IAAI,CAAC;IAEkB,CAAC;CAC/C;AAJD,0BAIC;KAHI,uBAAe;AAKpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,SAAgB,GAAG,CAAC,IAAY;IAC5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;GAUG;AACU,QAAA,CAAC,GAAG,OAAO,CAAC"}
@@ -0,0 +1,171 @@
1
+ import { Cursor, Tree } from '../..';
2
+ import { J } from '../../java';
3
+ import { JS } from '../index';
4
+ import { JavaScriptSemanticComparatorVisitor } from '../comparator';
5
+ import { CaptureMarker, CaptureStorageValue } from './utils';
6
+ import { DebugLogEntry, MatchExplanation } from './types';
7
+ /**
8
+ * Debug callbacks for pattern matching.
9
+ * These are always used together - either all present or all absent.
10
+ * Part of Layer 1 (Core Instrumentation).
11
+ */
12
+ export interface DebugCallbacks {
13
+ log: (level: DebugLogEntry['level'], scope: DebugLogEntry['scope'], message: string, data?: any) => void;
14
+ setExplanation: (reason: MatchExplanation['reason'], expected: string, actual: string, details?: string) => void;
15
+ getExplanation: () => MatchExplanation | undefined;
16
+ restoreExplanation: (explanation: MatchExplanation) => void;
17
+ clearExplanation: () => void;
18
+ pushPath: (name: string) => void;
19
+ popPath: () => void;
20
+ }
21
+ /**
22
+ * Snapshot of matcher state for backtracking.
23
+ * Includes both capture storage and debug state.
24
+ */
25
+ export interface MatcherState {
26
+ storage: Map<string, CaptureStorageValue>;
27
+ debugState?: {
28
+ explanation?: MatchExplanation;
29
+ logLength: number;
30
+ path: string[];
31
+ };
32
+ }
33
+ /**
34
+ * Callbacks for the matcher (debug and capture handling).
35
+ * Part of Layer 1 (Core Instrumentation).
36
+ */
37
+ export interface MatcherCallbacks {
38
+ handleCapture: (capture: CaptureMarker, target: J, wrapper?: J.RightPadded<J>) => boolean;
39
+ handleVariadicCapture: (capture: CaptureMarker, targets: J[], wrappers?: J.RightPadded<J>[]) => boolean;
40
+ saveState: () => MatcherState;
41
+ restoreState: (state: MatcherState) => void;
42
+ debug?: DebugCallbacks;
43
+ }
44
+ /**
45
+ * A comparator for pattern matching that is lenient about optional properties.
46
+ * Allows patterns without type annotations to match actual code with type annotations.
47
+ * Uses semantic comparison to match semantically equivalent code (e.g., isDate() and util.isDate()).
48
+ */
49
+ export declare class PatternMatchingComparator extends JavaScriptSemanticComparatorVisitor {
50
+ protected readonly matcher: MatcherCallbacks;
51
+ constructor(matcher: MatcherCallbacks, lenientTypeMatching?: boolean);
52
+ visit<R extends J>(j: Tree, p: J, parent?: Cursor): Promise<R | undefined>;
53
+ protected hasSameKind(j: J, other: J): boolean;
54
+ /**
55
+ * Additional specialized abort methods for pattern matching scenarios.
56
+ */
57
+ protected constraintFailed(captureName: string, targetKind: string): any;
58
+ protected captureConflict(captureName: string): any;
59
+ /**
60
+ * Override visitRightPadded to check if this wrapper has a CaptureMarker.
61
+ * If so, capture the entire wrapper (to preserve markers like semicolons).
62
+ */
63
+ visitRightPadded<T extends J | boolean>(right: J.RightPadded<T>, p: J): Promise<J.RightPadded<T>>;
64
+ visitContainer<T extends J>(container: J.Container<T>, p: J): Promise<J.Container<T>>;
65
+ /**
66
+ * Visit a single element in a container (for non-variadic matching).
67
+ * Extracted to allow debug subclass to add path tracking.
68
+ *
69
+ * @param element The pattern element
70
+ * @param otherElement The target element
71
+ * @param index The index in the container
72
+ * @returns true if matching should continue, false if it failed
73
+ */
74
+ protected visitContainerElement<T extends J>(element: J.RightPadded<T>, otherElement: J.RightPadded<T>, index: number): Promise<boolean>;
75
+ visitMethodInvocation(methodInvocation: J.MethodInvocation, other: J): Promise<J | undefined>;
76
+ visitBlock(block: J.Block, other: J): Promise<J | undefined>;
77
+ visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, other: J): Promise<J | undefined>;
78
+ /**
79
+ * Matches argument lists, with special handling for variadic captures.
80
+ * A variadic capture can match zero or more consecutive arguments.
81
+ */
82
+ private matchArguments;
83
+ /**
84
+ * Generic sequence matching with variadic capture support.
85
+ * Works for any sequence of JRightPadded elements (arguments, statements, etc.).
86
+ * A variadic capture can match zero or more consecutive elements.
87
+ *
88
+ * Uses pivot detection to optimize matching, with backtracking as fallback.
89
+ *
90
+ * @param patternElements The pattern elements (JRightPadded)
91
+ * @param targetElements The target elements to match against (JRightPadded)
92
+ * @param filterEmpty Whether to filter out J.Empty elements when capturing (true for arguments, false for statements)
93
+ * @returns true if the sequence matches, false otherwise
94
+ */
95
+ protected matchSequence(patternElements: J.RightPadded<J>[], targetElements: J.RightPadded<J>[], filterEmpty: boolean): Promise<boolean>;
96
+ /**
97
+ * Optimized sequence matcher with pivot detection and backtracking.
98
+ * For variadic patterns, tries to detect pivots (where next pattern matches) to avoid
99
+ * unnecessary backtracking. Falls back to full backtracking when pivots are ambiguous.
100
+ *
101
+ * @param patternElements The pattern elements (JRightPadded)
102
+ * @param targetElements The target elements to match against (JRightPadded)
103
+ * @param patternIdx Current position in pattern
104
+ * @param targetIdx Current position in target
105
+ * @param filterEmpty Whether to filter out J.Empty elements when capturing
106
+ * @returns true if the remaining sequence matches, false otherwise
107
+ */
108
+ protected matchSequenceOptimized(patternElements: J.RightPadded<J>[], targetElements: J.RightPadded<J>[], patternIdx: number, targetIdx: number, filterEmpty: boolean): Promise<boolean>;
109
+ /**
110
+ * Visit a single element in a sequence during non-variadic matching.
111
+ * Extracted to allow debug subclass to add path tracking.
112
+ *
113
+ * @param patternWrapper The pattern element
114
+ * @param targetWrapper The target element
115
+ * @param targetIdx The index in the target sequence
116
+ * @returns true if matching succeeded, false otherwise
117
+ */
118
+ protected visitSequenceElement(patternWrapper: J.RightPadded<J>, targetWrapper: J.RightPadded<J>, targetIdx: number): Promise<boolean>;
119
+ }
120
+ /**
121
+ * Debug-instrumented version of PatternMatchingComparator.
122
+ * Overrides methods to add path tracking, logging, and explanation capture.
123
+ * Zero cost when not instantiated - production code uses the base class.
124
+ */
125
+ export declare class DebugPatternMatchingComparator extends PatternMatchingComparator {
126
+ private get debug();
127
+ /**
128
+ * Extracts the last segment of a kind string (after the last dot).
129
+ * For example: "org.openrewrite.java.tree.J.MethodInvocation" -> "MethodInvocation"
130
+ */
131
+ private formatKind;
132
+ /**
133
+ * Formats a value for display in error messages.
134
+ */
135
+ private formatValue;
136
+ /**
137
+ * Override abort to capture explanation when debug is enabled.
138
+ * Only sets explanation on the first abort call (when this.match is still true).
139
+ * This preserves the most specific explanation closest to the actual mismatch.
140
+ */
141
+ protected abort<T>(t: T, reason?: string, propertyName?: string, expected?: any, actual?: any): T;
142
+ /**
143
+ * Override helper methods to extract detailed context from cursors.
144
+ */
145
+ protected kindMismatch(): any;
146
+ protected structuralMismatch(propertyName: string): any;
147
+ protected arrayLengthMismatch(propertyName: string): any;
148
+ protected valueMismatch(propertyName?: string, expected?: any, actual?: any): any;
149
+ visit<R extends J>(j: Tree, p: J, parent?: Cursor): Promise<R | undefined>;
150
+ protected visitElement<T extends J>(j: T, other: T): Promise<T>;
151
+ visitRightPadded<T extends J | boolean>(right: J.RightPadded<T>, p: J): Promise<J.RightPadded<T>>;
152
+ visitContainer<T extends J>(container: J.Container<T>, p: J): Promise<J.Container<T>>;
153
+ /**
154
+ * Override visitContainerProperty to add path tracking with property context.
155
+ */
156
+ protected visitContainerProperty<T extends J>(propertyName: string, container: J.Container<T>, otherContainer: J.Container<T>): Promise<J.Container<T>>;
157
+ /**
158
+ * Override visitRightPaddedProperty to add path tracking with property context.
159
+ */
160
+ protected visitRightPaddedProperty<T extends J | boolean>(propertyName: string, rightPadded: J.RightPadded<T>, otherRightPadded: J.RightPadded<T>): Promise<J.RightPadded<T>>;
161
+ /**
162
+ * Override visitLeftPaddedProperty to add path tracking with property context.
163
+ */
164
+ protected visitLeftPaddedProperty<T extends J | J.Space | number | string | boolean>(propertyName: string, leftPadded: J.LeftPadded<T>, otherLeftPadded: J.LeftPadded<T>): Promise<J.LeftPadded<T>>;
165
+ protected visitContainerElement<T extends J>(element: J.RightPadded<T>, otherElement: J.RightPadded<T>, index: number): Promise<boolean>;
166
+ protected visitArrayProperty<T>(parent: J, propertyName: string, array1: T[], array2: T[], visitor: (item1: T, item2: T, index: number) => Promise<void>): Promise<void>;
167
+ protected matchSequence(patternElements: J.RightPadded<J>[], targetElements: J.RightPadded<J>[], filterEmpty: boolean): Promise<boolean>;
168
+ protected visitSequenceElement(patternWrapper: J.RightPadded<J>, targetWrapper: J.RightPadded<J>, targetIdx: number): Promise<boolean>;
169
+ protected matchSequenceOptimized(patternElements: J.RightPadded<J>[], targetElements: J.RightPadded<J>[], patternIdx: number, targetIdx: number, filterEmpty: boolean): Promise<boolean>;
170
+ }
171
+ //# 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,EAAC,aAAa,EAAE,mBAAmB,EAAmB,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,GAAG,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CA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