@openrewrite/rewrite 8.81.2 → 8.81.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rpc/server.js +0 -0
- package/package.json +1 -1
- package/src/java/s.js~ +48 -0
- package/src/javascript/s.js~ +48 -0
- package/src/javascript/s2.js~ +68 -0
- package/src/rpc/server.ts +0 -0
- package/dist/rewrite-javascript-version.txt +0 -1
package/dist/rpc/server.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/java/s.js~
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const VISITOR_FILE = path.join(__dirname, "visitor.ts");
|
|
5
|
+
|
|
6
|
+
function addMiddleArgToVisitContainer(content) {
|
|
7
|
+
const lines = content.split("\n");
|
|
8
|
+
const updatedLines = [];
|
|
9
|
+
|
|
10
|
+
let currentMethod = null;
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13
|
+
let line = lines[i];
|
|
14
|
+
|
|
15
|
+
const methodMatch = line.match(/^\s*(?:public\s+|private\s+|protected\s+)?(?:async\s+)?(\w+)\s*\(.*\)\s*{/);
|
|
16
|
+
if (methodMatch) {
|
|
17
|
+
currentMethod = methodMatch[1];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const callMatch = line.match(/(\bvisitContainer\s*\()\s*([^,]+)\s*,\s*([^)\n]+)\)/);
|
|
21
|
+
if (callMatch) {
|
|
22
|
+
// Derive context from variable name or some keyword around
|
|
23
|
+
const arg1 = callMatch[2].trim();
|
|
24
|
+
let context = "UNKNOWN";
|
|
25
|
+
if (/case/i.test(line)) context = "CASE_LABEL";
|
|
26
|
+
else if (/block/i.test(arg1)) context = "BLOCK";
|
|
27
|
+
else if (/param/i.test(arg1)) context = "PARAM";
|
|
28
|
+
else if (/arg/i.test(arg1)) context = "ARGUMENT";
|
|
29
|
+
else context = arg1.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
30
|
+
|
|
31
|
+
const locationString = `"${currentMethod ? currentMethod.toUpperCase() + "_" + context : context}"`;
|
|
32
|
+
line = line.replace(callMatch[0], `${callMatch[1]}${callMatch[2]}, ${locationString}, ${callMatch[3]})`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
updatedLines.push(line);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return updatedLines.join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function main() {
|
|
42
|
+
const original = fs.readFileSync(VISITOR_FILE, "utf8");
|
|
43
|
+
const updated = addMiddleArgToVisitContainer(original);
|
|
44
|
+
fs.writeFileSync(VISITOR_FILE, updated, "utf8");
|
|
45
|
+
console.log("✅ visitContainer calls amended.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const VISITOR_FILE = path.join(__dirname, "visitor.ts");
|
|
5
|
+
|
|
6
|
+
function addMiddleArgToVisitContainer(content) {
|
|
7
|
+
const lines = content.split("\n");
|
|
8
|
+
const updatedLines = [];
|
|
9
|
+
|
|
10
|
+
let currentMethod = null;
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13
|
+
let line = lines[i];
|
|
14
|
+
|
|
15
|
+
const methodMatch = line.match(/^\s*(?:public\s+|private\s+|protected\s+)?(?:async\s+)?(\w+)\s*\(.*\)\s*{/);
|
|
16
|
+
if (methodMatch) {
|
|
17
|
+
currentMethod = methodMatch[1];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const callMatch = line.match(/(\bvisitContainer\s*\()\s*([^,]+)\s*,\s*([^)\n]+)\)/);
|
|
21
|
+
if (callMatch) {
|
|
22
|
+
// Derive context from variable name or some keyword around
|
|
23
|
+
const arg1 = callMatch[2].trim();
|
|
24
|
+
let context = "UNKNOWN";
|
|
25
|
+
if (/case/i.test(line)) context = "CASE_LABEL";
|
|
26
|
+
else if (/block/i.test(arg1)) context = "BLOCK";
|
|
27
|
+
else if (/param/i.test(arg1)) context = "PARAM";
|
|
28
|
+
else if (/arg/i.test(arg1)) context = "ARGUMENT";
|
|
29
|
+
else context = arg1.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
30
|
+
|
|
31
|
+
const locationString = `"${currentMethod ? currentMethod.toUpperCase() + "_" + context : context}"`;
|
|
32
|
+
line = line.replace(callMatch[0], `${callMatch[1]}${callMatch[2]}, ${locationString}, ${callMatch[3]})`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
updatedLines.push(line);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return updatedLines.join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function main() {
|
|
42
|
+
const original = fs.readFileSync(VISITOR_FILE, "utf8");
|
|
43
|
+
const updated = addMiddleArgToVisitContainer(original);
|
|
44
|
+
fs.writeFileSync(VISITOR_FILE, updated, "utf8");
|
|
45
|
+
console.log("✅ visitContainer calls amended.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const VISITOR_FILE = path.join(__dirname, "visitor.ts");
|
|
5
|
+
|
|
6
|
+
function toUpperUnderscore(name) {
|
|
7
|
+
return name
|
|
8
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
9
|
+
.replace(/[\W]+/g, "_")
|
|
10
|
+
.replace(/^_+|_+$/g, "")
|
|
11
|
+
.toUpperCase();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function extractPropertyFromLine(line) {
|
|
15
|
+
// Case 1: match property from lambda: el => el.property
|
|
16
|
+
let match = line.match(/el\s*=>\s*el\.([a-zA-Z0-9_]+)/);
|
|
17
|
+
if (match) return match[1];
|
|
18
|
+
|
|
19
|
+
// Case 2: match assignment target like: draft.valueType = await ...
|
|
20
|
+
match = line.match(/\b([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\s*=.*\s*await\b/);
|
|
21
|
+
if (match) return match[2];
|
|
22
|
+
|
|
23
|
+
return "UNKNOWN";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function addMiddleArgToVisitContainer(content) {
|
|
27
|
+
const lines = content.split("\n");
|
|
28
|
+
const updatedLines = [];
|
|
29
|
+
|
|
30
|
+
let currentMethod = null;
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < lines.length; i++) {
|
|
33
|
+
let line = lines[i];
|
|
34
|
+
|
|
35
|
+
const methodMatch = line.match(/^ +(?:public|protected|private)?\s*(?:override\s+)?(?:async\s+)?(visit[A-Z][A-Za-z0-9_]*)\s*\(/);
|
|
36
|
+
if (methodMatch) {
|
|
37
|
+
const fullMethod = methodMatch[1]; // e.g. visitExpressionWithTypeArguments
|
|
38
|
+
// Strip the "visit" prefix and convert to UPPER_UNDERSCORE
|
|
39
|
+
currentMethod = fullMethod.startsWith("visit") ? fullMethod.slice(5) : fullMethod;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const visitCallMatch = line.match(/(\bvisitContainer\s*\()\s*([^,]+)\s*,\s*([^)\n]+)\)/);
|
|
43
|
+
if (visitCallMatch) {
|
|
44
|
+
const objectArg = visitCallMatch[2].trim();
|
|
45
|
+
const restArg = visitCallMatch[3].trim();
|
|
46
|
+
|
|
47
|
+
const property = extractPropertyFromLine(line);
|
|
48
|
+
const method = currentMethod || "UNKNOWN";
|
|
49
|
+
|
|
50
|
+
const locationValue = `"${toUpperUnderscore(method)}_${toUpperUnderscore(property)}"`;
|
|
51
|
+
|
|
52
|
+
line = line.replace(visitCallMatch[0], `${visitCallMatch[1]}${objectArg}, ${locationValue}, ${restArg})`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
updatedLines.push(line);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return updatedLines.join("\n");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function main() {
|
|
62
|
+
const original = fs.readFileSync(VISITOR_FILE, "utf8");
|
|
63
|
+
const updated = addMiddleArgToVisitContainer(original);
|
|
64
|
+
fs.writeFileSync(VISITOR_FILE, updated, "utf8");
|
|
65
|
+
console.log("✅ visitContainer calls amended with location strings.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main();
|
package/src/rpc/server.ts
CHANGED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
8.81.2
|