@openrewrite/rewrite 8.63.2 → 8.63.4
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/rpc.d.ts +2 -2
- package/dist/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +10 -4
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/type.d.ts +1 -1
- package/dist/java/type.d.ts.map +1 -1
- package/dist/java/type.js +3 -3
- package/dist/java/type.js.map +1 -1
- package/dist/javascript/assertions.d.ts +1 -1
- package/dist/javascript/assertions.d.ts.map +1 -1
- package/dist/javascript/assertions.js +35 -65
- package/dist/javascript/assertions.js.map +1 -1
- package/dist/javascript/comparator.d.ts +2 -2
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/dependency-workspace.d.ts +44 -0
- package/dist/javascript/dependency-workspace.d.ts.map +1 -0
- package/dist/javascript/dependency-workspace.js +335 -0
- package/dist/javascript/dependency-workspace.js.map +1 -0
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +5 -2
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/preconditions.js +2 -2
- package/dist/javascript/preconditions.js.map +1 -1
- package/dist/javascript/templating.d.ts +110 -5
- package/dist/javascript/templating.d.ts.map +1 -1
- package/dist/javascript/templating.js +412 -38
- package/dist/javascript/templating.js.map +1 -1
- package/dist/javascript/type-mapping.js +2 -2
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/rpc/queue.d.ts +1 -0
- package/dist/rpc/queue.d.ts.map +1 -1
- package/dist/rpc/queue.js +11 -1
- package/dist/rpc/queue.js.map +1 -1
- package/dist/rpc/request/install-recipes.d.ts.map +1 -1
- package/dist/rpc/request/install-recipes.js +116 -21
- package/dist/rpc/request/install-recipes.js.map +1 -1
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +5 -0
- package/dist/rpc/server.js.map +1 -1
- package/dist/test/rewrite-test.d.ts +1 -1
- package/dist/test/rewrite-test.d.ts.map +1 -1
- package/dist/test/rewrite-test.js +27 -5
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/java/rpc.ts +4 -4
- package/src/java/type.ts +3 -3
- package/src/javascript/assertions.ts +14 -21
- package/src/javascript/comparator.ts +2 -2
- package/src/javascript/dependency-workspace.ts +317 -0
- package/src/javascript/parser.ts +6 -3
- package/src/javascript/preconditions.ts +2 -2
- package/src/javascript/templating.ts +535 -44
- package/src/javascript/type-mapping.ts +2 -2
- package/src/rpc/queue.ts +11 -1
- package/src/rpc/request/install-recipes.ts +127 -24
- package/src/rpc/server.ts +5 -0
- package/src/test/rewrite-test.ts +11 -3
|
@@ -27,13 +27,13 @@ function hasSourcePath(filePattern) {
|
|
|
27
27
|
}) : new search_2.IsSourceFile(filePattern);
|
|
28
28
|
}
|
|
29
29
|
function usesMethod(methodPattern, matchOverrides = false) {
|
|
30
|
-
return rpc_1.RewriteRpc.get() ? rpc_1.RewriteRpc.get().prepareRecipe("org.openrewrite.java.search.
|
|
30
|
+
return rpc_1.RewriteRpc.get() ? rpc_1.RewriteRpc.get().prepareRecipe("org.openrewrite.java.search.HasMethod", {
|
|
31
31
|
methodPattern,
|
|
32
32
|
matchOverrides
|
|
33
33
|
}) : new search_1.UsesMethod(methodPattern);
|
|
34
34
|
}
|
|
35
35
|
function usesType(fullyQualifiedType) {
|
|
36
|
-
return rpc_1.RewriteRpc.get() ? rpc_1.RewriteRpc.get().prepareRecipe("org.openrewrite.java.search.
|
|
36
|
+
return rpc_1.RewriteRpc.get() ? rpc_1.RewriteRpc.get().prepareRecipe("org.openrewrite.java.search.HasType", {
|
|
37
37
|
fullyQualifiedType,
|
|
38
38
|
checkAssignability: false
|
|
39
39
|
}) : new search_1.UsesType(fullyQualifiedType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preconditions.js","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":";;AAsBA,sCAIC;AAED,gCAKC;AAED,4BAKC;AAxCD;;;;;;;;;;;;;;GAcG;AACH,gCAAkC;AAClC,qCAA8C;AAG9C,sCAAuC;AAGvC,SAAgB,aAAa,CAAC,WAAmB;IAC7C,OAAO,gBAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAU,CAAC,GAAG,EAAG,CAAC,aAAa,CAAC,iCAAiC,EAAE;QACzF,WAAW;KACd,CAAC,CAAC,CAAC,CAAC,IAAI,qBAAY,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,UAAU,CAAC,aAAqB,EAAE,iBAA0B,KAAK;IAC7E,OAAO,gBAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAU,CAAC,GAAG,EAAG,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"preconditions.js","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":";;AAsBA,sCAIC;AAED,gCAKC;AAED,4BAKC;AAxCD;;;;;;;;;;;;;;GAcG;AACH,gCAAkC;AAClC,qCAA8C;AAG9C,sCAAuC;AAGvC,SAAgB,aAAa,CAAC,WAAmB;IAC7C,OAAO,gBAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAU,CAAC,GAAG,EAAG,CAAC,aAAa,CAAC,iCAAiC,EAAE;QACzF,WAAW;KACd,CAAC,CAAC,CAAC,CAAC,IAAI,qBAAY,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,UAAU,CAAC,aAAqB,EAAE,iBAA0B,KAAK;IAC7E,OAAO,gBAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAU,CAAC,GAAG,EAAG,CAAC,aAAa,CAAC,uCAAuC,EAAE;QAC/F,aAAa;QACb,cAAc;KACjB,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAU,CAAC,aAAa,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,QAAQ,CAAC,kBAA0B;IAC/C,OAAO,gBAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAU,CAAC,GAAG,EAAG,CAAC,aAAa,CAAC,qCAAqC,EAAE;QAC7F,kBAAkB;QAClB,kBAAkB,EAAE,KAAK;KAC5B,CAAC,CAAC,CAAC,CAAC,IAAI,iBAAQ,CAAC,kBAAkB,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -13,27 +13,65 @@ export interface Capture {
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a capture specification for use in template patterns.
|
|
15
15
|
*
|
|
16
|
+
* @param name Optional name for the capture. If not provided, an auto-generated name is used.
|
|
16
17
|
* @returns A Capture object
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
|
-
* //
|
|
20
|
+
* // Named inline captures
|
|
21
|
+
* const pattern = pattern`${capture('left')} + ${capture('right')}`;
|
|
22
|
+
*
|
|
23
|
+
* // Unnamed captures
|
|
20
24
|
* const {left, right} = {left: capture(), right: capture()};
|
|
21
25
|
* const pattern = pattern`${left} + ${right}`;
|
|
22
26
|
*
|
|
23
27
|
* // Repeated patterns using the same capture
|
|
24
|
-
* const expr = capture();
|
|
28
|
+
* const expr = capture('expr');
|
|
25
29
|
* const redundantOr = pattern`${expr} || ${expr}`;
|
|
26
30
|
*/
|
|
27
|
-
export declare function capture(): Capture;
|
|
31
|
+
export declare function capture(name?: string): Capture;
|
|
28
32
|
export declare namespace capture {
|
|
29
33
|
var nextUnnamedId: number;
|
|
30
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Concise alias for `capture`. Works well for inline captures in patterns and templates.
|
|
37
|
+
*
|
|
38
|
+
* @param name Optional name for the capture. If not provided, an auto-generated name is used.
|
|
39
|
+
* @returns A Capture object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Inline captures with _ alias
|
|
43
|
+
* pattern`isDate(${_('dateArg')})`
|
|
44
|
+
* template`${_('dateArg')} instanceof Date`
|
|
45
|
+
*/
|
|
46
|
+
export declare const _: typeof capture;
|
|
47
|
+
/**
|
|
48
|
+
* Configuration options for patterns.
|
|
49
|
+
*/
|
|
50
|
+
export interface PatternOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Import statements to provide type attribution context.
|
|
53
|
+
* These are prepended to the pattern when parsing to ensure proper type information.
|
|
54
|
+
*/
|
|
55
|
+
imports?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* NPM dependencies required for import resolution and type attribution.
|
|
58
|
+
* Maps package names to version specifiers (e.g., { 'util': '^1.0.0' }).
|
|
59
|
+
* The template engine will create a package.json with these dependencies.
|
|
60
|
+
*/
|
|
61
|
+
dependencies?: Record<string, string>;
|
|
62
|
+
}
|
|
31
63
|
/**
|
|
32
64
|
* Represents a pattern that can be matched against AST nodes.
|
|
33
65
|
*/
|
|
34
66
|
export declare class Pattern {
|
|
35
67
|
readonly templateParts: TemplateStringsArray;
|
|
36
68
|
readonly captures: Capture[];
|
|
69
|
+
private _options;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the configuration options for this pattern.
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
get options(): Readonly<PatternOptions>;
|
|
37
75
|
/**
|
|
38
76
|
* Creates a new pattern from template parts and captures.
|
|
39
77
|
*
|
|
@@ -41,6 +79,20 @@ export declare class Pattern {
|
|
|
41
79
|
* @param captures The captures between the string parts
|
|
42
80
|
*/
|
|
43
81
|
constructor(templateParts: TemplateStringsArray, captures: Capture[]);
|
|
82
|
+
/**
|
|
83
|
+
* Configures this pattern with additional options.
|
|
84
|
+
*
|
|
85
|
+
* @param options Configuration options
|
|
86
|
+
* @returns This pattern for method chaining
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* pattern`isDate(${capture('date')})`
|
|
90
|
+
* .configure({
|
|
91
|
+
* imports: ['import { isDate } from "util"'],
|
|
92
|
+
* dependencies: { 'util': '^1.0.0' }
|
|
93
|
+
* })
|
|
94
|
+
*/
|
|
95
|
+
configure(options: PatternOptions): Pattern;
|
|
44
96
|
/**
|
|
45
97
|
* Creates a matcher for this pattern against a specific AST node.
|
|
46
98
|
*
|
|
@@ -74,6 +126,22 @@ export declare function pattern(strings: TemplateStringsArray, ...captures: (Cap
|
|
|
74
126
|
* - Primitives: Values to be converted to literals
|
|
75
127
|
*/
|
|
76
128
|
export type TemplateParameter = Capture | Tree | string | number | boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Configuration options for templates.
|
|
131
|
+
*/
|
|
132
|
+
export interface TemplateOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Import statements to provide type attribution context.
|
|
135
|
+
* These are prepended to the template when parsing to ensure proper type information.
|
|
136
|
+
*/
|
|
137
|
+
imports?: string[];
|
|
138
|
+
/**
|
|
139
|
+
* NPM dependencies required for import resolution and type attribution.
|
|
140
|
+
* Maps package names to version specifiers (e.g., { 'util': '^1.0.0' }).
|
|
141
|
+
* The template engine will create a package.json with these dependencies.
|
|
142
|
+
*/
|
|
143
|
+
dependencies?: Record<string, string>;
|
|
144
|
+
}
|
|
77
145
|
/**
|
|
78
146
|
* Template for creating AST nodes.
|
|
79
147
|
*
|
|
@@ -91,6 +159,7 @@ export type TemplateParameter = Capture | Tree | string | number | boolean;
|
|
|
91
159
|
export declare class Template {
|
|
92
160
|
private readonly templateParts;
|
|
93
161
|
private readonly parameters;
|
|
162
|
+
private options;
|
|
94
163
|
/**
|
|
95
164
|
* Creates a new template.
|
|
96
165
|
*
|
|
@@ -98,6 +167,20 @@ export declare class Template {
|
|
|
98
167
|
* @param parameters The parameters between the string parts
|
|
99
168
|
*/
|
|
100
169
|
constructor(templateParts: TemplateStringsArray, parameters: Parameter[]);
|
|
170
|
+
/**
|
|
171
|
+
* Configures this template with additional options.
|
|
172
|
+
*
|
|
173
|
+
* @param options Configuration options
|
|
174
|
+
* @returns This template for method chaining
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* template`isDate(${capture('date')})`
|
|
178
|
+
* .configure({
|
|
179
|
+
* imports: ['import { isDate } from "util"'],
|
|
180
|
+
* dependencies: { 'util': '^1.0.0' }
|
|
181
|
+
* })
|
|
182
|
+
*/
|
|
183
|
+
configure(options: TemplateOptions): Template;
|
|
101
184
|
/**
|
|
102
185
|
* Applies this template and returns the resulting tree.
|
|
103
186
|
*
|
|
@@ -123,6 +206,15 @@ interface Parameter {
|
|
|
123
206
|
* Represents a replacement rule that can match a pattern and apply a template.
|
|
124
207
|
*/
|
|
125
208
|
export interface RewriteRule {
|
|
209
|
+
/**
|
|
210
|
+
* Attempts to apply this rewrite rule to the given AST node.
|
|
211
|
+
*
|
|
212
|
+
* @param cursor The cursor context at the current position in the AST
|
|
213
|
+
* @param node The AST node to try matching and transforming
|
|
214
|
+
* @returns The transformed node if a pattern matched, or `undefined` if no pattern matched.
|
|
215
|
+
* When using in a visitor, always use the `|| node` pattern to return the original
|
|
216
|
+
* node when there's no match: `return await rule.tryOn(this.cursor, node) || node;`
|
|
217
|
+
*/
|
|
126
218
|
tryOn(cursor: Cursor, node: J): Promise<J | undefined>;
|
|
127
219
|
}
|
|
128
220
|
/**
|
|
@@ -140,20 +232,33 @@ export interface RewriteConfig {
|
|
|
140
232
|
*
|
|
141
233
|
* @example
|
|
142
234
|
* // Single pattern
|
|
143
|
-
* const swapOperands =
|
|
235
|
+
* const swapOperands = rewrite(() => ({
|
|
144
236
|
* before: pattern`${"left"} + ${"right"}`,
|
|
145
237
|
* after: template`${"right"} + ${"left"}`
|
|
146
238
|
* }));
|
|
147
239
|
*
|
|
148
240
|
* @example
|
|
149
241
|
* // Multiple patterns
|
|
150
|
-
* const normalizeComparisons =
|
|
242
|
+
* const normalizeComparisons = rewrite(() => ({
|
|
151
243
|
* before: [
|
|
152
244
|
* pattern`${"left"} == ${"right"}`,
|
|
153
245
|
* pattern`${"left"} === ${"right"}`
|
|
154
246
|
* ],
|
|
155
247
|
* after: template`${"left"} === ${"right"}`
|
|
156
248
|
* }));
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Using in a visitor - IMPORTANT: use `|| node` to handle undefined when no match
|
|
252
|
+
* class MyVisitor extends JavaScriptVisitor<any> {
|
|
253
|
+
* override async visitBinary(binary: J.Binary, p: any): Promise<J | undefined> {
|
|
254
|
+
* const rule = rewrite(() => ({
|
|
255
|
+
* before: pattern`${capture('a')} + ${capture('b')}`,
|
|
256
|
+
* after: template`${capture('b')} + ${capture('a')}`
|
|
257
|
+
* }));
|
|
258
|
+
* // tryOn() returns undefined if no pattern matches, so always use || node
|
|
259
|
+
* return await rule.tryOn(this.cursor, binary) || binary;
|
|
260
|
+
* }
|
|
261
|
+
* }
|
|
157
262
|
*/
|
|
158
263
|
export declare function rewrite(builderFn: () => RewriteConfig): RewriteRule;
|
|
159
264
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/javascript/templating.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,MAAM,EAAU,IAAI,EAAC,MAAM,IAAI,CAAC;AACxC,OAAO,EAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/javascript/templating.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,MAAM,EAAU,IAAI,EAAC,MAAM,IAAI,CAAC;AACxC,OAAO,EAAC,CAAC,EAAO,MAAM,SAAS,CAAC;AAqGhC;;;GAGG;AACH,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CAChB;AASD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAK9C;yBALe,OAAO;;;AAUvB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,CAAC,gBAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,E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