@openrewrite/rewrite 8.67.0-20251105-083346 → 8.67.0-20251105-102503
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/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +7 -10
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +5 -5
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +38 -50
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +28 -7
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +20 -1
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/rewrite.d.ts.map +1 -1
- package/dist/javascript/templating/rewrite.js +24 -4
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +30 -1
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/javascript/comparator.ts +8 -10
- package/src/javascript/templating/comparator.ts +44 -34
- package/src/javascript/templating/pattern.ts +27 -3
- package/src/javascript/templating/placeholder-replacement.ts +22 -1
- package/src/javascript/templating/rewrite.ts +25 -5
- package/src/javascript/templating/types.ts +31 -1
|
@@ -331,6 +331,36 @@ export interface RewriteRule {
|
|
|
331
331
|
* ```
|
|
332
332
|
*/
|
|
333
333
|
andThen(next: RewriteRule): RewriteRule;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Creates a composite rule that tries this rule first, and if it doesn't match, tries an alternative rule.
|
|
337
|
+
*
|
|
338
|
+
* The resulting rule:
|
|
339
|
+
* 1. First applies this rule to the input node
|
|
340
|
+
* 2. If this rule matches and transforms the node, returns the result
|
|
341
|
+
* 3. If this rule returns undefined (no match), tries the alternative rule on the original node
|
|
342
|
+
*
|
|
343
|
+
* @param alternative The rule to try if this rule doesn't match
|
|
344
|
+
* @returns A new RewriteRule that tries both rules with fallback behavior
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* // Try specific pattern first, fall back to general pattern
|
|
349
|
+
* const specific = rewrite(() => ({
|
|
350
|
+
* before: pattern`foo(${capture('x')}, 0)`,
|
|
351
|
+
* after: template`bar(${capture('x')})`
|
|
352
|
+
* }));
|
|
353
|
+
*
|
|
354
|
+
* const general = rewrite(() => ({
|
|
355
|
+
* before: pattern`foo(${capture('x')}, ${capture('y')})`,
|
|
356
|
+
* after: template`baz(${capture('x')}, ${capture('y')})`
|
|
357
|
+
* }));
|
|
358
|
+
*
|
|
359
|
+
* const combined = specific.orElse(general);
|
|
360
|
+
* // Will try specific pattern first, if no match, try general pattern
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
orElse(alternative: RewriteRule): RewriteRule;
|
|
334
364
|
}
|
|
335
365
|
|
|
336
366
|
/**
|
|
@@ -338,5 +368,5 @@ export interface RewriteRule {
|
|
|
338
368
|
*/
|
|
339
369
|
export interface RewriteConfig {
|
|
340
370
|
before: Pattern | Pattern[],
|
|
341
|
-
after: Template | ((match: MatchResult) =>
|
|
371
|
+
after: Template | ((match: MatchResult) => Template)
|
|
342
372
|
}
|