@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
@@ -1,265 +0,0 @@
1
- import { Cursor, Tree } from '..';
2
- import { J } from '../java';
3
- /**
4
- * Capture specification for pattern matching.
5
- * Represents a placeholder in a template pattern that can capture a part of the AST.
6
- */
7
- export interface Capture {
8
- /**
9
- * The name of the capture, used to retrieve the captured node later.
10
- */
11
- name: string;
12
- }
13
- /**
14
- * Creates a capture specification for use in template patterns.
15
- *
16
- * @param name Optional name for the capture. If not provided, an auto-generated name is used.
17
- * @returns A Capture object
18
- *
19
- * @example
20
- * // Named inline captures
21
- * const pattern = pattern`${capture('left')} + ${capture('right')}`;
22
- *
23
- * // Unnamed captures
24
- * const {left, right} = {left: capture(), right: capture()};
25
- * const pattern = pattern`${left} + ${right}`;
26
- *
27
- * // Repeated patterns using the same capture
28
- * const expr = capture('expr');
29
- * const redundantOr = pattern`${expr} || ${expr}`;
30
- */
31
- export declare function capture(name?: string): Capture;
32
- export declare namespace capture {
33
- var nextUnnamedId: number;
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
- }
63
- /**
64
- * Represents a pattern that can be matched against AST nodes.
65
- */
66
- export declare class Pattern {
67
- readonly templateParts: TemplateStringsArray;
68
- readonly captures: Capture[];
69
- private _options;
70
- /**
71
- * Gets the configuration options for this pattern.
72
- * @readonly
73
- */
74
- get options(): Readonly<PatternOptions>;
75
- /**
76
- * Creates a new pattern from template parts and captures.
77
- *
78
- * @param templateParts The string parts of the template
79
- * @param captures The captures between the string parts
80
- */
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;
96
- /**
97
- * Creates a matcher for this pattern against a specific AST node.
98
- *
99
- * @param ast The AST node to match against
100
- * @returns A Matcher object
101
- */
102
- match(ast: J): Promise<MatchResult | undefined>;
103
- }
104
- export declare class MatchResult implements Pick<Map<string, J>, "get"> {
105
- private readonly bindings;
106
- constructor(bindings?: Map<string, J>);
107
- get(capture: Capture | string): J | undefined;
108
- }
109
- /**
110
- * Tagged template function for creating patterns.
111
- *
112
- * @param strings The string parts of the template
113
- * @param captures The captures between the string parts
114
- * @returns A Pattern object
115
- *
116
- * @example
117
- * // Using the same capture multiple times for repeated patterns
118
- * const expr = capture('expr');
119
- * const redundantOr = pattern`${expr} || ${expr}`;
120
- */
121
- export declare function pattern(strings: TemplateStringsArray, ...captures: (Capture | string)[]): Pattern;
122
- /**
123
- * Valid parameter types for template literals.
124
- * - Capture: For pattern matching and reuse
125
- * - Tree: AST nodes to be inserted directly
126
- * - Primitives: Values to be converted to literals
127
- */
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
- }
145
- /**
146
- * Template for creating AST nodes.
147
- *
148
- * This class provides the public API for template generation.
149
- * The actual templating logic is handled by the internal TemplateEngine.
150
- *
151
- * @example
152
- * // Generate a literal AST node
153
- * const result = template`2`.apply(cursor, coordinates);
154
- *
155
- * @example
156
- * // Generate an AST node with a parameter
157
- * const result = template`${capture()}`.apply(cursor, coordinates);
158
- */
159
- export declare class Template {
160
- private readonly templateParts;
161
- private readonly parameters;
162
- private options;
163
- /**
164
- * Creates a new template.
165
- *
166
- * @param templateParts The string parts of the template
167
- * @param parameters The parameters between the string parts
168
- */
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;
184
- /**
185
- * Applies this template and returns the resulting tree.
186
- *
187
- * @param cursor The cursor pointing to the current location in the AST
188
- * @param tree Input tree
189
- * @param values values for parameters in template
190
- * @returns A Promise resolving to the generated AST node
191
- */
192
- apply(cursor: Cursor, tree: J, values?: Pick<Map<string, J>, 'get'>): Promise<J | undefined>;
193
- }
194
- export declare function template(strings: TemplateStringsArray, ...parameters: TemplateParameter[]): Template;
195
- /**
196
- * Parameter specification for template generation.
197
- * Represents a placeholder in a template that will be replaced with a parameter value.
198
- */
199
- interface Parameter {
200
- /**
201
- * The value to substitute into the template.
202
- */
203
- value: any;
204
- }
205
- /**
206
- * Represents a replacement rule that can match a pattern and apply a template.
207
- */
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
- */
218
- tryOn(cursor: Cursor, node: J): Promise<J | undefined>;
219
- }
220
- /**
221
- * Configuration for a replacement rule.
222
- */
223
- export interface RewriteConfig {
224
- before: Pattern | Pattern[];
225
- after: Template;
226
- }
227
- /**
228
- * Creates a replacement rule using a capture context and configuration.
229
- *
230
- * @param builderFn Function that takes a capture context and returns before/after configuration
231
- * @returns A replacement rule that can be applied to AST nodes
232
- *
233
- * @example
234
- * // Single pattern
235
- * const swapOperands = rewrite(() => ({
236
- * before: pattern`${"left"} + ${"right"}`,
237
- * after: template`${"right"} + ${"left"}`
238
- * }));
239
- *
240
- * @example
241
- * // Multiple patterns
242
- * const normalizeComparisons = rewrite(() => ({
243
- * before: [
244
- * pattern`${"left"} == ${"right"}`,
245
- * pattern`${"left"} === ${"right"}`
246
- * ],
247
- * after: template`${"left"} === ${"right"}`
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
- * }
262
- */
263
- export declare function rewrite(builderFn: () => RewriteConfig): RewriteRule;
264
- export {};
265
- //# sourceMappingURL=templating.d.ts.map
@@ -1 +0,0 @@
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,EAAa,CAAC,EAAC,MAAM,SAAS,CAAC;AA2MtC;;;GAGG;AACH,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CAChB;AASD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,IAAI,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