@openrewrite/rewrite 8.67.0-20251106-160325 → 8.67.0-20251107-071946
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/tree.d.ts +2 -0
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/tree.js +5 -1
- package/dist/java/tree.js.map +1 -1
- package/dist/javascript/assertions.js +2 -2
- package/dist/javascript/assertions.js.map +1 -1
- package/dist/javascript/format.js +1 -1
- package/dist/javascript/format.js.map +1 -1
- package/dist/javascript/templating/engine.d.ts +34 -8
- package/dist/javascript/templating/engine.d.ts.map +1 -1
- package/dist/javascript/templating/engine.js +317 -60
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts +11 -0
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +36 -295
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
- package/dist/javascript/templating/template.d.ts +9 -2
- package/dist/javascript/templating/template.d.ts.map +1 -1
- package/dist/javascript/templating/template.js +37 -0
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +26 -11
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/javascript/templating/utils.d.ts +41 -22
- package/dist/javascript/templating/utils.d.ts.map +1 -1
- package/dist/javascript/templating/utils.js +111 -76
- package/dist/javascript/templating/utils.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +3 -1
- package/src/java/tree.ts +2 -0
- package/src/javascript/assertions.ts +1 -1
- package/src/javascript/format.ts +1 -1
- package/src/javascript/templating/engine.ts +376 -54
- package/src/javascript/templating/pattern.ts +55 -322
- package/src/javascript/templating/placeholder-replacement.ts +1 -1
- package/src/javascript/templating/template.ts +57 -3
- package/src/javascript/templating/types.ts +27 -11
- package/src/javascript/templating/utils.ts +113 -81
|
@@ -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,
|
|
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,WAAW,EAAE,OAAO,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,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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
|
|
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
|
-
*
|
|
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
|
|
21
|
+
export declare const WRAPPER_FUNCTION_NAME = "__WRAPPER__";
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
|
28
|
+
export declare class LRUCache<K, V> {
|
|
29
|
+
private maxSize;
|
|
30
30
|
private cache;
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/utils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAC;AAExC;;;;;;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;AAEzD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IAGV,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,KAAK,CAAmB;gBAEZ,OAAO,EAAE,MAAM;IAEnC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAU1B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAiB3B,KAAK,IAAI,IAAI;CAGhB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,qBAA+B,CAAC;AAE3D;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC5B,aAAa,EAAE,MAAM,EAAE,GAAG,oBAAoB,EAC9C,QAAQ,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AAO;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.
|
|
13
|
-
exports.
|
|
14
|
-
const
|
|
15
|
-
const
|
|
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
|
-
*
|
|
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
|
-
|
|
16
|
+
exports.WRAPPER_FUNCTION_NAME = '__WRAPPER__';
|
|
25
17
|
/**
|
|
26
|
-
*
|
|
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
|
-
*
|
|
21
|
+
* Used by both Pattern and Template caching to provide bounded memory usage.
|
|
29
22
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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.
|
|
96
|
-
|
|
97
|
-
|
|
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/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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-
|
|
1
|
+
8.67.0-20251107-071946
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/rewrite",
|
|
3
|
-
"version": "8.67.0-
|
|
3
|
+
"version": "8.67.0-20251107-071946",
|
|
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/
|
|
22
|
+
import {setTemplateSourceFileCache} from "./templating/engine";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Shared TypeScript source file cache for test parsers.
|
package/src/javascript/format.ts
CHANGED
|
@@ -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
|
}
|