@openrewrite/rewrite 8.67.0-20251106-160325 → 8.67.0-20251107-103550

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 (44) hide show
  1. package/dist/java/tree.d.ts +2 -0
  2. package/dist/java/tree.d.ts.map +1 -1
  3. package/dist/java/tree.js +5 -1
  4. package/dist/java/tree.js.map +1 -1
  5. package/dist/javascript/assertions.js +2 -2
  6. package/dist/javascript/assertions.js.map +1 -1
  7. package/dist/javascript/format.js +1 -1
  8. package/dist/javascript/format.js.map +1 -1
  9. package/dist/javascript/templating/engine.d.ts +41 -25
  10. package/dist/javascript/templating/engine.d.ts.map +1 -1
  11. package/dist/javascript/templating/engine.js +378 -92
  12. package/dist/javascript/templating/engine.js.map +1 -1
  13. package/dist/javascript/templating/pattern.d.ts +11 -0
  14. package/dist/javascript/templating/pattern.d.ts.map +1 -1
  15. package/dist/javascript/templating/pattern.js +36 -295
  16. package/dist/javascript/templating/pattern.js.map +1 -1
  17. package/dist/javascript/templating/placeholder-replacement.d.ts +1 -1
  18. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
  19. package/dist/javascript/templating/rewrite.d.ts +17 -11
  20. package/dist/javascript/templating/rewrite.d.ts.map +1 -1
  21. package/dist/javascript/templating/rewrite.js +17 -11
  22. package/dist/javascript/templating/rewrite.js.map +1 -1
  23. package/dist/javascript/templating/template.d.ts +17 -3
  24. package/dist/javascript/templating/template.d.ts.map +1 -1
  25. package/dist/javascript/templating/template.js +45 -5
  26. package/dist/javascript/templating/template.js.map +1 -1
  27. package/dist/javascript/templating/types.d.ts +36 -13
  28. package/dist/javascript/templating/types.d.ts.map +1 -1
  29. package/dist/javascript/templating/utils.d.ts +41 -22
  30. package/dist/javascript/templating/utils.d.ts.map +1 -1
  31. package/dist/javascript/templating/utils.js +111 -76
  32. package/dist/javascript/templating/utils.js.map +1 -1
  33. package/dist/version.txt +1 -1
  34. package/package.json +3 -1
  35. package/src/java/tree.ts +2 -0
  36. package/src/javascript/assertions.ts +1 -1
  37. package/src/javascript/format.ts +1 -1
  38. package/src/javascript/templating/engine.ts +439 -105
  39. package/src/javascript/templating/pattern.ts +55 -322
  40. package/src/javascript/templating/placeholder-replacement.ts +1 -1
  41. package/src/javascript/templating/rewrite.ts +17 -11
  42. package/src/javascript/templating/template.ts +66 -11
  43. package/src/javascript/templating/types.ts +37 -13
  44. package/src/javascript/templating/utils.ts +114 -81
@@ -193,8 +193,47 @@ class Template {
193
193
  */
194
194
  configure(options) {
195
195
  this.options = Object.assign(Object.assign({}, this.options), options);
196
+ // Invalidate cache when configuration changes
197
+ this._cachedTemplate = undefined;
196
198
  return this;
197
199
  }
200
+ /**
201
+ * Gets the template tree for this template, using two-level caching:
202
+ * - Level 1: Instance cache (this._cachedTemplate) - fastest, no lookup needed
203
+ * - Level 2: Global cache (globalAstCache) - fast, shared across all templates
204
+ * - Level 3: TemplateEngine - slow, parses and processes the template
205
+ *
206
+ * Since all parameters are now placeholders (no primitives), templates with the same
207
+ * structure always parse to the same AST regardless of parameter values.
208
+ *
209
+ * @returns The cached or newly computed template tree
210
+ * @internal
211
+ */
212
+ getTemplateTree() {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ // Level 1: Instance cache (fastest path)
215
+ if (this._cachedTemplate) {
216
+ return this._cachedTemplate;
217
+ }
218
+ // Generate cache key for global lookup
219
+ // Since all parameters use placeholders, we only need the template structure
220
+ const contextStatements = this.options.context || this.options.imports || [];
221
+ const parametersKey = this.parameters.length.toString(); // Just the count
222
+ const cacheKey = (0, utils_1.generateCacheKey)(this.templateParts, parametersKey, contextStatements, this.options.dependencies || {});
223
+ // Level 2: Global cache (fast path - shared with Pattern)
224
+ const cached = utils_1.globalAstCache.get(cacheKey);
225
+ if (cached) {
226
+ this._cachedTemplate = cached;
227
+ return cached;
228
+ }
229
+ // Level 3: Compute via TemplateEngine (slow path)
230
+ const result = yield engine_1.TemplateEngine.getTemplateTree(this.templateParts, this.parameters, contextStatements, this.options.dependencies || {});
231
+ // Cache in both levels
232
+ utils_1.globalAstCache.set(cacheKey, result);
233
+ this._cachedTemplate = result;
234
+ return result;
235
+ });
236
+ }
198
237
  /**
199
238
  * Applies this template and returns the resulting tree.
200
239
  *
@@ -241,12 +280,13 @@ class Template {
241
280
  normalizedValues = normalized;
242
281
  }
243
282
  }
244
- // Prefer 'context' over deprecated 'imports'
245
- const contextStatements = this.options.context || this.options.imports || [];
246
- return engine_1.TemplateEngine.applyTemplate(this.templateParts, this.parameters, cursor, {
283
+ // Use instance-level cache to get the template tree
284
+ const ast = yield this.getTemplateTree();
285
+ // Delegate to TemplateEngine for placeholder substitution and application
286
+ return engine_1.TemplateEngine.applyTemplateFromAst(ast, this.parameters, cursor, {
247
287
  tree,
248
288
  mode: JavaCoordinates.Mode.Replace
249
- }, normalizedValues, wrappersMap, contextStatements, this.options.dependencies || {});
289
+ }, normalizedValues, wrappersMap);
250
290
  });
251
291
  }
252
292
  }
@@ -260,7 +300,7 @@ exports.Template = Template;
260
300
  * access array elements (e.g., `args.elements[0].element`).
261
301
  *
262
302
  * @param strings The string parts of the template
263
- * @param parameters The parameters between the string parts (Capture, Tree, or primitives)
303
+ * @param parameters The parameters between the string parts (Capture, CaptureValue, TemplateParam, Tree, or Tree[])
264
304
  * @returns A Template object that can be applied to generate AST nodes
265
305
  *
266
306
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/javascript/templating/template.ts"],"names":[],"mappings":";;;;;;;;;;;;AAwUA,4BAQC;AA9TD,uCAAsC;AACtC,mCAA4C;AAC5C,uCAA8C;AAC9C,qCAAmD;AAWnD,IAAU,eAAe,CASxB;AATD,WAAU,eAAe;IAIrB,IAAY,IAIX;IAJD,WAAY,IAAI;QACZ,mCAAM,CAAA;QACN,iCAAK,CAAA;QACL,qCAAO,CAAA;IACX,CAAC,EAJW,IAAI,GAAJ,oBAAI,KAAJ,oBAAI,QAIf;AACL,CAAC,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YAC7E,OAAO,uBAAc,CAAC,aAAa,CAC/B,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,UAAU,EACf,MAAM,EACN;gBACI,IAAI;gBACJ,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO;aACrC,EACD,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAClC,CAAC;QACN,CAAC;KAAA;CACJ;AA9GD,4BA8GC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,SAAgB,QAAQ,CAAC,OAA6B,EAAE,GAAG,UAA+B;IACtF,8FAA8F;IAC9F,MAAM,mBAAmB,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC/C,uDAAuD;QACvD,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACtD,CAAC"}
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/javascript/templating/template.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+XA,4BAQC;AArXD,uCAAsC;AACtC,mCAA8E;AAC9E,uCAA8C;AAC9C,qCAAwC;AAYxC,IAAU,eAAe,CASxB;AATD,WAAU,eAAe;IAIrB,IAAY,IAIX;IAJD,WAAY,IAAI;QACZ,mCAAM,CAAA;QACN,iCAAK,CAAA;QACL,qCAAO,CAAA;IACX,CAAC,EAJW,IAAI,GAAJ,oBAAI,KAAJ,oBAAI,QAIf;AACL,CAAC,EATS,eAAe,KAAf,eAAe,QASxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,eAAe;IAA5B;QACY,UAAK,GAAa,EAAE,CAAC;QACrB,WAAM,GAAwB,EAAE,CAAC;IA6D7C,CAAC;IA3DG;;;;;OAKG;IACH,IAAI,CAAC,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A+B;IACtF,8FAA8F;IAC9F,MAAM,mBAAmB,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC/C,uDAAuD;QACvD,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACtD,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { Cursor, Tree } from '../..';
2
2
  import { J, Type } from '../../java';
3
- import type { Pattern, MatchResult } from "./pattern";
3
+ import type { MatchResult, Pattern } from "./pattern";
4
4
  import type { Template } from "./template";
5
+ import type { CaptureValue } from "./capture";
5
6
  /**
6
7
  * Options for variadic captures that match zero or more nodes in a sequence.
7
8
  */
@@ -81,14 +82,14 @@ export interface CaptureOptions<T = any> {
81
82
  * but does NOT enforce any runtime constraints on what the capture will match.
82
83
  *
83
84
  * **Pattern Matching Behavior:**
84
- * - A bare `pattern`${capture('x')}`` will structurally match ANY expression
85
- * - Pattern structure determines matching: `pattern`foo(${capture('x')})`` only matches `foo()` calls
85
+ * - A bare `pattern`${capture()}`` will structurally match ANY expression
86
+ * - Pattern structure determines matching: `pattern`foo(${capture()})`` only matches `foo()` calls with one arg
86
87
  * - Use structural patterns to narrow matching scope before applying semantic validation
87
88
  *
88
89
  * **Variadic Captures:**
89
90
  * Use `{ variadic: true }` to match zero or more nodes in a sequence:
90
91
  * ```typescript
91
- * const args = capture('args', { variadic: true });
92
+ * const args = capture({ variadic: true });
92
93
  * pattern`foo(${args})` // Matches: foo(), foo(a), foo(a, b, c)
93
94
  * ```
94
95
  */
@@ -145,8 +146,9 @@ export interface Capture<T = any> {
145
146
  *
146
147
  * @example
147
148
  * // Variadic any - match zero or more without capturing
149
+ * const first = any();
148
150
  * const rest = any({ variadic: true });
149
- * const pat = pattern`bar(${capture('first')}, ${rest})`
151
+ * const pat = pattern`bar(${first}, ${rest})`
150
152
  *
151
153
  * @example
152
154
  * // With constraints - validate but don't capture
@@ -240,11 +242,29 @@ export interface PatternOptions {
240
242
  * Valid parameter types for template literals.
241
243
  * - Capture: For pattern matching and reuse
242
244
  * - CaptureValue: Result of property access or array operations on captures (e.g., capture.prop, capture[0], capture.slice(1))
245
+ * - TemplateParam: For standalone template parameters
243
246
  * - Tree: AST nodes to be inserted directly
244
247
  * - Tree[]: Arrays of AST nodes (from variadic capture operations like slice)
245
- * - Primitives: Values to be converted to literals
248
+ *
249
+ * Note: Primitive values (string, number, boolean) are NOT supported in template literals.
250
+ * Use Template.builder() API if you need to insert literal values.
251
+ */
252
+ export type TemplateParameter = Capture | CaptureValue | TemplateParam | Tree | Tree[];
253
+ /**
254
+ * Parameter specification for template generation (internal).
255
+ * Represents a placeholder in a template that will be replaced with a parameter value.
256
+ * This is the internal wrapper used by the template engine.
257
+ *
258
+ * Note: The value is typed as `any` rather than `TemplateParameter` to allow flexible
259
+ * internal handling without excessive type guards. The public API (template function)
260
+ * constrains inputs to `TemplateParameter`, providing type safety at the API boundary.
246
261
  */
247
- export type TemplateParameter = Capture | any | TemplateParam | Tree | Tree[] | string | number | boolean;
262
+ export interface Parameter {
263
+ /**
264
+ * The value to substitute into the template.
265
+ */
266
+ value: any;
267
+ }
248
268
  /**
249
269
  * Configuration options for templates.
250
270
  */
@@ -309,18 +329,21 @@ export interface RewriteRule {
309
329
  *
310
330
  * @example
311
331
  * ```typescript
312
- * const rule1 = rewrite(() => ({
313
- * before: pattern`${capture('a')} + ${capture('b')}`,
314
- * after: template`${capture('b')} + ${capture('a')}`
315
- * }));
332
+ * const rule1 = rewrite(() => {
333
+ * const { a, b } = { a: capture(), b: capture() };
334
+ * return {
335
+ * before: pattern`${a} + ${b}`,
336
+ * after: template`${b} + ${a}`
337
+ * };
338
+ * });
316
339
  *
317
340
  * const rule2 = rewrite(() => ({
318
341
  * before: pattern`${capture('x')} + 1`,
319
- * after: template`${capture('x')} + 2`
342
+ * after: template`${capture('x')}++`
320
343
  * }));
321
344
  *
322
345
  * const combined = rule1.andThen(rule2);
323
- * // Will first swap operands, then if result matches "x + 1", change to "x + 2"
346
+ * // Will first swap operands, then if result matches "x + 1", change to "x++"
324
347
  * ```
325
348
  */
326
349
  andThen(next: RewriteRule): RewriteRule;
@@ -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,EAAE,IAAI,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAC,OAAO,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IACrC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,GAAG;IAC5B;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC;IAEtB;;OAEG;IACH,kBAAkB,IAAI,eAAe,GAAG,SAAS,CAAC;IAElD;;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CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC5B,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,KAAK,QAAQ,CAAC,CAAC;IAErD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtE"}
@@ -1,9 +1,7 @@
1
- import ts from 'typescript';
2
1
  import { Cursor } from '../..';
3
2
  import { J } from '../../java';
4
- import { JS } from '../index';
5
3
  import { Marker, Markers } from '../../markers';
6
- import { VariadicOptions, Capture, Any } from './types';
4
+ import { VariadicOptions } from './types';
7
5
  /**
8
6
  * Internal storage value type for pattern match captures.
9
7
  * - J: Scalar captures without wrapper (fallback)
@@ -17,31 +15,42 @@ export type CaptureStorageValue = J | J.RightPadded<J> | J[] | J.RightPadded<J>[
17
15
  */
18
16
  export declare const WRAPPERS_MAP_SYMBOL: unique symbol;
19
17
  /**
20
- * Configure the sourceFileCache used for template parsing.
21
- *
22
- * @param cache The sourceFileCache to use, or undefined to disable caching
18
+ * Shared wrapper function name used by both patterns and templates.
19
+ * Using the same name allows cache sharing when pattern and template code is identical.
23
20
  */
24
- export declare function setTemplateSourceFileCache(cache?: Map<string, ts.SourceFile>): void;
21
+ export declare const WRAPPER_FUNCTION_NAME = "__WRAPPER__";
25
22
  /**
26
- * Cache for compiled templates and patterns.
27
- * Stores parsed ASTs to avoid expensive re-parsing and dependency resolution.
23
+ * Simple LRU (Least Recently Used) cache implementation using Map's insertion order.
24
+ * JavaScript Map maintains insertion order, so the first entry is the oldest.
25
+ *
26
+ * Used by both Pattern and Template caching to provide bounded memory usage.
28
27
  */
29
- export declare class TemplateCache {
28
+ export declare class LRUCache<K, V> {
29
+ private maxSize;
30
30
  private cache;
31
- /**
32
- * Generates a cache key from template string, captures, and options.
33
- */
34
- private generateKey;
35
- /**
36
- * Gets a cached compilation unit or creates and caches a new one.
37
- */
38
- getOrParse(templateString: string, captures: (Capture | Any)[], contextStatements: string[], dependencies: Record<string, string>): Promise<JS.CompilationUnit>;
39
- /**
40
- * Clears the cache.
41
- */
31
+ constructor(maxSize: number);
32
+ get(key: K): V | undefined;
33
+ set(key: K, value: V): void;
42
34
  clear(): void;
43
35
  }
44
- export declare const templateCache: TemplateCache;
36
+ /**
37
+ * Shared global LRU cache for both pattern and template ASTs.
38
+ * When pattern and template code is identical, they share the same cached AST.
39
+ * This mirrors JavaTemplate's unified approach in the Java implementation.
40
+ * Bounded to 100 entries using LRU eviction.
41
+ */
42
+ export declare const globalAstCache: LRUCache<string, J>;
43
+ /**
44
+ * Generates a cache key for template/pattern processing.
45
+ * Used by both Pattern and Template for consistent cache key generation.
46
+ *
47
+ * @param templateParts The template string parts
48
+ * @param itemsKey String representing the captures/parameters (comma-separated)
49
+ * @param contextStatements Context declarations
50
+ * @param dependencies NPM dependencies
51
+ * @returns A cache key string
52
+ */
53
+ export declare function generateCacheKey(templateParts: string[] | TemplateStringsArray, itemsKey: string, contextStatements: string[], dependencies: Record<string, string>): string;
45
54
  /**
46
55
  * Marker that stores capture metadata on pattern AST nodes.
47
56
  * This avoids the need to parse capture names from identifiers during matching.
@@ -113,5 +122,15 @@ export declare class PlaceholderUtils {
113
122
  static getVariadicOptions(node: {
114
123
  markers: Markers;
115
124
  }): VariadicOptions | undefined;
125
+ /**
126
+ * Extracts the relevant AST node from a wrapper function.
127
+ * Used by both pattern and template processors to intelligently extract
128
+ * code from `function __WRAPPER__() { code }` wrappers.
129
+ *
130
+ * @param lastStatement The last statement from the compilation unit
131
+ * @param contextName Context name for error messages (e.g., 'Pattern', 'Template')
132
+ * @returns The extracted AST node
133
+ */
134
+ static extractFromWrapper(lastStatement: J, contextName: string): J;
116
135
  }
117
136
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAC;AAG5B,OAAO,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAC,eAAe,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,SAAS,CAAC;AAEtD;;;;;;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;AAOzD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,IAAI,CAEnF;AAED;;;GAGG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,KAAK,CAAyC;IAEtD;;OAEG;IAC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I,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM;IAOnE;;;;;OAKG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO;IAS7D;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,eAAe,GAAG,SAAS;IASlF;;;;;;;;OAQG;IACH,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;CA0CtE"}
@@ -1,100 +1,83 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PlaceholderUtils = exports.CaptureMarker = exports.templateCache = exports.TemplateCache = exports.WRAPPERS_MAP_SYMBOL = void 0;
13
- exports.setTemplateSourceFileCache = setTemplateSourceFileCache;
14
- const parser_1 = require("../parser");
15
- const dependency_workspace_1 = require("../dependency-workspace");
3
+ exports.PlaceholderUtils = exports.CaptureMarker = exports.globalAstCache = exports.LRUCache = exports.WRAPPER_FUNCTION_NAME = exports.WRAPPERS_MAP_SYMBOL = void 0;
4
+ exports.generateCacheKey = generateCacheKey;
5
+ const java_1 = require("../../java");
6
+ const index_1 = require("../index");
16
7
  const uuid_1 = require("../../uuid");
17
8
  /**
18
9
  * Symbol to access wrappersMap without exposing it as public API
19
10
  */
20
11
  exports.WRAPPERS_MAP_SYMBOL = Symbol('wrappersMap');
21
12
  /**
22
- * Module-level TypeScript sourceFileCache for template parsing.
13
+ * Shared wrapper function name used by both patterns and templates.
14
+ * Using the same name allows cache sharing when pattern and template code is identical.
23
15
  */
24
- let templateSourceFileCache;
16
+ exports.WRAPPER_FUNCTION_NAME = '__WRAPPER__';
25
17
  /**
26
- * Configure the sourceFileCache used for template parsing.
18
+ * Simple LRU (Least Recently Used) cache implementation using Map's insertion order.
19
+ * JavaScript Map maintains insertion order, so the first entry is the oldest.
27
20
  *
28
- * @param cache The sourceFileCache to use, or undefined to disable caching
21
+ * Used by both Pattern and Template caching to provide bounded memory usage.
29
22
  */
30
- function setTemplateSourceFileCache(cache) {
31
- templateSourceFileCache = cache;
32
- }
33
- /**
34
- * Cache for compiled templates and patterns.
35
- * Stores parsed ASTs to avoid expensive re-parsing and dependency resolution.
36
- */
37
- class TemplateCache {
38
- constructor() {
23
+ class LRUCache {
24
+ constructor(maxSize) {
25
+ this.maxSize = maxSize;
39
26
  this.cache = new Map();
40
27
  }
41
- /**
42
- * Generates a cache key from template string, captures, and options.
43
- */
44
- generateKey(templateString, captures, contextStatements, dependencies) {
45
- // Use the actual template string (with placeholders) as the primary key
46
- const templateKey = templateString;
47
- // Capture names
48
- const capturesKey = captures.map(c => c.getName()).join(',');
49
- // Context statements
50
- const contextKey = contextStatements.join(';');
51
- // Dependencies
52
- const depsKey = JSON.stringify(dependencies || {});
53
- return `${templateKey}::${capturesKey}::${contextKey}::${depsKey}`;
28
+ get(key) {
29
+ const value = this.cache.get(key);
30
+ if (value !== undefined) {
31
+ // Move to end (most recently used)
32
+ this.cache.delete(key);
33
+ this.cache.set(key, value);
34
+ }
35
+ return value;
54
36
  }
55
- /**
56
- * Gets a cached compilation unit or creates and caches a new one.
57
- */
58
- getOrParse(templateString, captures, contextStatements, dependencies) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const key = this.generateKey(templateString, captures, contextStatements, dependencies);
61
- let cu = this.cache.get(key);
62
- if (cu) {
63
- return cu;
64
- }
65
- // Create workspace if dependencies are provided
66
- // DependencyWorkspace has its own cache, so multiple templates with
67
- // the same dependencies will automatically share the same workspace
68
- let workspaceDir;
69
- if (dependencies && Object.keys(dependencies).length > 0) {
70
- workspaceDir = yield dependency_workspace_1.DependencyWorkspace.getOrCreateWorkspace(dependencies);
37
+ set(key, value) {
38
+ // Remove if exists (to update position)
39
+ this.cache.delete(key);
40
+ // Add to end
41
+ this.cache.set(key, value);
42
+ // Evict oldest if over capacity
43
+ if (this.cache.size > this.maxSize) {
44
+ const iterator = this.cache.keys();
45
+ const firstEntry = iterator.next();
46
+ if (!firstEntry.done) {
47
+ this.cache.delete(firstEntry.value);
71
48
  }
72
- // Prepend context statements for type attribution context
73
- const fullTemplateString = contextStatements.length > 0
74
- ? contextStatements.join('\n') + '\n' + templateString
75
- : templateString;
76
- // Parse and cache (workspace only needed during parsing)
77
- // Use templateSourceFileCache if configured for ~3.2x speedup on dependency file parsing
78
- const parser = new parser_1.JavaScriptParser({
79
- relativeTo: workspaceDir,
80
- sourceFileCache: templateSourceFileCache
81
- });
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
- });
49
+ }
87
50
  }
88
- /**
89
- * Clears the cache.
90
- */
91
51
  clear() {
92
52
  this.cache.clear();
93
53
  }
94
54
  }
95
- exports.TemplateCache = TemplateCache;
96
- // Global cache instance
97
- exports.templateCache = new TemplateCache();
55
+ exports.LRUCache = LRUCache;
56
+ /**
57
+ * Shared global LRU cache for both pattern and template ASTs.
58
+ * When pattern and template code is identical, they share the same cached AST.
59
+ * This mirrors JavaTemplate's unified approach in the Java implementation.
60
+ * Bounded to 100 entries using LRU eviction.
61
+ */
62
+ exports.globalAstCache = new LRUCache(100);
63
+ /**
64
+ * Generates a cache key for template/pattern processing.
65
+ * Used by both Pattern and Template for consistent cache key generation.
66
+ *
67
+ * @param templateParts The template string parts
68
+ * @param itemsKey String representing the captures/parameters (comma-separated)
69
+ * @param contextStatements Context declarations
70
+ * @param dependencies NPM dependencies
71
+ * @returns A cache key string
72
+ */
73
+ function generateCacheKey(templateParts, itemsKey, contextStatements, dependencies) {
74
+ return [
75
+ Array.from(templateParts).join('|'),
76
+ itemsKey,
77
+ contextStatements.join(';'),
78
+ JSON.stringify(dependencies)
79
+ ].join('::');
80
+ }
98
81
  /**
99
82
  * Marker that stores capture metadata on pattern AST nodes.
100
83
  * This avoids the need to parse capture names from identifiers during matching.
@@ -209,6 +192,58 @@ class PlaceholderUtils {
209
192
  }
210
193
  return undefined;
211
194
  }
195
+ /**
196
+ * Extracts the relevant AST node from a wrapper function.
197
+ * Used by both pattern and template processors to intelligently extract
198
+ * code from `function __WRAPPER__() { code }` wrappers.
199
+ *
200
+ * @param lastStatement The last statement from the compilation unit
201
+ * @param contextName Context name for error messages (e.g., 'Pattern', 'Template')
202
+ * @returns The extracted AST node
203
+ */
204
+ static extractFromWrapper(lastStatement, contextName) {
205
+ var _a;
206
+ let extracted;
207
+ // Since we always wrap in function __WRAPPER__() { code }, look for it
208
+ if (lastStatement.kind === java_1.J.Kind.MethodDeclaration) {
209
+ const method = lastStatement;
210
+ if (((_a = method.name) === null || _a === void 0 ? void 0 : _a.simpleName) === exports.WRAPPER_FUNCTION_NAME && method.body) {
211
+ const body = method.body;
212
+ // Intelligently extract based on what's in the function body
213
+ if (body.statements.length === 0) {
214
+ throw new Error(`${contextName} function body is empty`);
215
+ }
216
+ else if (body.statements.length === 1) {
217
+ const stmt = body.statements[0].element;
218
+ // Single expression statement → extract the expression
219
+ if (stmt.kind === index_1.JS.Kind.ExpressionStatement) {
220
+ extracted = stmt.expression;
221
+ }
222
+ // Single block statement → keep the block
223
+ else if (stmt.kind === java_1.J.Kind.Block) {
224
+ extracted = stmt;
225
+ }
226
+ // Other single statement → keep it
227
+ else {
228
+ extracted = stmt;
229
+ }
230
+ }
231
+ else {
232
+ // Multiple statements → keep the block
233
+ extracted = body;
234
+ }
235
+ }
236
+ else {
237
+ // Not our wrapper function
238
+ extracted = lastStatement;
239
+ }
240
+ }
241
+ else {
242
+ // Shouldn't happen with our wrapping strategy, but handle it
243
+ extracted = lastStatement;
244
+ }
245
+ return extracted;
246
+ }
212
247
  }
213
248
  exports.PlaceholderUtils = PlaceholderUtils;
214
249
  PlaceholderUtils.CAPTURE_PREFIX = '__capt_';
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAiDA,gEAEC;AAhCD,sCAA2C;AAC3C,kEAA4D;AAE5D,qCAAoC;AAYpC;;GAEG;AACU,QAAA,mBAAmB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEzD;;GAEG;AACH,IAAI,uBAA+D,CAAC;AAEpE;;;;GAIG;AACH,SAAgB,0BAA0B,CAAC,KAAkC;IACzE,uBAAuB,GAAG,KAAK,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAa,aAAa;IAA1B;QACY,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IA0E1D,CAAC;IAxEG;;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,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QAEnD,OAAO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AC;qBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACtC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;oBAExC,uDAAuD;oBACvD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;wBAC5C,SAAS,GAAI,IAA+B,CAAC,UAAU,CAAC;oBAC5D,CAAC;oBACD,0CAA0C;yBACrC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;wBAClC,SAAS,GAAG,IAAI,CAAC;oBACrB,CAAC;oBACD,mCAAmC;yBAC9B,CAAC;wBACF,SAAS,GAAG,IAAI,CAAC;oBACrB,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,uCAAuC;oBACvC,SAAS,GAAG,IAAI,CAAC;gBACrB,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,2BAA2B;gBAC3B,SAAS,GAAG,aAAa,CAAC;YAC9B,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,6DAA6D;YAC7D,SAAS,GAAG,aAAa,CAAC;QAC9B,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;;AA9JL,4CA+JC;AA9JmB,+BAAc,GAAG,SAAS,CAAC;AAC3B,mCAAkB,GAAG,gBAAgB,CAAC"}
package/dist/version.txt CHANGED
@@ -1 +1 @@
1
- 8.67.0-20251106-160325
1
+ 8.67.0-20251107-103550
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.67.0-20251106-160325",
3
+ "version": "8.67.0-20251107-103550",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "homepage": "https://github.com/openrewrite/rewrite",
@@ -41,9 +41,11 @@
41
41
  "vscode-jsonrpc": "^8.2.1"
42
42
  },
43
43
  "devDependencies": {
44
+ "@types/benchmark": "^2.1.5",
44
45
  "@types/diff": "^5.2.2",
45
46
  "@types/jest": "^29.5.13",
46
47
  "@types/picomatch": "^4.0.2",
48
+ "benchmark": "^2.1.4",
47
49
  "jest": "^29.7.0",
48
50
  "jest-junit": "^16.0.0",
49
51
  "ts-jest": "^29.2.5",
package/src/java/tree.ts CHANGED
@@ -841,6 +841,8 @@ export const isIf = (tree: any): tree is J.If => tree["kind"] === J.Kind.If;
841
841
  export const isLambda = (tree: any): tree is J.Lambda => tree["kind"] === J.Kind.Lambda;
842
842
  export const isLiteral = (tree: any): tree is J.Literal => tree["kind"] === J.Kind.Literal;
843
843
  export const isMethodDeclaration = (n: any): n is J.MethodDeclaration => n.kind === J.Kind.MethodDeclaration;
844
+ export const isMethodInvocation = (n: any): n is J.MethodInvocation => n.kind === J.Kind.MethodInvocation;
845
+ export const isNewClass = (n: any): n is J.NewClass => n.kind === J.Kind.NewClass;
844
846
  export const isVariableDeclarations = (n: any): n is J.VariableDeclarations => n.kind === J.Kind.VariableDeclarations;
845
847
 
846
848
  export function rightPadded<T extends J | boolean>(t: T, trailing: J.Space, markers?: Markers): J.RightPadded<T> {
@@ -19,7 +19,7 @@ import {JS} from "./tree";
19
19
  import ts from 'typescript';
20
20
  import {json, Json} from "../json";
21
21
  import {DependencyWorkspace} from "./dependency-workspace";
22
- import {setTemplateSourceFileCache} from "./templating/utils";
22
+ import {setTemplateSourceFileCache} from "./templating/engine";
23
23
 
24
24
  /**
25
25
  * Shared TypeScript source file cache for test parsers.
@@ -1039,7 +1039,7 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
1039
1039
  const b = await super.visitBlock(block, p) as J.Block;
1040
1040
  return produce(b, draft => {
1041
1041
  if (!draft.end.whitespace.includes("\n")) {
1042
- draft.end.whitespace = draft.end.whitespace + "\n";
1042
+ draft.end.whitespace = draft.end.whitespace.replace(/[ \t]+$/, '') + "\n";
1043
1043
  }
1044
1044
  });
1045
1045
  }