@openrewrite/rewrite 8.66.0-SNAPSHOT → 8.66.1
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 +91 -5
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +679 -3091
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format.d.ts.map +1 -1
- package/dist/javascript/format.js +4 -3
- package/dist/javascript/format.js.map +1 -1
- package/dist/javascript/index.d.ts +1 -1
- package/dist/javascript/index.d.ts.map +1 -1
- package/dist/javascript/index.js +1 -1
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +22 -21
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.d.ts +2 -2
- package/dist/javascript/print.d.ts.map +1 -1
- package/dist/javascript/print.js +4 -4
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/templating/capture.d.ts +226 -0
- package/dist/javascript/templating/capture.d.ts.map +1 -0
- package/dist/javascript/templating/capture.js +371 -0
- package/dist/javascript/templating/capture.js.map +1 -0
- package/dist/javascript/templating/comparator.d.ts +61 -0
- package/dist/javascript/templating/comparator.d.ts.map +1 -0
- package/dist/javascript/templating/comparator.js +393 -0
- package/dist/javascript/templating/comparator.js.map +1 -0
- package/dist/javascript/templating/engine.d.ts +75 -0
- package/dist/javascript/templating/engine.d.ts.map +1 -0
- package/dist/javascript/templating/engine.js +228 -0
- package/dist/javascript/templating/engine.js.map +1 -0
- package/dist/javascript/templating/index.d.ts +6 -0
- package/dist/javascript/templating/index.d.ts.map +1 -0
- package/dist/javascript/templating/index.js +42 -0
- package/dist/javascript/templating/index.js.map +1 -0
- package/dist/javascript/templating/pattern.d.ts +171 -0
- package/dist/javascript/templating/pattern.d.ts.map +1 -0
- package/dist/javascript/templating/pattern.js +681 -0
- package/dist/javascript/templating/pattern.js.map +1 -0
- package/dist/javascript/templating/placeholder-replacement.d.ts +58 -0
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
- package/dist/javascript/templating/placeholder-replacement.js +365 -0
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
- package/dist/javascript/templating/rewrite.d.ts +39 -0
- package/dist/javascript/templating/rewrite.d.ts.map +1 -0
- package/dist/javascript/templating/rewrite.js +81 -0
- package/dist/javascript/templating/rewrite.js.map +1 -0
- package/dist/javascript/templating/template.d.ts +204 -0
- package/dist/javascript/templating/template.d.ts.map +1 -0
- package/dist/javascript/templating/template.js +293 -0
- package/dist/javascript/templating/template.js.map +1 -0
- package/dist/javascript/templating/types.d.ts +263 -0
- package/dist/javascript/templating/types.d.ts.map +1 -0
- package/dist/javascript/templating/types.js +3 -0
- package/dist/javascript/templating/types.js.map +1 -0
- package/dist/javascript/templating/utils.d.ts +118 -0
- package/dist/javascript/templating/utils.d.ts.map +1 -0
- package/dist/javascript/templating/utils.js +253 -0
- package/dist/javascript/templating/utils.js.map +1 -0
- package/dist/test/rewrite-test.d.ts.map +1 -1
- package/dist/test/rewrite-test.js +65 -9
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +2 -2
- package/src/javascript/comparator.ts +721 -3607
- package/src/javascript/format.ts +3 -2
- package/src/javascript/index.ts +1 -1
- package/src/javascript/parser.ts +23 -22
- package/src/javascript/print.ts +6 -6
- package/src/javascript/templating/capture.ts +503 -0
- package/src/javascript/templating/comparator.ts +430 -0
- package/src/javascript/templating/engine.ts +252 -0
- package/src/javascript/templating/index.ts +60 -0
- package/src/javascript/templating/pattern.ts +727 -0
- package/src/javascript/templating/placeholder-replacement.ts +372 -0
- package/src/javascript/templating/rewrite.ts +95 -0
- package/src/javascript/templating/template.ts +326 -0
- package/src/javascript/templating/types.ts +300 -0
- package/src/javascript/templating/utils.ts +284 -0
- package/src/test/rewrite-test.ts +65 -1
- package/dist/javascript/templating.d.ts +0 -265
- package/dist/javascript/templating.d.ts.map +0 -1
- package/dist/javascript/templating.js +0 -1069
- package/dist/javascript/templating.js.map +0 -1
- package/src/javascript/templating.ts +0 -1277
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Cursor, Tree } from '../..';
|
|
2
|
+
import { J } from '../../java';
|
|
3
|
+
/**
|
|
4
|
+
* Options for variadic captures that match zero or more nodes in a sequence.
|
|
5
|
+
*/
|
|
6
|
+
export interface VariadicOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Minimum number of nodes that must be matched (default: 0).
|
|
9
|
+
*/
|
|
10
|
+
min?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum number of nodes that can be matched (default: unlimited).
|
|
13
|
+
*/
|
|
14
|
+
max?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for the capture function.
|
|
18
|
+
*
|
|
19
|
+
* The constraint function receives different parameter types depending on whether
|
|
20
|
+
* the capture is variadic:
|
|
21
|
+
* - For regular captures: constraint receives a single node of type T
|
|
22
|
+
* - For variadic captures: constraint receives an array of nodes of type T[]
|
|
23
|
+
*/
|
|
24
|
+
export interface CaptureOptions<T = any> {
|
|
25
|
+
name?: string;
|
|
26
|
+
variadic?: boolean | VariadicOptions;
|
|
27
|
+
constraint?: (node: T) => boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Capture specification for pattern matching.
|
|
31
|
+
* Represents a placeholder in a template pattern that can capture a part of the AST.
|
|
32
|
+
*
|
|
33
|
+
* @template T The expected type of the captured AST node (for TypeScript autocomplete)
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* **Important: Type Parameter is for IDE Support Only**
|
|
37
|
+
*
|
|
38
|
+
* The generic type parameter `<T>` provides IDE autocomplete and type checking in your code,
|
|
39
|
+
* but does NOT enforce any runtime constraints on what the capture will match.
|
|
40
|
+
*
|
|
41
|
+
* **Pattern Matching Behavior:**
|
|
42
|
+
* - A bare `pattern`${capture('x')}`` will structurally match ANY expression
|
|
43
|
+
* - Pattern structure determines matching: `pattern`foo(${capture('x')})`` only matches `foo()` calls
|
|
44
|
+
* - Use structural patterns to narrow matching scope before applying semantic validation
|
|
45
|
+
*
|
|
46
|
+
* **Variadic Captures:**
|
|
47
|
+
* Use `{ variadic: true }` to match zero or more nodes in a sequence:
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const args = capture('args', { variadic: true });
|
|
50
|
+
* pattern`foo(${args})` // Matches: foo(), foo(a), foo(a, b, c)
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface Capture<T = any> {
|
|
54
|
+
/**
|
|
55
|
+
* Gets the string name of this capture.
|
|
56
|
+
*/
|
|
57
|
+
getName(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if this is a variadic capture (matching zero or more nodes).
|
|
60
|
+
*/
|
|
61
|
+
isVariadic(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the variadic options if this is a variadic capture, undefined otherwise.
|
|
64
|
+
*/
|
|
65
|
+
getVariadicOptions(): VariadicOptions | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the constraint function if this capture has one.
|
|
68
|
+
* For regular captures (T = Expression), constraint receives a single node.
|
|
69
|
+
* For variadic captures (T = Expression[]), constraint receives an array of nodes.
|
|
70
|
+
*/
|
|
71
|
+
getConstraint?(): ((node: T) => boolean) | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Non-capturing pattern match specification.
|
|
75
|
+
* Represents a placeholder in a pattern that matches AST nodes without binding them to a name.
|
|
76
|
+
*
|
|
77
|
+
* Use `any()` when you need to match structure without caring about the specific values.
|
|
78
|
+
* The key difference from `Capture` is that `Any` cannot be used in templates - the TypeScript
|
|
79
|
+
* type system prevents this at compile time.
|
|
80
|
+
*
|
|
81
|
+
* @template T The expected type of the matched AST node (for TypeScript autocomplete and constraints)
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* **Why Any<T> is Separate from Capture<T>:**
|
|
85
|
+
*
|
|
86
|
+
* Using a separate type provides compile-time safety:
|
|
87
|
+
* - `pattern`foo(${any()})`` - ✅ OK in patterns
|
|
88
|
+
* - `template`bar(${any()})`` - ❌ TypeScript error (Any<T> not assignable to template parameters)
|
|
89
|
+
*
|
|
90
|
+
* This prevents logical errors where you try to use a non-capturing match in a template.
|
|
91
|
+
*
|
|
92
|
+
* **Semantic Parallel with TypeScript's `any`:**
|
|
93
|
+
*
|
|
94
|
+
* Just as TypeScript's `any` type means "be permissive about types here",
|
|
95
|
+
* pattern matching's `any()` means "be permissive about values here":
|
|
96
|
+
* - TypeScript `any`: Accept any type, don't check it
|
|
97
|
+
* - Pattern `any()`: Match any value, don't bind it
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // Match without capturing
|
|
101
|
+
* const pat = pattern`foo(${any()})`
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // Variadic any - match zero or more without capturing
|
|
105
|
+
* const rest = any({ variadic: true });
|
|
106
|
+
* const pat = pattern`bar(${capture('first')}, ${rest})`
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // With constraints - validate but don't capture
|
|
110
|
+
* const numericArg = any<J.Literal>({
|
|
111
|
+
* constraint: (node) => typeof node.value === 'number'
|
|
112
|
+
* });
|
|
113
|
+
* const pat = pattern`process(${numericArg})`
|
|
114
|
+
*/
|
|
115
|
+
export interface Any<T = any> {
|
|
116
|
+
/**
|
|
117
|
+
* Gets the internal identifier for this any pattern.
|
|
118
|
+
*/
|
|
119
|
+
getName(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Returns true if this is a variadic any (matching zero or more nodes).
|
|
122
|
+
*/
|
|
123
|
+
isVariadic(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the variadic options if this is a variadic any, undefined otherwise.
|
|
126
|
+
*/
|
|
127
|
+
getVariadicOptions(): VariadicOptions | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the constraint function if this any pattern has one.
|
|
130
|
+
* For regular any (T = Expression), constraint receives a single node.
|
|
131
|
+
* For variadic any (T = Expression[]), constraint receives an array of nodes.
|
|
132
|
+
*/
|
|
133
|
+
getConstraint?(): ((node: T) => boolean) | undefined;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Template parameter specification for template-only parameter substitution.
|
|
137
|
+
* Unlike Capture, TemplateParam does not support property access and is simpler.
|
|
138
|
+
*
|
|
139
|
+
* @template T The expected type of the parameter value (for TypeScript autocomplete only)
|
|
140
|
+
*/
|
|
141
|
+
export interface TemplateParam<T = any> {
|
|
142
|
+
/**
|
|
143
|
+
* The name of the parameter, used to look up the value in the values map.
|
|
144
|
+
*/
|
|
145
|
+
readonly name: string;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the string name of this parameter.
|
|
148
|
+
*/
|
|
149
|
+
getName(): string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Configuration options for patterns.
|
|
153
|
+
*/
|
|
154
|
+
export interface PatternOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Declarations to provide type attribution context for the pattern.
|
|
157
|
+
* These can include import statements, type declarations, function declarations, or any
|
|
158
|
+
* other declarations needed for proper type information. They are prepended to the pattern
|
|
159
|
+
* when parsing to ensure proper type attribution.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* pattern`forwardRef(${capture('comp')})`
|
|
164
|
+
* .configure({
|
|
165
|
+
* context: [
|
|
166
|
+
* `import { forwardRef } from 'react'`,
|
|
167
|
+
* `type MyType = { value: number }`
|
|
168
|
+
* ]
|
|
169
|
+
* })
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
context?: string[];
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated Use `context` instead. This alias will be removed in a future version.
|
|
175
|
+
*
|
|
176
|
+
* Import statements to provide type attribution context.
|
|
177
|
+
* These are prepended to the pattern when parsing to ensure proper type information.
|
|
178
|
+
*/
|
|
179
|
+
imports?: string[];
|
|
180
|
+
/**
|
|
181
|
+
* NPM dependencies required for import resolution and type attribution.
|
|
182
|
+
* Maps package names to version specifiers (e.g., { 'util': '^1.0.0' }).
|
|
183
|
+
* The template engine will create a package.json with these dependencies.
|
|
184
|
+
*/
|
|
185
|
+
dependencies?: Record<string, string>;
|
|
186
|
+
/**
|
|
187
|
+
* When true, allows patterns without type annotations to match code with type annotations.
|
|
188
|
+
* This enables more flexible pattern matching during development or when full type attribution
|
|
189
|
+
* is not needed. When false, enforces strict type matching where both pattern and target must
|
|
190
|
+
* have matching type annotations.
|
|
191
|
+
*
|
|
192
|
+
* @default true (lenient matching enabled for backward compatibility)
|
|
193
|
+
*/
|
|
194
|
+
lenientTypeMatching?: boolean;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Valid parameter types for template literals.
|
|
198
|
+
* - Capture: For pattern matching and reuse
|
|
199
|
+
* - CaptureValue: Result of property access or array operations on captures (e.g., capture.prop, capture[0], capture.slice(1))
|
|
200
|
+
* - Tree: AST nodes to be inserted directly
|
|
201
|
+
* - Tree[]: Arrays of AST nodes (from variadic capture operations like slice)
|
|
202
|
+
* - Primitives: Values to be converted to literals
|
|
203
|
+
*/
|
|
204
|
+
export type TemplateParameter = Capture | any | TemplateParam | Tree | Tree[] | string | number | boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Configuration options for templates.
|
|
207
|
+
*/
|
|
208
|
+
export interface TemplateOptions {
|
|
209
|
+
/**
|
|
210
|
+
* Declarations to provide type attribution context for the template.
|
|
211
|
+
* These can include import statements, type declarations, function declarations, or any
|
|
212
|
+
* other declarations needed for proper type information. They are prepended to the template
|
|
213
|
+
* when parsing to ensure proper type attribution.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* template`console.log(${capture('value')})`
|
|
218
|
+
* .configure({
|
|
219
|
+
* context: [
|
|
220
|
+
* `type MyType = { value: number }`,
|
|
221
|
+
* `const console = { log: (x: any) => void 0 }`
|
|
222
|
+
* ]
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
context?: string[];
|
|
227
|
+
/**
|
|
228
|
+
* @deprecated Use `context` instead. This alias will be removed in a future version.
|
|
229
|
+
*
|
|
230
|
+
* Import statements to provide type attribution context.
|
|
231
|
+
* These are prepended to the template when parsing to ensure proper type information.
|
|
232
|
+
*/
|
|
233
|
+
imports?: string[];
|
|
234
|
+
/**
|
|
235
|
+
* NPM dependencies required for import resolution and type attribution.
|
|
236
|
+
* Maps package names to version specifiers (e.g., { 'util': '^1.0.0' }).
|
|
237
|
+
* The template engine will create a package.json with these dependencies.
|
|
238
|
+
*/
|
|
239
|
+
dependencies?: Record<string, string>;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Represents a replacement rule that can match a pattern and apply a template.
|
|
243
|
+
*/
|
|
244
|
+
export interface RewriteRule {
|
|
245
|
+
/**
|
|
246
|
+
* Attempts to apply this rewrite rule to the given AST node.
|
|
247
|
+
*
|
|
248
|
+
* @param cursor The cursor context at the current position in the AST
|
|
249
|
+
* @param node The AST node to try matching and transforming
|
|
250
|
+
* @returns The transformed node if a pattern matched, or `undefined` if no pattern matched.
|
|
251
|
+
* When using in a visitor, always use the `|| node` pattern to return the original
|
|
252
|
+
* node when there's no match: `return await rule.tryOn(this.cursor, node) || node;`
|
|
253
|
+
*/
|
|
254
|
+
tryOn(cursor: Cursor, node: J): Promise<J | undefined>;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Configuration for a replacement rule.
|
|
258
|
+
*/
|
|
259
|
+
export interface RewriteConfig {
|
|
260
|
+
before: any;
|
|
261
|
+
after: any;
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/types.ts"],"names":[],"mappings":"AAe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
1
|
+
import { J } from '../../java';
|
|
2
|
+
import { JS } from '../index';
|
|
3
|
+
import { Marker } from '../../markers';
|
|
4
|
+
import { VariadicOptions, Capture, Any } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Internal storage value type for pattern match captures.
|
|
7
|
+
* - J: Scalar captures without wrapper (fallback)
|
|
8
|
+
* - J.RightPadded<J>: Scalar captures with wrapper (preserves trailing markers like semicolons)
|
|
9
|
+
* - J[]: Variadic captures without wrapper metadata
|
|
10
|
+
* - J.RightPadded<J>[]: Variadic captures with wrapper metadata (preserves markers like commas)
|
|
11
|
+
*/
|
|
12
|
+
export type CaptureStorageValue = J | J.RightPadded<J> | J[] | J.RightPadded<J>[];
|
|
13
|
+
/**
|
|
14
|
+
* Symbol to access wrappersMap without exposing it as public API
|
|
15
|
+
*/
|
|
16
|
+
export declare const WRAPPERS_MAP_SYMBOL: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Cache for compiled templates and patterns.
|
|
19
|
+
* Stores parsed ASTs to avoid expensive re-parsing and dependency resolution.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TemplateCache {
|
|
22
|
+
private cache;
|
|
23
|
+
/**
|
|
24
|
+
* Generates a cache key from template string, captures, and options.
|
|
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
|
+
*/
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|
|
36
|
+
export declare const templateCache: TemplateCache;
|
|
37
|
+
/**
|
|
38
|
+
* Marker that stores capture metadata on pattern AST nodes.
|
|
39
|
+
* This avoids the need to parse capture names from identifiers during matching.
|
|
40
|
+
*/
|
|
41
|
+
export declare class CaptureMarker implements Marker {
|
|
42
|
+
readonly captureName: string;
|
|
43
|
+
readonly variadicOptions?: VariadicOptions | undefined;
|
|
44
|
+
readonly kind = "org.openrewrite.javascript.CaptureMarker";
|
|
45
|
+
readonly id: string;
|
|
46
|
+
constructor(captureName: string, variadicOptions?: VariadicOptions | undefined);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Utility class for managing placeholder naming and parsing.
|
|
50
|
+
* Centralizes all logic related to capture placeholders.
|
|
51
|
+
*/
|
|
52
|
+
export declare class PlaceholderUtils {
|
|
53
|
+
static readonly CAPTURE_PREFIX = "__capt_";
|
|
54
|
+
static readonly PLACEHOLDER_PREFIX = "__PLACEHOLDER_";
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a node is a capture placeholder.
|
|
57
|
+
*
|
|
58
|
+
* @param node The node to check
|
|
59
|
+
* @returns true if the node is a capture placeholder, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
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
|
+
/**
|
|
70
|
+
* Gets the CaptureMarker from a node, if present.
|
|
71
|
+
*
|
|
72
|
+
* @param node The node to check
|
|
73
|
+
* @returns The CaptureMarker or undefined
|
|
74
|
+
*/
|
|
75
|
+
static getCaptureMarker(node: J): CaptureMarker | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Parses a capture placeholder to extract name and type constraint.
|
|
78
|
+
*
|
|
79
|
+
* @param identifier The identifier string to parse
|
|
80
|
+
* @returns Object with name and optional type constraint, or null if not a valid capture
|
|
81
|
+
*/
|
|
82
|
+
static parseCapture(identifier: string): {
|
|
83
|
+
name: string;
|
|
84
|
+
typeConstraint?: string;
|
|
85
|
+
} | null;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a capture placeholder string.
|
|
88
|
+
*
|
|
89
|
+
* @param name The capture name
|
|
90
|
+
* @param typeConstraint Optional type constraint
|
|
91
|
+
* @returns The formatted placeholder string
|
|
92
|
+
*/
|
|
93
|
+
static createCapture(name: string, typeConstraint?: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Checks if a capture marker indicates a variadic capture.
|
|
96
|
+
*
|
|
97
|
+
* @param node The node to check
|
|
98
|
+
* @returns true if the node has a variadic CaptureMarker, false otherwise
|
|
99
|
+
*/
|
|
100
|
+
static isVariadicCapture(node: J): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the variadic options from a capture marker.
|
|
103
|
+
*
|
|
104
|
+
* @param node The node to extract variadic options from
|
|
105
|
+
* @returns The VariadicOptions, or undefined if not a variadic capture
|
|
106
|
+
*/
|
|
107
|
+
static getVariadicOptions(node: J): VariadicOptions | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if a statement is an ExpressionStatement wrapping a capture identifier.
|
|
110
|
+
* When a capture placeholder appears in statement position, the parser wraps it as
|
|
111
|
+
* an ExpressionStatement. This method unwraps it to get the identifier.
|
|
112
|
+
*
|
|
113
|
+
* @param stmt The statement to check
|
|
114
|
+
* @returns The unwrapped capture identifier, or the original statement if not wrapped
|
|
115
|
+
*/
|
|
116
|
+
static unwrapStatementCapture(stmt: J): J;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAC;AAG5B,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,OAAO,EAAC,eAAe,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,SAAS,CAAC;AAEtD;;;;;;GA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AE,CAAC,GAAG,aAAa,GAAG,SAAS;IAS3D;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAuBzF;;;;;;OAMG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM;IAOnE;;;;;OAKG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO;IAS1C;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,GAAG,eAAe,GAAG,SAAS;IAS/D;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC;CAc5C"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PlaceholderUtils = exports.CaptureMarker = exports.templateCache = exports.TemplateCache = exports.WRAPPERS_MAP_SYMBOL = void 0;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright 2025 the original author or authors.
|
|
15
|
+
* <p>
|
|
16
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License.
|
|
18
|
+
* You may obtain a copy of the License at
|
|
19
|
+
* <p>
|
|
20
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
21
|
+
* <p>
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
* See the License for the specific language governing permissions and
|
|
26
|
+
* limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
const java_1 = require("../../java");
|
|
29
|
+
const index_1 = require("../index");
|
|
30
|
+
const parser_1 = require("../parser");
|
|
31
|
+
const dependency_workspace_1 = require("../dependency-workspace");
|
|
32
|
+
const uuid_1 = require("../../uuid");
|
|
33
|
+
/**
|
|
34
|
+
* Symbol to access wrappersMap without exposing it as public API
|
|
35
|
+
*/
|
|
36
|
+
exports.WRAPPERS_MAP_SYMBOL = Symbol('wrappersMap');
|
|
37
|
+
/**
|
|
38
|
+
* Cache for compiled templates and patterns.
|
|
39
|
+
* Stores parsed ASTs to avoid expensive re-parsing and dependency resolution.
|
|
40
|
+
*/
|
|
41
|
+
class TemplateCache {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.cache = new Map();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generates a cache key from template string, captures, and options.
|
|
47
|
+
*/
|
|
48
|
+
generateKey(templateString, captures, contextStatements, dependencies) {
|
|
49
|
+
// Use the actual template string (with placeholders) as the primary key
|
|
50
|
+
const templateKey = templateString;
|
|
51
|
+
// Capture names
|
|
52
|
+
const capturesKey = captures.map(c => c.getName()).join(',');
|
|
53
|
+
// Context statements
|
|
54
|
+
const contextKey = contextStatements.join(';');
|
|
55
|
+
// Dependencies
|
|
56
|
+
const depsKey = JSON.stringify(dependencies || {});
|
|
57
|
+
return `${templateKey}::${capturesKey}::${contextKey}::${depsKey}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets a cached compilation unit or creates and caches a new one.
|
|
61
|
+
*/
|
|
62
|
+
getOrParse(templateString, captures, contextStatements, dependencies) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const key = this.generateKey(templateString, captures, contextStatements, dependencies);
|
|
65
|
+
let cu = this.cache.get(key);
|
|
66
|
+
if (cu) {
|
|
67
|
+
return cu;
|
|
68
|
+
}
|
|
69
|
+
// Create workspace if dependencies are provided
|
|
70
|
+
// DependencyWorkspace has its own cache, so multiple templates with
|
|
71
|
+
// the same dependencies will automatically share the same workspace
|
|
72
|
+
let workspaceDir;
|
|
73
|
+
if (dependencies && Object.keys(dependencies).length > 0) {
|
|
74
|
+
workspaceDir = yield dependency_workspace_1.DependencyWorkspace.getOrCreateWorkspace(dependencies);
|
|
75
|
+
}
|
|
76
|
+
// Prepend context statements for type attribution context
|
|
77
|
+
const fullTemplateString = contextStatements.length > 0
|
|
78
|
+
? contextStatements.join('\n') + '\n' + templateString
|
|
79
|
+
: templateString;
|
|
80
|
+
// Parse and cache (workspace only needed during parsing)
|
|
81
|
+
const parser = new parser_1.JavaScriptParser({ relativeTo: workspaceDir });
|
|
82
|
+
const parseGenerator = parser.parse({ text: fullTemplateString, sourcePath: 'template.ts' });
|
|
83
|
+
cu = (yield parseGenerator.next()).value;
|
|
84
|
+
this.cache.set(key, cu);
|
|
85
|
+
return cu;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Clears the cache.
|
|
90
|
+
*/
|
|
91
|
+
clear() {
|
|
92
|
+
this.cache.clear();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.TemplateCache = TemplateCache;
|
|
96
|
+
// Global cache instance
|
|
97
|
+
exports.templateCache = new TemplateCache();
|
|
98
|
+
/**
|
|
99
|
+
* Marker that stores capture metadata on pattern AST nodes.
|
|
100
|
+
* This avoids the need to parse capture names from identifiers during matching.
|
|
101
|
+
*/
|
|
102
|
+
class CaptureMarker {
|
|
103
|
+
constructor(captureName, variadicOptions) {
|
|
104
|
+
this.captureName = captureName;
|
|
105
|
+
this.variadicOptions = variadicOptions;
|
|
106
|
+
this.kind = 'org.openrewrite.javascript.CaptureMarker';
|
|
107
|
+
this.id = (0, uuid_1.randomId)();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.CaptureMarker = CaptureMarker;
|
|
111
|
+
/**
|
|
112
|
+
* Utility class for managing placeholder naming and parsing.
|
|
113
|
+
* Centralizes all logic related to capture placeholders.
|
|
114
|
+
*/
|
|
115
|
+
class PlaceholderUtils {
|
|
116
|
+
/**
|
|
117
|
+
* Checks if a node is a capture placeholder.
|
|
118
|
+
*
|
|
119
|
+
* @param node The node to check
|
|
120
|
+
* @returns true if the node is a capture placeholder, false otherwise
|
|
121
|
+
*/
|
|
122
|
+
static isCapture(node) {
|
|
123
|
+
// Check for CaptureMarker first (efficient)
|
|
124
|
+
for (const marker of node.markers.markers) {
|
|
125
|
+
if (marker instanceof CaptureMarker) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the capture name from a node with a CaptureMarker.
|
|
133
|
+
*
|
|
134
|
+
* @param node The node to extract capture name from
|
|
135
|
+
* @returns The capture name, or null if not a capture
|
|
136
|
+
*/
|
|
137
|
+
static getCaptureName(node) {
|
|
138
|
+
// Check for CaptureMarker
|
|
139
|
+
for (const marker of node.markers.markers) {
|
|
140
|
+
if (marker instanceof CaptureMarker) {
|
|
141
|
+
return marker.captureName;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the CaptureMarker from a node, if present.
|
|
148
|
+
*
|
|
149
|
+
* @param node The node to check
|
|
150
|
+
* @returns The CaptureMarker or undefined
|
|
151
|
+
*/
|
|
152
|
+
static getCaptureMarker(node) {
|
|
153
|
+
for (const marker of node.markers.markers) {
|
|
154
|
+
if (marker instanceof CaptureMarker) {
|
|
155
|
+
return marker;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Parses a capture placeholder to extract name and type constraint.
|
|
162
|
+
*
|
|
163
|
+
* @param identifier The identifier string to parse
|
|
164
|
+
* @returns Object with name and optional type constraint, or null if not a valid capture
|
|
165
|
+
*/
|
|
166
|
+
static parseCapture(identifier) {
|
|
167
|
+
if (!identifier.startsWith(this.CAPTURE_PREFIX)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
// Handle unnamed captures: "__capt_unnamed_N__"
|
|
171
|
+
if (identifier.startsWith(`${this.CAPTURE_PREFIX}unnamed_`)) {
|
|
172
|
+
const match = identifier.match(/__capt_(unnamed_\d+)__/);
|
|
173
|
+
return match ? { name: match[1] } : null;
|
|
174
|
+
}
|
|
175
|
+
// Handle all other captures (including any()): "__capt_name__" or "__capt_name_type__"
|
|
176
|
+
const match = identifier.match(/__capt_([^_]+(?:_\d+)?)(?:_([^_]+))?__/);
|
|
177
|
+
if (!match) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
name: match[1],
|
|
182
|
+
typeConstraint: match[2]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a capture placeholder string.
|
|
187
|
+
*
|
|
188
|
+
* @param name The capture name
|
|
189
|
+
* @param typeConstraint Optional type constraint
|
|
190
|
+
* @returns The formatted placeholder string
|
|
191
|
+
*/
|
|
192
|
+
static createCapture(name, typeConstraint) {
|
|
193
|
+
// Always use CAPTURE_PREFIX - the capturing flag is used internally for binding behavior
|
|
194
|
+
return typeConstraint
|
|
195
|
+
? `${this.CAPTURE_PREFIX}${name}_${typeConstraint}__`
|
|
196
|
+
: `${this.CAPTURE_PREFIX}${name}__`;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Checks if a capture marker indicates a variadic capture.
|
|
200
|
+
*
|
|
201
|
+
* @param node The node to check
|
|
202
|
+
* @returns true if the node has a variadic CaptureMarker, false otherwise
|
|
203
|
+
*/
|
|
204
|
+
static isVariadicCapture(node) {
|
|
205
|
+
for (const marker of node.markers.markers) {
|
|
206
|
+
if (marker instanceof CaptureMarker && marker.variadicOptions) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets the variadic options from a capture marker.
|
|
214
|
+
*
|
|
215
|
+
* @param node The node to extract variadic options from
|
|
216
|
+
* @returns The VariadicOptions, or undefined if not a variadic capture
|
|
217
|
+
*/
|
|
218
|
+
static getVariadicOptions(node) {
|
|
219
|
+
for (const marker of node.markers.markers) {
|
|
220
|
+
if (marker instanceof CaptureMarker) {
|
|
221
|
+
return marker.variadicOptions;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Checks if a statement is an ExpressionStatement wrapping a capture identifier.
|
|
228
|
+
* When a capture placeholder appears in statement position, the parser wraps it as
|
|
229
|
+
* an ExpressionStatement. This method unwraps it to get the identifier.
|
|
230
|
+
*
|
|
231
|
+
* @param stmt The statement to check
|
|
232
|
+
* @returns The unwrapped capture identifier, or the original statement if not wrapped
|
|
233
|
+
*/
|
|
234
|
+
static unwrapStatementCapture(stmt) {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
// Check if it's an ExpressionStatement containing a capture identifier
|
|
237
|
+
if (stmt.kind === index_1.JS.Kind.ExpressionStatement) {
|
|
238
|
+
const exprStmt = stmt;
|
|
239
|
+
if (((_a = exprStmt.expression) === null || _a === void 0 ? void 0 : _a.kind) === java_1.J.Kind.Identifier) {
|
|
240
|
+
const identifier = exprStmt.expression;
|
|
241
|
+
// Check if this is a capture placeholder
|
|
242
|
+
if ((_b = identifier.simpleName) === null || _b === void 0 ? void 0 : _b.startsWith(this.CAPTURE_PREFIX)) {
|
|
243
|
+
return identifier;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return stmt;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.PlaceholderUtils = PlaceholderUtils;
|
|
251
|
+
PlaceholderUtils.CAPTURE_PREFIX = '__capt_';
|
|
252
|
+
PlaceholderUtils.PLACEHOLDER_PREFIX = '__PLACEHOLDER_';
|
|
253
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,qCAA6B;AAC7B,oCAA4B;AAC5B,sCAA2C;AAC3C,kEAA4D;AAE5D,qCAAoC;AAYpC;;GAEG;AACU,QAAA,mBAAmB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAa,aAAa;IAA1B;QACY,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IAsE1D,CAAC;IApEG;;OAEG;IACK,WAAW,CACf,cAAsB,EACtB,QAAgC,EAChC,iBAA2B,EAC3B,YAAoC;QAEpC,wEAAwE;QACxE,MAAM,WAAW,GAAG,cAAc,CAAC;QAEnC,gBAAgB;QAChB,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE7D,qBAAqB;QACrB,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE/C,eAAe;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CA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