@openrewrite/rewrite 8.66.1 → 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.
- package/dist/java/tree.d.ts +10 -1
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/tree.js +21 -5
- package/dist/java/tree.js.map +1 -1
- package/dist/java/type-visitor.d.ts +1 -1
- package/dist/java/type-visitor.d.ts.map +1 -1
- package/dist/java/visitor.d.ts +2 -2
- package/dist/java/visitor.d.ts.map +1 -1
- package/dist/java/visitor.js +8 -2
- package/dist/java/visitor.js.map +1 -1
- package/dist/javascript/assertions.d.ts +6 -0
- package/dist/javascript/assertions.d.ts.map +1 -1
- package/dist/javascript/assertions.js +14 -6
- package/dist/javascript/assertions.js.map +1 -1
- package/dist/javascript/comparator.d.ts +154 -7
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +623 -180
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format.d.ts +5 -3
- package/dist/javascript/format.d.ts.map +1 -1
- package/dist/javascript/format.js +85 -43
- package/dist/javascript/format.js.map +1 -1
- package/dist/javascript/index.d.ts +1 -0
- package/dist/javascript/index.d.ts.map +1 -1
- package/dist/javascript/index.js +1 -0
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/parser.d.ts +2 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +39 -30
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/templating/capture.d.ts +81 -14
- package/dist/javascript/templating/capture.d.ts.map +1 -1
- package/dist/javascript/templating/capture.js +98 -8
- package/dist/javascript/templating/capture.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +125 -15
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +946 -118
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/engine.d.ts +58 -25
- package/dist/javascript/templating/engine.d.ts.map +1 -1
- package/dist/javascript/templating/engine.js +527 -94
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/index.d.ts +3 -3
- package/dist/javascript/templating/index.d.ts.map +1 -1
- package/dist/javascript/templating/index.js +3 -1
- package/dist/javascript/templating/index.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts +121 -16
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +528 -257
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts +30 -5
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +183 -81
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/rewrite.d.ts +56 -11
- package/dist/javascript/templating/rewrite.d.ts.map +1 -1
- package/dist/javascript/templating/rewrite.js +143 -16
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/javascript/templating/template.d.ts +31 -5
- package/dist/javascript/templating/template.d.ts.map +1 -1
- package/dist/javascript/templating/template.js +89 -15
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +359 -12
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/javascript/templating/utils.d.ts +52 -35
- package/dist/javascript/templating/utils.d.ts.map +1 -1
- package/dist/javascript/templating/utils.js +107 -109
- package/dist/javascript/templating/utils.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +21 -11
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/json/rpc.js +2 -2
- package/dist/json/rpc.js.map +1 -1
- package/dist/recipe/order-imports.js.map +1 -1
- package/dist/test/rewrite-test.d.ts.map +1 -1
- package/dist/test/rewrite-test.js +10 -6
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/version.txt +1 -1
- package/dist/visitor.d.ts +4 -4
- package/dist/visitor.d.ts.map +1 -1
- package/dist/visitor.js +8 -3
- package/dist/visitor.js.map +1 -1
- package/package.json +4 -2
- package/src/java/tree.ts +10 -3
- package/src/java/type-visitor.ts +1 -1
- package/src/java/visitor.ts +11 -5
- package/src/javascript/assertions.ts +9 -3
- package/src/javascript/comparator.ts +676 -185
- package/src/javascript/format.ts +72 -34
- package/src/javascript/index.ts +1 -0
- package/src/javascript/parser.ts +51 -31
- package/src/javascript/templating/capture.ts +107 -15
- package/src/javascript/templating/comparator.ts +1087 -134
- package/src/javascript/templating/engine.ts +601 -103
- package/src/javascript/templating/index.ts +9 -2
- package/src/javascript/templating/pattern.ts +655 -281
- package/src/javascript/templating/placeholder-replacement.ts +183 -80
- package/src/javascript/templating/rewrite.ts +152 -18
- package/src/javascript/templating/template.ts +110 -22
- package/src/javascript/templating/types.ts +386 -12
- package/src/javascript/templating/utils.ts +116 -102
- package/src/javascript/type-mapping.ts +20 -11
- package/src/json/rpc.ts +2 -2
- package/src/recipe/order-imports.ts +1 -1
- package/src/test/rewrite-test.ts +12 -7
- package/src/visitor.ts +14 -6
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Cursor, Tree } from '../..';
|
|
2
|
-
import { J } from '../../java';
|
|
2
|
+
import { J, Type } from '../../java';
|
|
3
|
+
import type { Pattern } from "./pattern";
|
|
4
|
+
import type { Template } from "./template";
|
|
5
|
+
import type { CaptureValue, RawCode } from "./capture";
|
|
3
6
|
/**
|
|
4
7
|
* Options for variadic captures that match zero or more nodes in a sequence.
|
|
5
8
|
*/
|
|
@@ -13,6 +16,18 @@ export interface VariadicOptions {
|
|
|
13
16
|
*/
|
|
14
17
|
max?: number;
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Constraint function for captures.
|
|
21
|
+
* The cursor parameter is always provided with a defined value, but functions can
|
|
22
|
+
* choose to accept it or not (TypeScript allows functions with fewer parameters).
|
|
23
|
+
*
|
|
24
|
+
* For non-variadic captures: use ConstraintFunction<T> where T is the node type
|
|
25
|
+
* For variadic captures: use ConstraintFunction<T[]> where T[] is the array type
|
|
26
|
+
*
|
|
27
|
+
* When used with variadic captures, the cursor points to the nearest common parent
|
|
28
|
+
* of the captured elements.
|
|
29
|
+
*/
|
|
30
|
+
export type ConstraintFunction<T> = (node: T, cursor: Cursor) => boolean;
|
|
16
31
|
/**
|
|
17
32
|
* Options for the capture function.
|
|
18
33
|
*
|
|
@@ -20,11 +35,53 @@ export interface VariadicOptions {
|
|
|
20
35
|
* the capture is variadic:
|
|
21
36
|
* - For regular captures: constraint receives a single node of type T
|
|
22
37
|
* - For variadic captures: constraint receives an array of nodes of type T[]
|
|
38
|
+
*
|
|
39
|
+
* The constraint function can optionally receive a cursor parameter to perform
|
|
40
|
+
* context-aware validation during pattern matching.
|
|
23
41
|
*/
|
|
24
42
|
export interface CaptureOptions<T = any> {
|
|
25
43
|
name?: string;
|
|
26
44
|
variadic?: boolean | VariadicOptions;
|
|
27
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Optional constraint function that validates whether a captured node should be accepted.
|
|
47
|
+
* The function always receives:
|
|
48
|
+
* - node: The captured node (or array of nodes for variadic captures)
|
|
49
|
+
* - cursor: A cursor at the captured node's position (always defined)
|
|
50
|
+
*
|
|
51
|
+
* Functions can choose to accept just the node parameter if they don't need the cursor.
|
|
52
|
+
*
|
|
53
|
+
* @param node The captured node to validate
|
|
54
|
+
* @param cursor Cursor at the captured node's position
|
|
55
|
+
* @returns true if the capture should be accepted, false otherwise
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Simple node validation (cursor parameter ignored)
|
|
60
|
+
* capture<J.Literal>('size', {
|
|
61
|
+
* constraint: (node) => typeof node.value === 'number' && node.value > 100
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* // Context-aware validation (using cursor)
|
|
65
|
+
* capture<J.MethodInvocation>('method', {
|
|
66
|
+
* constraint: (node, cursor) => {
|
|
67
|
+
* if (!node.name.simpleName.startsWith('get')) return false;
|
|
68
|
+
* const cls = cursor.firstEnclosing(isClassDeclaration);
|
|
69
|
+
* return cls?.name.simpleName === 'ApiController';
|
|
70
|
+
* }
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
constraint?: ConstraintFunction<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Type annotation for this capture. When provided, the template engine will generate
|
|
77
|
+
* a preamble declaring the capture identifier with this type annotation, allowing
|
|
78
|
+
* the TypeScript parser/compiler to produce a properly type-attributed AST.
|
|
79
|
+
*
|
|
80
|
+
* Can be specified as:
|
|
81
|
+
* - A string type annotation (e.g., "boolean", "string", "number")
|
|
82
|
+
* - A Type instance from the AST (the type will be inferred from the Type)
|
|
83
|
+
*/
|
|
84
|
+
type?: string | Type;
|
|
28
85
|
}
|
|
29
86
|
/**
|
|
30
87
|
* Capture specification for pattern matching.
|
|
@@ -39,14 +96,14 @@ export interface CaptureOptions<T = any> {
|
|
|
39
96
|
* but does NOT enforce any runtime constraints on what the capture will match.
|
|
40
97
|
*
|
|
41
98
|
* **Pattern Matching Behavior:**
|
|
42
|
-
* - A bare `pattern`${capture(
|
|
43
|
-
* - Pattern structure determines matching: `pattern`foo(${capture(
|
|
99
|
+
* - A bare `pattern`${capture()}`` will structurally match ANY expression
|
|
100
|
+
* - Pattern structure determines matching: `pattern`foo(${capture()})`` only matches `foo()` calls with one arg
|
|
44
101
|
* - Use structural patterns to narrow matching scope before applying semantic validation
|
|
45
102
|
*
|
|
46
103
|
* **Variadic Captures:**
|
|
47
104
|
* Use `{ variadic: true }` to match zero or more nodes in a sequence:
|
|
48
105
|
* ```typescript
|
|
49
|
-
* const args = capture(
|
|
106
|
+
* const args = capture({ variadic: true });
|
|
50
107
|
* pattern`foo(${args})` // Matches: foo(), foo(a), foo(a, b, c)
|
|
51
108
|
* ```
|
|
52
109
|
*/
|
|
@@ -67,8 +124,9 @@ export interface Capture<T = any> {
|
|
|
67
124
|
* Gets the constraint function if this capture has one.
|
|
68
125
|
* For regular captures (T = Expression), constraint receives a single node.
|
|
69
126
|
* For variadic captures (T = Expression[]), constraint receives an array of nodes.
|
|
127
|
+
* The constraint function can optionally receive a cursor for context-aware validation.
|
|
70
128
|
*/
|
|
71
|
-
getConstraint?():
|
|
129
|
+
getConstraint?(): ConstraintFunction<T> | undefined;
|
|
72
130
|
}
|
|
73
131
|
/**
|
|
74
132
|
* Non-capturing pattern match specification.
|
|
@@ -102,8 +160,9 @@ export interface Capture<T = any> {
|
|
|
102
160
|
*
|
|
103
161
|
* @example
|
|
104
162
|
* // Variadic any - match zero or more without capturing
|
|
163
|
+
* const first = any();
|
|
105
164
|
* const rest = any({ variadic: true });
|
|
106
|
-
* const pat = pattern`bar(${
|
|
165
|
+
* const pat = pattern`bar(${first}, ${rest})`
|
|
107
166
|
*
|
|
108
167
|
* @example
|
|
109
168
|
* // With constraints - validate but don't capture
|
|
@@ -130,7 +189,7 @@ export interface Any<T = any> {
|
|
|
130
189
|
* For regular any (T = Expression), constraint receives a single node.
|
|
131
190
|
* For variadic any (T = Expression[]), constraint receives an array of nodes.
|
|
132
191
|
*/
|
|
133
|
-
getConstraint?():
|
|
192
|
+
getConstraint?(): ConstraintFunction<T> | undefined;
|
|
134
193
|
}
|
|
135
194
|
/**
|
|
136
195
|
* Template parameter specification for template-only parameter substitution.
|
|
@@ -192,16 +251,79 @@ export interface PatternOptions {
|
|
|
192
251
|
* @default true (lenient matching enabled for backward compatibility)
|
|
193
252
|
*/
|
|
194
253
|
lenientTypeMatching?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Enable debug logging for this pattern.
|
|
256
|
+
* When enabled, all match attempts will log detailed information to stderr,
|
|
257
|
+
* including the AST path traversed, mismatches encountered, and captured values.
|
|
258
|
+
*
|
|
259
|
+
* Can be overridden at the match() call level.
|
|
260
|
+
* Global debug can be enabled via PATTERN_DEBUG=true environment variable.
|
|
261
|
+
*
|
|
262
|
+
* Precedence: match() call > pattern configure() > PATTERN_DEBUG env var
|
|
263
|
+
*
|
|
264
|
+
* @default undefined (inherits from environment or match() call)
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* // Pattern-level debug
|
|
269
|
+
* const pat = pattern({ debug: true })`console.log(${value})`;
|
|
270
|
+
*
|
|
271
|
+
* // Disable debug for a noisy pattern when global debug is on
|
|
272
|
+
* const noisyPat = pattern({ debug: false })`import ${x} from ${y}`;
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
debug?: boolean;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Options for individual match() calls.
|
|
279
|
+
*/
|
|
280
|
+
export interface MatchOptions {
|
|
281
|
+
/**
|
|
282
|
+
* Enable debug logging for this specific match() call.
|
|
283
|
+
* Overrides pattern-level debug setting and global PATTERN_DEBUG env var.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Debug just this call
|
|
288
|
+
* const match = await pattern.match(node, cursor, { debug: true });
|
|
289
|
+
*
|
|
290
|
+
* // Disable debug for this call even if pattern or global debug is on
|
|
291
|
+
* const match = await pattern.match(node, cursor, { debug: false });
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
debug?: boolean;
|
|
195
295
|
}
|
|
196
296
|
/**
|
|
197
297
|
* Valid parameter types for template literals.
|
|
198
298
|
* - Capture: For pattern matching and reuse
|
|
199
299
|
* - CaptureValue: Result of property access or array operations on captures (e.g., capture.prop, capture[0], capture.slice(1))
|
|
300
|
+
* - TemplateParam: For standalone template parameters
|
|
301
|
+
* - RawCode: For inserting literal code strings at construction time
|
|
200
302
|
* - Tree: AST nodes to be inserted directly
|
|
201
303
|
* - Tree[]: Arrays of AST nodes (from variadic capture operations like slice)
|
|
202
|
-
* -
|
|
304
|
+
* - J.RightPadded<any>: Wrapper containing an element with markers (element will be extracted)
|
|
305
|
+
* - J.RightPadded<any>[]: Array of wrappers (elements will be expanded)
|
|
306
|
+
* - J.Container<any>: Container with elements (elements will be expanded)
|
|
307
|
+
*
|
|
308
|
+
* Note: Primitive values (string, number, boolean) are NOT supported in template literals.
|
|
309
|
+
* Use raw() for inserting code strings, or Template.builder() API for programmatic construction.
|
|
203
310
|
*/
|
|
204
|
-
export type TemplateParameter = Capture |
|
|
311
|
+
export type TemplateParameter = Capture | CaptureValue | TemplateParam | RawCode | Tree | Tree[] | J.RightPadded<any> | J.RightPadded<any>[] | J.Container<any>;
|
|
312
|
+
/**
|
|
313
|
+
* Parameter specification for template generation (internal).
|
|
314
|
+
* Represents a placeholder in a template that will be replaced with a parameter value.
|
|
315
|
+
* This is the internal wrapper used by the template engine.
|
|
316
|
+
*
|
|
317
|
+
* Note: The value is typed as `any` rather than `TemplateParameter` to allow flexible
|
|
318
|
+
* internal handling without excessive type guards. The public API (template function)
|
|
319
|
+
* constrains inputs to `TemplateParameter`, providing type safety at the API boundary.
|
|
320
|
+
*/
|
|
321
|
+
export interface Parameter {
|
|
322
|
+
/**
|
|
323
|
+
* The value to substitute into the template.
|
|
324
|
+
*/
|
|
325
|
+
value: any;
|
|
326
|
+
}
|
|
205
327
|
/**
|
|
206
328
|
* Configuration options for templates.
|
|
207
329
|
*/
|
|
@@ -252,12 +374,237 @@ export interface RewriteRule {
|
|
|
252
374
|
* node when there's no match: `return await rule.tryOn(this.cursor, node) || node;`
|
|
253
375
|
*/
|
|
254
376
|
tryOn(cursor: Cursor, node: J): Promise<J | undefined>;
|
|
377
|
+
/**
|
|
378
|
+
* Chains this rule with another rule, creating a composite rule that applies both transformations sequentially.
|
|
379
|
+
*
|
|
380
|
+
* The resulting rule:
|
|
381
|
+
* 1. First applies this rule to the input node
|
|
382
|
+
* 2. If this rule matches and transforms the node, applies the next rule to the result
|
|
383
|
+
* 3. If the next rule returns undefined (no match), keeps the result from the first rule
|
|
384
|
+
* 4. If this rule returns undefined (no match), returns undefined without trying the next rule
|
|
385
|
+
*
|
|
386
|
+
* @param next The rule to apply after this rule
|
|
387
|
+
* @returns A new RewriteRule that applies both rules in sequence
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const rule1 = rewrite(() => {
|
|
392
|
+
* const { a, b } = { a: capture(), b: capture() };
|
|
393
|
+
* return {
|
|
394
|
+
* before: pattern`${a} + ${b}`,
|
|
395
|
+
* after: template`${b} + ${a}`
|
|
396
|
+
* };
|
|
397
|
+
* });
|
|
398
|
+
*
|
|
399
|
+
* const rule2 = rewrite(() => ({
|
|
400
|
+
* before: pattern`${capture('x')} + 1`,
|
|
401
|
+
* after: template`${capture('x')}++`
|
|
402
|
+
* }));
|
|
403
|
+
*
|
|
404
|
+
* const combined = rule1.andThen(rule2);
|
|
405
|
+
* // Will first swap operands, then if result matches "x + 1", change to "x++"
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
andThen(next: RewriteRule): RewriteRule;
|
|
409
|
+
/**
|
|
410
|
+
* Creates a composite rule that tries this rule first, and if it doesn't match, tries an alternative rule.
|
|
411
|
+
*
|
|
412
|
+
* The resulting rule:
|
|
413
|
+
* 1. First applies this rule to the input node
|
|
414
|
+
* 2. If this rule matches and transforms the node, returns the result
|
|
415
|
+
* 3. If this rule returns undefined (no match), tries the alternative rule on the original node
|
|
416
|
+
*
|
|
417
|
+
* @param alternative The rule to try if this rule doesn't match
|
|
418
|
+
* @returns A new RewriteRule that tries both rules with fallback behavior
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* // Try specific pattern first, fall back to general pattern
|
|
423
|
+
* const specific = rewrite(() => ({
|
|
424
|
+
* before: pattern`foo(${capture('x')}, 0)`,
|
|
425
|
+
* after: template`bar(${capture('x')})`
|
|
426
|
+
* }));
|
|
427
|
+
*
|
|
428
|
+
* const general = rewrite(() => ({
|
|
429
|
+
* before: pattern`foo(${capture('x')}, ${capture('y')})`,
|
|
430
|
+
* after: template`baz(${capture('x')}, ${capture('y')})`
|
|
431
|
+
* }));
|
|
432
|
+
*
|
|
433
|
+
* const combined = specific.orElse(general);
|
|
434
|
+
* // Will try specific pattern first, if no match, try general pattern
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
orElse(alternative: RewriteRule): RewriteRule;
|
|
255
438
|
}
|
|
256
439
|
/**
|
|
257
440
|
* Configuration for a replacement rule.
|
|
258
441
|
*/
|
|
259
442
|
export interface RewriteConfig {
|
|
260
|
-
before:
|
|
261
|
-
after:
|
|
443
|
+
before: Pattern | Pattern[];
|
|
444
|
+
after: Template | ((match: MatchResult) => Template);
|
|
445
|
+
/**
|
|
446
|
+
* Optional context predicate that must evaluate to true for the transformation to be applied.
|
|
447
|
+
* Evaluated after the pattern matches structurally but before applying the template.
|
|
448
|
+
* Provides access to both the matched node and the cursor for context inspection.
|
|
449
|
+
*
|
|
450
|
+
* @param node The matched AST node
|
|
451
|
+
* @param cursor The cursor at the matched node, providing access to ancestors and context
|
|
452
|
+
* @returns true if the transformation should be applied, false otherwise
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* rewrite(() => ({
|
|
457
|
+
* before: pattern`await ${_('promise')}`,
|
|
458
|
+
* after: template`await ${_('promise')}.catch(handleError)`,
|
|
459
|
+
* where: (node, cursor) => {
|
|
460
|
+
* // Only apply inside async functions
|
|
461
|
+
* const method = cursor.firstEnclosing((n: any): n is J.MethodDeclaration =>
|
|
462
|
+
* n.kind === J.Kind.MethodDeclaration
|
|
463
|
+
* );
|
|
464
|
+
* return method?.modifiers.some(m => m.type === 'async') || false;
|
|
465
|
+
* }
|
|
466
|
+
* }));
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
where?: (node: J, cursor: Cursor) => boolean | Promise<boolean>;
|
|
470
|
+
/**
|
|
471
|
+
* Optional context predicate that must evaluate to false for the transformation to be applied.
|
|
472
|
+
* Evaluated after the pattern matches structurally but before applying the template.
|
|
473
|
+
* Provides access to both the matched node and the cursor for context inspection.
|
|
474
|
+
*
|
|
475
|
+
* @param node The matched AST node
|
|
476
|
+
* @param cursor The cursor at the matched node, providing access to ancestors and context
|
|
477
|
+
* @returns true if the transformation should NOT be applied, false if it should proceed
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* rewrite(() => ({
|
|
482
|
+
* before: pattern`await ${_('promise')}`,
|
|
483
|
+
* after: template`await ${_('promise')}.catch(handleError)`,
|
|
484
|
+
* whereNot: (node, cursor) => {
|
|
485
|
+
* // Don't apply inside try-catch blocks
|
|
486
|
+
* return cursor.firstEnclosing((n: any): n is J.Try =>
|
|
487
|
+
* n.kind === J.Kind.Try
|
|
488
|
+
* ) !== undefined;
|
|
489
|
+
* }
|
|
490
|
+
* }));
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
whereNot?: (node: J, cursor: Cursor) => boolean | Promise<boolean>;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Options for debugging pattern matching.
|
|
497
|
+
* Used in Layer 1 (Core Instrumentation) to control debug output.
|
|
498
|
+
*/
|
|
499
|
+
export interface DebugOptions {
|
|
500
|
+
/**
|
|
501
|
+
* Enable detailed logging during pattern matching.
|
|
502
|
+
*/
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Log structural comparison steps.
|
|
506
|
+
*/
|
|
507
|
+
logComparison?: boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Log constraint evaluation.
|
|
510
|
+
*/
|
|
511
|
+
logConstraints?: boolean;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* A single debug log entry collected during pattern matching.
|
|
515
|
+
* Part of Layer 1 (Core Instrumentation).
|
|
516
|
+
*/
|
|
517
|
+
export interface DebugLogEntry {
|
|
518
|
+
/**
|
|
519
|
+
* Severity level of the log entry.
|
|
520
|
+
*/
|
|
521
|
+
level: 'trace' | 'debug' | 'info' | 'warn';
|
|
522
|
+
/**
|
|
523
|
+
* The scope/category of the log entry.
|
|
524
|
+
*/
|
|
525
|
+
scope: 'matching' | 'comparison' | 'constraint';
|
|
526
|
+
/**
|
|
527
|
+
* Path in the AST where this log entry was generated.
|
|
528
|
+
*/
|
|
529
|
+
path: string[];
|
|
530
|
+
/**
|
|
531
|
+
* Human-readable message.
|
|
532
|
+
*/
|
|
533
|
+
message: string;
|
|
534
|
+
/**
|
|
535
|
+
* Optional data associated with this log entry.
|
|
536
|
+
*/
|
|
537
|
+
data?: any;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Detailed explanation of why a pattern failed to match.
|
|
541
|
+
* Built by Layer 1 (Core Instrumentation) and exposed by Layer 2 (API).
|
|
542
|
+
*/
|
|
543
|
+
export interface MatchExplanation {
|
|
544
|
+
/**
|
|
545
|
+
* The reason for the match failure.
|
|
546
|
+
*/
|
|
547
|
+
reason: 'structural-mismatch' | 'constraint-failed' | 'type-mismatch' | 'kind-mismatch' | 'value-mismatch' | 'array-length-mismatch';
|
|
548
|
+
/**
|
|
549
|
+
* Path in the AST where the failure occurred (e.g., ['select', 'name']).
|
|
550
|
+
*/
|
|
551
|
+
path: string[];
|
|
552
|
+
/**
|
|
553
|
+
* Human-readable description of what was expected.
|
|
554
|
+
*/
|
|
555
|
+
expected: string;
|
|
556
|
+
/**
|
|
557
|
+
* Human-readable description of what was actually found.
|
|
558
|
+
*/
|
|
559
|
+
actual: string;
|
|
560
|
+
/**
|
|
561
|
+
* For constraint failures, details about which constraints failed.
|
|
562
|
+
*/
|
|
563
|
+
constraintFailures?: Array<{
|
|
564
|
+
captureName: string;
|
|
565
|
+
actualValue: any;
|
|
566
|
+
error?: string;
|
|
567
|
+
}>;
|
|
568
|
+
/**
|
|
569
|
+
* Additional context about the failure.
|
|
570
|
+
*/
|
|
571
|
+
details?: string;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Interface for accessing captured nodes from a successful pattern match.
|
|
575
|
+
* Part of the public API.
|
|
576
|
+
*/
|
|
577
|
+
export interface MatchResult {
|
|
578
|
+
/**
|
|
579
|
+
* Get a captured node by name or by Capture object.
|
|
580
|
+
*
|
|
581
|
+
* @param capture The capture name (string) or Capture object
|
|
582
|
+
* @returns The captured node(s), or undefined if not found
|
|
583
|
+
*/
|
|
584
|
+
get(capture: string): any;
|
|
585
|
+
get<T>(capture: Capture<T>): T | undefined;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Result of a pattern match attempt with debug information.
|
|
589
|
+
* Part of Layer 2 (Public API).
|
|
590
|
+
*/
|
|
591
|
+
export interface MatchAttemptResult {
|
|
592
|
+
/**
|
|
593
|
+
* Whether the pattern matched successfully.
|
|
594
|
+
*/
|
|
595
|
+
matched: boolean;
|
|
596
|
+
/**
|
|
597
|
+
* If matched, the match result with captured nodes. Undefined if not matched.
|
|
598
|
+
* Use `result.get('captureName')` or `result.get(captureObject)` to access captures.
|
|
599
|
+
*/
|
|
600
|
+
result?: MatchResult;
|
|
601
|
+
/**
|
|
602
|
+
* If not matched, explanation of why. Undefined if matched.
|
|
603
|
+
*/
|
|
604
|
+
explanation?: MatchExplanation;
|
|
605
|
+
/**
|
|
606
|
+
* Debug log entries collected during matching (if debug was enabled).
|
|
607
|
+
*/
|
|
608
|
+
debugLog?: DebugLogEntry[];
|
|
262
609
|
}
|
|
263
610
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/types.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,CAAC;AACnC,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/types.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,CAAC;AACnC,OAAO,EAAC,CAAC,EAAE,I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H,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC9B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { J } from '../../java';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { VariadicOptions, Capture, Any } from './types';
|
|
2
|
+
import { Marker, Markers } from '../../markers';
|
|
3
|
+
import { ConstraintFunction, VariadicOptions } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Internal storage value type for pattern match captures.
|
|
7
6
|
* - J: Scalar captures without wrapper (fallback)
|
|
@@ -15,25 +14,42 @@ export type CaptureStorageValue = J | J.RightPadded<J> | J[] | J.RightPadded<J>[
|
|
|
15
14
|
*/
|
|
16
15
|
export declare const WRAPPERS_MAP_SYMBOL: unique symbol;
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* Shared wrapper function name used by both patterns and templates.
|
|
18
|
+
* Using the same name allows cache sharing when pattern and template code is identical.
|
|
20
19
|
*/
|
|
21
|
-
export declare
|
|
20
|
+
export declare const WRAPPER_FUNCTION_NAME = "__WRAPPER__";
|
|
21
|
+
/**
|
|
22
|
+
* Simple LRU (Least Recently Used) cache implementation using Map's insertion order.
|
|
23
|
+
* JavaScript Map maintains insertion order, so the first entry is the oldest.
|
|
24
|
+
*
|
|
25
|
+
* Used by both Pattern and Template caching to provide bounded memory usage.
|
|
26
|
+
*/
|
|
27
|
+
export declare class LRUCache<K, V> {
|
|
28
|
+
private maxSize;
|
|
22
29
|
private cache;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private generateKey;
|
|
27
|
-
/**
|
|
28
|
-
* Gets a cached compilation unit or creates and caches a new one.
|
|
29
|
-
*/
|
|
30
|
-
getOrParse(templateString: string, captures: (Capture | Any<any>)[], contextStatements: string[], dependencies: Record<string, string>): Promise<JS.CompilationUnit>;
|
|
31
|
-
/**
|
|
32
|
-
* Clears the cache.
|
|
33
|
-
*/
|
|
30
|
+
constructor(maxSize: number);
|
|
31
|
+
get(key: K): V | undefined;
|
|
32
|
+
set(key: K, value: V): void;
|
|
34
33
|
clear(): void;
|
|
35
34
|
}
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Shared global LRU cache for both pattern and template ASTs.
|
|
37
|
+
* When pattern and template code is identical, they share the same cached AST.
|
|
38
|
+
* This mirrors JavaTemplate's unified approach in the Java implementation.
|
|
39
|
+
* Bounded to 100 entries using LRU eviction.
|
|
40
|
+
*/
|
|
41
|
+
export declare const globalAstCache: LRUCache<string, J>;
|
|
42
|
+
/**
|
|
43
|
+
* Generates a cache key for template/pattern processing.
|
|
44
|
+
* Used by both Pattern and Template for consistent cache key generation.
|
|
45
|
+
*
|
|
46
|
+
* @param templateParts The template string parts
|
|
47
|
+
* @param itemsKey String representing the captures/parameters (comma-separated)
|
|
48
|
+
* @param contextStatements Context declarations
|
|
49
|
+
* @param dependencies NPM dependencies
|
|
50
|
+
* @returns A cache key string
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateCacheKey(templateParts: string[] | TemplateStringsArray, itemsKey: string, contextStatements: string[], dependencies: Record<string, string>): string;
|
|
37
53
|
/**
|
|
38
54
|
* Marker that stores capture metadata on pattern AST nodes.
|
|
39
55
|
* This avoids the need to parse capture names from identifiers during matching.
|
|
@@ -41,9 +57,10 @@ export declare const templateCache: TemplateCache;
|
|
|
41
57
|
export declare class CaptureMarker implements Marker {
|
|
42
58
|
readonly captureName: string;
|
|
43
59
|
readonly variadicOptions?: VariadicOptions | undefined;
|
|
60
|
+
readonly constraint?: ConstraintFunction<any> | undefined;
|
|
44
61
|
readonly kind = "org.openrewrite.javascript.CaptureMarker";
|
|
45
62
|
readonly id: string;
|
|
46
|
-
constructor(captureName: string, variadicOptions?: VariadicOptions | undefined);
|
|
63
|
+
constructor(captureName: string, variadicOptions?: VariadicOptions | undefined, constraint?: ConstraintFunction<any> | undefined);
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
49
66
|
* Utility class for managing placeholder naming and parsing.
|
|
@@ -59,20 +76,15 @@ export declare class PlaceholderUtils {
|
|
|
59
76
|
* @returns true if the node is a capture placeholder, false otherwise
|
|
60
77
|
*/
|
|
61
78
|
static isCapture(node: J): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Gets the capture name from a node with a CaptureMarker.
|
|
64
|
-
*
|
|
65
|
-
* @param node The node to extract capture name from
|
|
66
|
-
* @returns The capture name, or null if not a capture
|
|
67
|
-
*/
|
|
68
|
-
static getCaptureName(node: J): string | undefined;
|
|
69
79
|
/**
|
|
70
80
|
* Gets the CaptureMarker from a node, if present.
|
|
71
81
|
*
|
|
72
82
|
* @param node The node to check
|
|
73
83
|
* @returns The CaptureMarker or undefined
|
|
74
84
|
*/
|
|
75
|
-
static getCaptureMarker(node:
|
|
85
|
+
static getCaptureMarker(node: {
|
|
86
|
+
markers: Markers;
|
|
87
|
+
}): CaptureMarker | undefined;
|
|
76
88
|
/**
|
|
77
89
|
* Parses a capture placeholder to extract name and type constraint.
|
|
78
90
|
*
|
|
@@ -97,22 +109,27 @@ export declare class PlaceholderUtils {
|
|
|
97
109
|
* @param node The node to check
|
|
98
110
|
* @returns true if the node has a variadic CaptureMarker, false otherwise
|
|
99
111
|
*/
|
|
100
|
-
static isVariadicCapture(node:
|
|
112
|
+
static isVariadicCapture(node: {
|
|
113
|
+
markers: Markers;
|
|
114
|
+
}): boolean;
|
|
101
115
|
/**
|
|
102
116
|
* Gets the variadic options from a capture marker.
|
|
103
117
|
*
|
|
104
118
|
* @param node The node to extract variadic options from
|
|
105
119
|
* @returns The VariadicOptions, or undefined if not a variadic capture
|
|
106
120
|
*/
|
|
107
|
-
static getVariadicOptions(node:
|
|
121
|
+
static getVariadicOptions(node: {
|
|
122
|
+
markers: Markers;
|
|
123
|
+
}): VariadicOptions | undefined;
|
|
108
124
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
125
|
+
* Extracts the relevant AST node from a wrapper function.
|
|
126
|
+
* Used by both pattern and template processors to intelligently extract
|
|
127
|
+
* code from `function __WRAPPER__() { code }` wrappers.
|
|
112
128
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @
|
|
129
|
+
* @param lastStatement The last statement from the compilation unit
|
|
130
|
+
* @param contextName Context name for error messages (e.g., 'Pattern', 'Template')
|
|
131
|
+
* @returns The extracted AST node
|
|
115
132
|
*/
|
|
116
|
-
static
|
|
133
|
+
static extractFromWrapper(lastStatement: J, contextName: string): J;
|
|
117
134
|
}
|
|
118
135
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAC,kBAAkB,EAAE,eAAe,EAAC,MAAM,SAAS,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,mBAAmB,eAAwB,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IAGV,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,KAAK,CAAmB;gBAEZ,OAAO,EAAE,MAAM;I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