miniread 1.8.0 → 1.10.0
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/scripts/snapshot/run-snapshot-cli.js +58 -69
- package/dist/transforms/rename-loop-index-variables-v2/get-loop-counter-name.d.ts +5 -0
- package/dist/transforms/rename-loop-index-variables-v2/get-loop-counter-name.js +123 -0
- package/dist/transforms/rename-loop-index-variables-v2/get-renamed-ancestor-loop-count.d.ts +3 -0
- package/dist/transforms/rename-loop-index-variables-v2/get-renamed-ancestor-loop-count.js +19 -0
- package/dist/transforms/rename-loop-index-variables-v2/get-target-index-base-name.d.ts +1 -0
- package/dist/transforms/rename-loop-index-variables-v2/get-target-index-base-name.js +6 -0
- package/dist/transforms/rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.d.ts +2 -0
- package/dist/transforms/rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.js +47 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-loop-counter-name.d.ts +5 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-loop-counter-name.js +121 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-renamed-ancestor-loop-count.d.ts +3 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-renamed-ancestor-loop-count.js +19 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-target-index-base-name.d.ts +1 -0
- package/dist/transforms/rename-loop-index-variables-v3/get-target-index-base-name.js +6 -0
- package/dist/transforms/rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.d.ts +2 -0
- package/dist/transforms/rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.js +47 -0
- package/dist/transforms/rename-replace-child-parameters/ast-node-predicates.d.ts +3 -0
- package/dist/transforms/rename-replace-child-parameters/ast-node-predicates.js +12 -0
- package/dist/transforms/rename-replace-child-parameters/collect-replace-child-parameter-renames.d.ts +3 -0
- package/dist/transforms/rename-replace-child-parameters/collect-replace-child-parameter-renames.js +39 -0
- package/dist/transforms/rename-replace-child-parameters/constants.d.ts +3 -0
- package/dist/transforms/rename-replace-child-parameters/constants.js +3 -0
- package/dist/transforms/rename-replace-child-parameters/get-single-return-identifier-name.d.ts +2 -0
- package/dist/transforms/rename-replace-child-parameters/get-single-return-identifier-name.js +23 -0
- package/dist/transforms/rename-replace-child-parameters/get-two-identifier-parameters.d.ts +6 -0
- package/dist/transforms/rename-replace-child-parameters/get-two-identifier-parameters.js +13 -0
- package/dist/transforms/rename-replace-child-parameters/has-replace-child-forwarding-call.d.ts +2 -0
- package/dist/transforms/rename-replace-child-parameters/has-replace-child-forwarding-call.js +57 -0
- package/dist/transforms/rename-replace-child-parameters/is-already-child-parameter-name.d.ts +1 -0
- package/dist/transforms/rename-replace-child-parameters/is-already-child-parameter-name.js +8 -0
- package/dist/transforms/rename-replace-child-parameters/is-replace-child-named-function.d.ts +2 -0
- package/dist/transforms/rename-replace-child-parameters/is-replace-child-named-function.js +43 -0
- package/dist/transforms/rename-replace-child-parameters/rename-replace-child-parameters-transform.d.ts +2 -0
- package/dist/transforms/rename-replace-child-parameters/rename-replace-child-parameters-transform.js +44 -0
- package/dist/transforms/rename-replace-child-parameters/replace-child-types.d.ts +3 -0
- package/dist/transforms/rename-replace-child-parameters/replace-child-types.js +1 -0
- package/dist/transforms/transform-registry.js +6 -0
- package/package.json +1 -1
- package/transform-manifest.json +34 -2
|
@@ -70,24 +70,11 @@ export const runSnapshotCli = async (argv) => {
|
|
|
70
70
|
}
|
|
71
71
|
const expectedPath = path.join(testCaseDirectory, `${transform}-expected.js`);
|
|
72
72
|
const actualPath = path.join(testCaseDirectory, `${transform}.js`);
|
|
73
|
-
// Run the transform and format
|
|
74
|
-
let actualOutput;
|
|
75
|
-
try {
|
|
76
|
-
const rawOutput = await runTransform(basePath, transform);
|
|
77
|
-
actualOutput = await formatCode(rawOutput);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
81
|
-
console.error(`Error running transform: ${message}`);
|
|
82
|
-
return 1;
|
|
83
|
-
}
|
|
84
73
|
if (expected) {
|
|
85
74
|
// Expected-file workflow
|
|
86
75
|
// Step 1: Check if expected file exists, create from base.js if not
|
|
87
|
-
let expectedExists = false;
|
|
88
76
|
try {
|
|
89
77
|
await fs.access(expectedPath);
|
|
90
|
-
expectedExists = true;
|
|
91
78
|
}
|
|
92
79
|
catch {
|
|
93
80
|
// Expected file doesn't exist, create it from base.js
|
|
@@ -96,67 +83,69 @@ export const runSnapshotCli = async (argv) => {
|
|
|
96
83
|
await fs.writeFile(expectedPath, formattedBase);
|
|
97
84
|
console.log(`Created: test-cases/${testcase}/${transform}-expected.js`);
|
|
98
85
|
console.log("Edit this file to match your expected output, then re-run.");
|
|
99
|
-
}
|
|
100
|
-
// Step 2: Write actual output
|
|
101
|
-
await fs.writeFile(actualPath, actualOutput);
|
|
102
|
-
console.log(`Created: test-cases/${testcase}/${transform}.js`);
|
|
103
|
-
if (!expectedExists) {
|
|
104
|
-
// First run - just created expected file, user needs to edit it
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
// Step 3: Compare expected vs actual
|
|
108
|
-
const expectedContent = await fs.readFile(expectedPath, "utf8");
|
|
109
|
-
if (expectedContent === actualOutput) {
|
|
110
|
-
// Success! Delete expected file
|
|
111
|
-
await fs.unlink(expectedPath);
|
|
112
|
-
console.log(`\nSuccess: Output matches expected.`);
|
|
113
|
-
console.log(`Deleted: test-cases/${testcase}/${transform}-expected.js`);
|
|
114
|
-
console.log(`\nSnapshot ready: test-cases/${testcase}/${transform}.js`);
|
|
115
86
|
return 0;
|
|
116
87
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
88
|
+
}
|
|
89
|
+
// Common path: Run the transform, format, and write actual output
|
|
90
|
+
let actualOutput;
|
|
91
|
+
try {
|
|
92
|
+
const rawOutput = await runTransform(basePath, transform);
|
|
93
|
+
actualOutput = await formatCode(rawOutput);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
+
console.error(`Error running transform: ${message}`);
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
await fs.writeFile(actualPath, actualOutput);
|
|
101
|
+
console.log(`Created: test-cases/${testcase}/${transform}.js`);
|
|
102
|
+
if (!expected) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
// Step 3: Compare expected vs actual
|
|
106
|
+
const expectedContent = await fs.readFile(expectedPath, "utf8");
|
|
107
|
+
if (expectedContent === actualOutput) {
|
|
108
|
+
// Success! Delete expected file
|
|
109
|
+
await fs.unlink(expectedPath);
|
|
110
|
+
console.log(`\nSuccess: Output matches expected.`);
|
|
111
|
+
console.log(`Deleted: test-cases/${testcase}/${transform}-expected.js`);
|
|
112
|
+
console.log(`\nSnapshot ready: test-cases/${testcase}/${transform}.js`);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
// Diff - show the difference
|
|
116
|
+
console.log(`\nDiff: expected vs actual`);
|
|
117
|
+
console.log("---");
|
|
118
|
+
// Simple line-by-line diff output
|
|
119
|
+
const expectedLines = expectedContent.split("\n");
|
|
120
|
+
const actualLines = actualOutput.split("\n");
|
|
121
|
+
const maxLines = Math.max(expectedLines.length, actualLines.length);
|
|
122
|
+
let hasDiff = false;
|
|
123
|
+
for (let lineIndex = 0; lineIndex < maxLines; lineIndex++) {
|
|
124
|
+
const exp = expectedLines[lineIndex];
|
|
125
|
+
const act = actualLines[lineIndex];
|
|
126
|
+
if (exp !== act) {
|
|
127
|
+
hasDiff = true;
|
|
128
|
+
if (exp !== undefined && act === undefined) {
|
|
129
|
+
console.log(`Line ${lineIndex + 1}:`);
|
|
130
|
+
console.log(` - ${exp}`);
|
|
145
131
|
}
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
console.log(
|
|
132
|
+
else if (exp === undefined && act !== undefined) {
|
|
133
|
+
console.log(`Line ${lineIndex + 1}:`);
|
|
134
|
+
console.log(` + ${act}`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.log(`Line ${lineIndex + 1}:`);
|
|
138
|
+
console.log(` - ${exp}`);
|
|
139
|
+
console.log(` + ${act}`);
|
|
149
140
|
}
|
|
150
|
-
console.log("---");
|
|
151
|
-
console.log(`\nExpected file preserved: test-cases/${testcase}/${transform}-expected.js`);
|
|
152
|
-
console.log("Fix the implementation or update the expected file, then re-run.");
|
|
153
|
-
return 1;
|
|
154
141
|
}
|
|
155
142
|
}
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
console.log(`Created: test-cases/${testcase}/${transform}.js`);
|
|
160
|
-
return 0;
|
|
143
|
+
if (!hasDiff) {
|
|
144
|
+
// Shouldn't happen since we already checked equality, but just in case
|
|
145
|
+
console.log("(no visible differences)");
|
|
161
146
|
}
|
|
147
|
+
console.log("---");
|
|
148
|
+
console.log(`\nExpected file preserved: test-cases/${testcase}/${transform}-expected.js`);
|
|
149
|
+
console.log("Fix the implementation or update the expected file, then re-run.");
|
|
150
|
+
return 1;
|
|
162
151
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/traverse";
|
|
2
|
+
import type { ForStatement } from "@babel/types";
|
|
3
|
+
export declare const LOOP_INDEX_BASE_NAME = "index";
|
|
4
|
+
export declare const getStableRenamedIndexLoopCounterName: (path: NodePath<ForStatement>) => string | undefined;
|
|
5
|
+
export declare const getLoopCounterNameIfEligible: (path: NodePath<ForStatement>) => string | undefined;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { isStableRenamed } from "../../core/stable-naming.js";
|
|
2
|
+
export const LOOP_INDEX_BASE_NAME = "index";
|
|
3
|
+
const isEligibleVariableDeclarationKind = (kind) => {
|
|
4
|
+
return kind === "let" || kind === "var";
|
|
5
|
+
};
|
|
6
|
+
const isStableRenamedIndexLoopCounterName = (name) => {
|
|
7
|
+
if (!isStableRenamed(name))
|
|
8
|
+
return false;
|
|
9
|
+
return name.startsWith(`$${LOOP_INDEX_BASE_NAME}`);
|
|
10
|
+
};
|
|
11
|
+
const isLoopCounterDeclarator = (loopCounterName, path) => {
|
|
12
|
+
const test = path.node.test;
|
|
13
|
+
if (!test)
|
|
14
|
+
return false;
|
|
15
|
+
if (test.type !== "BinaryExpression")
|
|
16
|
+
return false;
|
|
17
|
+
if (test.operator !== "<" && test.operator !== "<=")
|
|
18
|
+
return false;
|
|
19
|
+
if (test.left.type !== "Identifier")
|
|
20
|
+
return false;
|
|
21
|
+
if (test.left.name !== loopCounterName)
|
|
22
|
+
return false;
|
|
23
|
+
if (test.right.type !== "MemberExpression")
|
|
24
|
+
return false;
|
|
25
|
+
if (test.right.computed)
|
|
26
|
+
return false;
|
|
27
|
+
if (test.right.property.type !== "Identifier")
|
|
28
|
+
return false;
|
|
29
|
+
if (test.right.property.name !== "length")
|
|
30
|
+
return false;
|
|
31
|
+
const update = path.node.update;
|
|
32
|
+
if (!update)
|
|
33
|
+
return false;
|
|
34
|
+
if (update.type === "UpdateExpression") {
|
|
35
|
+
if (update.operator !== "++")
|
|
36
|
+
return false;
|
|
37
|
+
if (update.argument.type !== "Identifier")
|
|
38
|
+
return false;
|
|
39
|
+
if (update.argument.name !== loopCounterName)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
else if (update.type === "AssignmentExpression") {
|
|
43
|
+
if (update.operator !== "+=")
|
|
44
|
+
return false;
|
|
45
|
+
if (update.left.type !== "Identifier")
|
|
46
|
+
return false;
|
|
47
|
+
if (update.left.name !== loopCounterName)
|
|
48
|
+
return false;
|
|
49
|
+
if (update.right.type !== "NumericLiteral")
|
|
50
|
+
return false;
|
|
51
|
+
if (update.right.value <= 0)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
export const getStableRenamedIndexLoopCounterName = (path) => {
|
|
60
|
+
const init = path.node.init;
|
|
61
|
+
if (!init)
|
|
62
|
+
return;
|
|
63
|
+
if (init.type !== "VariableDeclaration")
|
|
64
|
+
return;
|
|
65
|
+
if (!isEligibleVariableDeclarationKind(init.kind))
|
|
66
|
+
return;
|
|
67
|
+
if (init.declarations.length === 0)
|
|
68
|
+
return;
|
|
69
|
+
let stableName;
|
|
70
|
+
for (const declarator of init.declarations) {
|
|
71
|
+
if (declarator.id.type !== "Identifier")
|
|
72
|
+
continue;
|
|
73
|
+
const loopCounterName = declarator.id.name;
|
|
74
|
+
if (!isStableRenamedIndexLoopCounterName(loopCounterName))
|
|
75
|
+
continue;
|
|
76
|
+
if (!declarator.init)
|
|
77
|
+
continue;
|
|
78
|
+
if (declarator.init.type !== "NumericLiteral")
|
|
79
|
+
continue;
|
|
80
|
+
if (declarator.init.value !== 0)
|
|
81
|
+
continue;
|
|
82
|
+
if (!isLoopCounterDeclarator(loopCounterName, path))
|
|
83
|
+
continue;
|
|
84
|
+
if (stableName !== undefined)
|
|
85
|
+
return;
|
|
86
|
+
stableName = loopCounterName;
|
|
87
|
+
}
|
|
88
|
+
return stableName;
|
|
89
|
+
};
|
|
90
|
+
export const getLoopCounterNameIfEligible = (path) => {
|
|
91
|
+
const init = path.node.init;
|
|
92
|
+
if (!init)
|
|
93
|
+
return;
|
|
94
|
+
if (init.type !== "VariableDeclaration")
|
|
95
|
+
return;
|
|
96
|
+
if (!isEligibleVariableDeclarationKind(init.kind))
|
|
97
|
+
return;
|
|
98
|
+
if (init.declarations.length === 0)
|
|
99
|
+
return;
|
|
100
|
+
if (init.kind === "let" && init.declarations.length < 2)
|
|
101
|
+
return;
|
|
102
|
+
const eligibleNames = [];
|
|
103
|
+
for (const declarator of init.declarations) {
|
|
104
|
+
if (declarator.id.type !== "Identifier")
|
|
105
|
+
continue;
|
|
106
|
+
if (!declarator.init)
|
|
107
|
+
continue;
|
|
108
|
+
if (declarator.init.type !== "NumericLiteral")
|
|
109
|
+
continue;
|
|
110
|
+
if (declarator.init.value !== 0)
|
|
111
|
+
continue;
|
|
112
|
+
const loopCounterName = declarator.id.name;
|
|
113
|
+
if (!isLoopCounterDeclarator(loopCounterName, path))
|
|
114
|
+
continue;
|
|
115
|
+
eligibleNames.push(loopCounterName);
|
|
116
|
+
if (eligibleNames.length > 1)
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const name0 = eligibleNames[0];
|
|
120
|
+
if (!name0)
|
|
121
|
+
return;
|
|
122
|
+
return name0;
|
|
123
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getStableRenamedIndexLoopCounterName } from "./get-loop-counter-name.js";
|
|
2
|
+
export const getRenamedAncestorLoopCount = (path, renamedLoops) => {
|
|
3
|
+
let count = 0;
|
|
4
|
+
for (const ancestor of path.getAncestry()) {
|
|
5
|
+
if (ancestor === path)
|
|
6
|
+
continue;
|
|
7
|
+
if (!ancestor.isForStatement())
|
|
8
|
+
continue;
|
|
9
|
+
if (renamedLoops.has(ancestor.node)) {
|
|
10
|
+
count++;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const stableName = getStableRenamedIndexLoopCounterName(ancestor);
|
|
14
|
+
if (!stableName)
|
|
15
|
+
continue;
|
|
16
|
+
count++;
|
|
17
|
+
}
|
|
18
|
+
return count;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getTargetIndexBaseName: (renamedAncestorLoopCount: number) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LOOP_INDEX_BASE_NAME } from "./get-loop-counter-name.js";
|
|
2
|
+
export const getTargetIndexBaseName = (renamedAncestorLoopCount) => {
|
|
3
|
+
if (renamedAncestorLoopCount === 0)
|
|
4
|
+
return LOOP_INDEX_BASE_NAME;
|
|
5
|
+
return `${LOOP_INDEX_BASE_NAME}${renamedAncestorLoopCount + 1}`;
|
|
6
|
+
};
|
package/dist/transforms/rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { isStableRenamed, RenameGroup } from "../../core/stable-naming.js";
|
|
3
|
+
import { getFilesToProcess, } from "../../core/types.js";
|
|
4
|
+
import { getLoopCounterNameIfEligible } from "./get-loop-counter-name.js";
|
|
5
|
+
import { getRenamedAncestorLoopCount } from "./get-renamed-ancestor-loop-count.js";
|
|
6
|
+
import { getTargetIndexBaseName } from "./get-target-index-base-name.js";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
9
|
+
const traverse = require("@babel/traverse").default;
|
|
10
|
+
export const renameLoopIndexVariablesV2Transform = {
|
|
11
|
+
id: "rename-loop-index-variables-v2",
|
|
12
|
+
description: "Renames numeric for-loop counters in `for (var ...)` (single or multi-declarator) and `for (let ...)` (multi-declarator) to $index/$index2/...",
|
|
13
|
+
scope: "file",
|
|
14
|
+
parallelizable: true,
|
|
15
|
+
transform(context) {
|
|
16
|
+
let nodesVisited = 0;
|
|
17
|
+
let transformationsApplied = 0;
|
|
18
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
19
|
+
const group = new RenameGroup();
|
|
20
|
+
const eligibleLoops = new WeakMap();
|
|
21
|
+
traverse(fileInfo.ast, {
|
|
22
|
+
ForStatement(path) {
|
|
23
|
+
nodesVisited++;
|
|
24
|
+
const loopCounterName = getLoopCounterNameIfEligible(path);
|
|
25
|
+
if (!loopCounterName)
|
|
26
|
+
return;
|
|
27
|
+
// Skip already-stable names
|
|
28
|
+
if (isStableRenamed(loopCounterName))
|
|
29
|
+
return;
|
|
30
|
+
const renamedAncestorLoopCount = getRenamedAncestorLoopCount(path, eligibleLoops);
|
|
31
|
+
const baseName = getTargetIndexBaseName(renamedAncestorLoopCount);
|
|
32
|
+
eligibleLoops.set(path.node, baseName);
|
|
33
|
+
group.add({
|
|
34
|
+
scope: path.scope,
|
|
35
|
+
currentName: loopCounterName,
|
|
36
|
+
baseName,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
transformationsApplied += group.apply();
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve({
|
|
43
|
+
nodesVisited,
|
|
44
|
+
transformationsApplied,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/traverse";
|
|
2
|
+
import type { ForStatement } from "@babel/types";
|
|
3
|
+
export declare const LOOP_INDEX_BASE_NAME = "index";
|
|
4
|
+
export declare const getStableRenamedIndexLoopCounterName: (path: NodePath<ForStatement>) => string | undefined;
|
|
5
|
+
export declare const getLoopCounterNameIfEligible: (path: NodePath<ForStatement>) => string | undefined;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { isStableRenamed } from "../../core/stable-naming.js";
|
|
2
|
+
export const LOOP_INDEX_BASE_NAME = "index";
|
|
3
|
+
const isEligibleVariableDeclarationKind = (kind) => {
|
|
4
|
+
return kind === "let" || kind === "var";
|
|
5
|
+
};
|
|
6
|
+
const isStableRenamedIndexLoopCounterName = (name) => {
|
|
7
|
+
if (!isStableRenamed(name))
|
|
8
|
+
return false;
|
|
9
|
+
return name.startsWith(`$${LOOP_INDEX_BASE_NAME}`);
|
|
10
|
+
};
|
|
11
|
+
const isLoopCounterDeclarator = (loopCounterName, path) => {
|
|
12
|
+
const test = path.node.test;
|
|
13
|
+
if (!test)
|
|
14
|
+
return false;
|
|
15
|
+
if (test.type !== "BinaryExpression")
|
|
16
|
+
return false;
|
|
17
|
+
if (test.operator !== "<" && test.operator !== "<=")
|
|
18
|
+
return false;
|
|
19
|
+
if (test.left.type !== "Identifier")
|
|
20
|
+
return false;
|
|
21
|
+
if (test.left.name !== loopCounterName)
|
|
22
|
+
return false;
|
|
23
|
+
if (test.right.type !== "MemberExpression")
|
|
24
|
+
return false;
|
|
25
|
+
if (test.right.computed)
|
|
26
|
+
return false;
|
|
27
|
+
if (test.right.property.type !== "Identifier")
|
|
28
|
+
return false;
|
|
29
|
+
if (test.right.property.name !== "length")
|
|
30
|
+
return false;
|
|
31
|
+
const update = path.node.update;
|
|
32
|
+
if (!update)
|
|
33
|
+
return false;
|
|
34
|
+
if (update.type === "UpdateExpression") {
|
|
35
|
+
if (update.operator !== "++")
|
|
36
|
+
return false;
|
|
37
|
+
if (update.argument.type !== "Identifier")
|
|
38
|
+
return false;
|
|
39
|
+
if (update.argument.name !== loopCounterName)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
else if (update.type === "AssignmentExpression") {
|
|
43
|
+
if (update.operator !== "+=")
|
|
44
|
+
return false;
|
|
45
|
+
if (update.left.type !== "Identifier")
|
|
46
|
+
return false;
|
|
47
|
+
if (update.left.name !== loopCounterName)
|
|
48
|
+
return false;
|
|
49
|
+
if (update.right.type !== "NumericLiteral")
|
|
50
|
+
return false;
|
|
51
|
+
if (update.right.value <= 0)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
export const getStableRenamedIndexLoopCounterName = (path) => {
|
|
60
|
+
const init = path.node.init;
|
|
61
|
+
if (!init)
|
|
62
|
+
return;
|
|
63
|
+
if (init.type !== "VariableDeclaration")
|
|
64
|
+
return;
|
|
65
|
+
if (!isEligibleVariableDeclarationKind(init.kind))
|
|
66
|
+
return;
|
|
67
|
+
if (init.declarations.length === 0)
|
|
68
|
+
return;
|
|
69
|
+
let stableName;
|
|
70
|
+
for (const declarator of init.declarations) {
|
|
71
|
+
if (declarator.id.type !== "Identifier")
|
|
72
|
+
continue;
|
|
73
|
+
const loopCounterName = declarator.id.name;
|
|
74
|
+
if (!isStableRenamedIndexLoopCounterName(loopCounterName))
|
|
75
|
+
continue;
|
|
76
|
+
if (!declarator.init)
|
|
77
|
+
continue;
|
|
78
|
+
if (declarator.init.type !== "NumericLiteral")
|
|
79
|
+
continue;
|
|
80
|
+
if (declarator.init.value !== 0)
|
|
81
|
+
continue;
|
|
82
|
+
if (!isLoopCounterDeclarator(loopCounterName, path))
|
|
83
|
+
continue;
|
|
84
|
+
if (stableName !== undefined)
|
|
85
|
+
return;
|
|
86
|
+
stableName = loopCounterName;
|
|
87
|
+
}
|
|
88
|
+
return stableName;
|
|
89
|
+
};
|
|
90
|
+
export const getLoopCounterNameIfEligible = (path) => {
|
|
91
|
+
const init = path.node.init;
|
|
92
|
+
if (!init)
|
|
93
|
+
return;
|
|
94
|
+
if (init.type !== "VariableDeclaration")
|
|
95
|
+
return;
|
|
96
|
+
if (!isEligibleVariableDeclarationKind(init.kind))
|
|
97
|
+
return;
|
|
98
|
+
if (init.declarations.length === 0)
|
|
99
|
+
return;
|
|
100
|
+
const eligibleNames = [];
|
|
101
|
+
for (const declarator of init.declarations) {
|
|
102
|
+
if (declarator.id.type !== "Identifier")
|
|
103
|
+
continue;
|
|
104
|
+
if (!declarator.init)
|
|
105
|
+
continue;
|
|
106
|
+
if (declarator.init.type !== "NumericLiteral")
|
|
107
|
+
continue;
|
|
108
|
+
if (declarator.init.value !== 0)
|
|
109
|
+
continue;
|
|
110
|
+
const loopCounterName = declarator.id.name;
|
|
111
|
+
if (!isLoopCounterDeclarator(loopCounterName, path))
|
|
112
|
+
continue;
|
|
113
|
+
eligibleNames.push(loopCounterName);
|
|
114
|
+
if (eligibleNames.length > 1)
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const name0 = eligibleNames[0];
|
|
118
|
+
if (!name0)
|
|
119
|
+
return;
|
|
120
|
+
return name0;
|
|
121
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getStableRenamedIndexLoopCounterName } from "./get-loop-counter-name.js";
|
|
2
|
+
export const getRenamedAncestorLoopCount = (path, renamedLoops) => {
|
|
3
|
+
let count = 0;
|
|
4
|
+
for (const ancestor of path.getAncestry()) {
|
|
5
|
+
if (ancestor === path)
|
|
6
|
+
continue;
|
|
7
|
+
if (!ancestor.isForStatement())
|
|
8
|
+
continue;
|
|
9
|
+
if (renamedLoops.has(ancestor.node)) {
|
|
10
|
+
count++;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const stableName = getStableRenamedIndexLoopCounterName(ancestor);
|
|
14
|
+
if (!stableName)
|
|
15
|
+
continue;
|
|
16
|
+
count++;
|
|
17
|
+
}
|
|
18
|
+
return count;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getTargetIndexBaseName: (renamedAncestorLoopCount: number) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LOOP_INDEX_BASE_NAME } from "./get-loop-counter-name.js";
|
|
2
|
+
export const getTargetIndexBaseName = (renamedAncestorLoopCount) => {
|
|
3
|
+
if (renamedAncestorLoopCount === 0)
|
|
4
|
+
return LOOP_INDEX_BASE_NAME;
|
|
5
|
+
return `${LOOP_INDEX_BASE_NAME}${renamedAncestorLoopCount + 1}`;
|
|
6
|
+
};
|
package/dist/transforms/rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { isStableRenamed, RenameGroup } from "../../core/stable-naming.js";
|
|
3
|
+
import { getFilesToProcess, } from "../../core/types.js";
|
|
4
|
+
import { getLoopCounterNameIfEligible } from "./get-loop-counter-name.js";
|
|
5
|
+
import { getRenamedAncestorLoopCount } from "./get-renamed-ancestor-loop-count.js";
|
|
6
|
+
import { getTargetIndexBaseName } from "./get-target-index-base-name.js";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
9
|
+
const traverse = require("@babel/traverse").default;
|
|
10
|
+
export const renameLoopIndexVariablesV3Transform = {
|
|
11
|
+
id: "rename-loop-index-variables-v3",
|
|
12
|
+
description: "Renames numeric for-loop counters (single or multi-declarator `for (var/let ...)`) to $index/$index2/... based on nesting depth",
|
|
13
|
+
scope: "file",
|
|
14
|
+
parallelizable: true,
|
|
15
|
+
transform(context) {
|
|
16
|
+
let nodesVisited = 0;
|
|
17
|
+
let transformationsApplied = 0;
|
|
18
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
19
|
+
const group = new RenameGroup();
|
|
20
|
+
const eligibleLoops = new WeakMap();
|
|
21
|
+
traverse(fileInfo.ast, {
|
|
22
|
+
ForStatement(path) {
|
|
23
|
+
nodesVisited++;
|
|
24
|
+
const loopCounterName = getLoopCounterNameIfEligible(path);
|
|
25
|
+
if (!loopCounterName)
|
|
26
|
+
return;
|
|
27
|
+
// Skip already-stable names
|
|
28
|
+
if (isStableRenamed(loopCounterName))
|
|
29
|
+
return;
|
|
30
|
+
const renamedAncestorLoopCount = getRenamedAncestorLoopCount(path, eligibleLoops);
|
|
31
|
+
const baseName = getTargetIndexBaseName(renamedAncestorLoopCount);
|
|
32
|
+
eligibleLoops.set(path.node, baseName);
|
|
33
|
+
group.add({
|
|
34
|
+
scope: path.scope,
|
|
35
|
+
currentName: loopCounterName,
|
|
36
|
+
baseName,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
transformationsApplied += group.apply();
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve({
|
|
43
|
+
nodesVisited,
|
|
44
|
+
transformationsApplied,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const isIdentifierNamed = (node, name) => {
|
|
2
|
+
return (typeof node === "object" &&
|
|
3
|
+
node !== null &&
|
|
4
|
+
node.type === "Identifier" &&
|
|
5
|
+
node.name === name);
|
|
6
|
+
};
|
|
7
|
+
export const isStringLiteralValue = (node, value) => {
|
|
8
|
+
return (typeof node === "object" &&
|
|
9
|
+
node !== null &&
|
|
10
|
+
node.type === "StringLiteral" &&
|
|
11
|
+
node.value === value);
|
|
12
|
+
};
|
package/dist/transforms/rename-replace-child-parameters/collect-replace-child-parameter-renames.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isStableRenamed } from "../../core/stable-naming.js";
|
|
2
|
+
import { BASE_NEW_CHILD, BASE_OLD_CHILD } from "./constants.js";
|
|
3
|
+
import { getSingleReturnIdentifierName } from "./get-single-return-identifier-name.js";
|
|
4
|
+
import { getTwoIdentifierParameters } from "./get-two-identifier-parameters.js";
|
|
5
|
+
import { hasReplaceChildForwardingCall } from "./has-replace-child-forwarding-call.js";
|
|
6
|
+
import { isAlreadyChildParameterName } from "./is-already-child-parameter-name.js";
|
|
7
|
+
import { isReplaceChildNamedFunction } from "./is-replace-child-named-function.js";
|
|
8
|
+
export const collectReplaceChildParameterRenames = (path, group) => {
|
|
9
|
+
if (!isReplaceChildNamedFunction(path))
|
|
10
|
+
return;
|
|
11
|
+
if (path.node.body.type !== "BlockStatement")
|
|
12
|
+
return;
|
|
13
|
+
const parameters = getTwoIdentifierParameters(path);
|
|
14
|
+
if (!parameters)
|
|
15
|
+
return;
|
|
16
|
+
const returnIdentifierName = getSingleReturnIdentifierName(path);
|
|
17
|
+
if (returnIdentifierName !== parameters.parameter1.name)
|
|
18
|
+
return;
|
|
19
|
+
if (!hasReplaceChildForwardingCall(path, parameters.parameter0.name, parameters.parameter1.name))
|
|
20
|
+
return;
|
|
21
|
+
const parameter0Name = parameters.parameter0.name;
|
|
22
|
+
if (!isStableRenamed(parameter0Name) &&
|
|
23
|
+
!isAlreadyChildParameterName(parameter0Name, BASE_NEW_CHILD)) {
|
|
24
|
+
group.add({
|
|
25
|
+
scope: path.scope,
|
|
26
|
+
currentName: parameter0Name,
|
|
27
|
+
baseName: BASE_NEW_CHILD,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const parameter1Name = parameters.parameter1.name;
|
|
31
|
+
if (!isStableRenamed(parameter1Name) &&
|
|
32
|
+
!isAlreadyChildParameterName(parameter1Name, BASE_OLD_CHILD)) {
|
|
33
|
+
group.add({
|
|
34
|
+
scope: path.scope,
|
|
35
|
+
currentName: parameter1Name,
|
|
36
|
+
baseName: BASE_OLD_CHILD,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const getSingleReturnIdentifierName = (path) => {
|
|
2
|
+
let returnCount = 0;
|
|
3
|
+
let identifierName;
|
|
4
|
+
const rootNode = path.node;
|
|
5
|
+
path.traverse({
|
|
6
|
+
Function(innerPath) {
|
|
7
|
+
if (innerPath.node !== rootNode)
|
|
8
|
+
innerPath.skip();
|
|
9
|
+
},
|
|
10
|
+
ReturnStatement(returnPath) {
|
|
11
|
+
returnCount++;
|
|
12
|
+
const argument = returnPath.node.argument;
|
|
13
|
+
if (argument?.type !== "Identifier") {
|
|
14
|
+
identifierName = undefined;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
identifierName = argument.name;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
if (returnCount !== 1)
|
|
21
|
+
return;
|
|
22
|
+
return identifierName;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Identifier } from "@babel/types";
|
|
2
|
+
import type { ReplaceChildFunctionPath } from "./replace-child-types.js";
|
|
3
|
+
export declare const getTwoIdentifierParameters: (path: ReplaceChildFunctionPath) => {
|
|
4
|
+
parameter0: Identifier;
|
|
5
|
+
parameter1: Identifier;
|
|
6
|
+
} | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getTwoIdentifierParameters = (path) => {
|
|
2
|
+
if (path.node.params.length !== 2)
|
|
3
|
+
return;
|
|
4
|
+
const parameter0 = path.node.params[0];
|
|
5
|
+
const parameter1 = path.node.params[1];
|
|
6
|
+
if (parameter0?.type !== "Identifier")
|
|
7
|
+
return;
|
|
8
|
+
if (parameter1?.type !== "Identifier")
|
|
9
|
+
return;
|
|
10
|
+
if (parameter0.name === parameter1.name)
|
|
11
|
+
return;
|
|
12
|
+
return { parameter0, parameter1 };
|
|
13
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isIdentifierNamed } from "./ast-node-predicates.js";
|
|
2
|
+
import { REPLACE_CHILD_NAME } from "./constants.js";
|
|
3
|
+
export const hasReplaceChildForwardingCall = (path, parameter0Name, parameter1Name) => {
|
|
4
|
+
let found = false;
|
|
5
|
+
const rootNode = path.node;
|
|
6
|
+
path.traverse({
|
|
7
|
+
Function(innerPath) {
|
|
8
|
+
if (innerPath.node !== rootNode)
|
|
9
|
+
innerPath.skip();
|
|
10
|
+
},
|
|
11
|
+
CallExpression(callPath) {
|
|
12
|
+
if (found)
|
|
13
|
+
return;
|
|
14
|
+
const call = callPath.node;
|
|
15
|
+
const callee = call.callee;
|
|
16
|
+
if (callee.type !== "MemberExpression")
|
|
17
|
+
return;
|
|
18
|
+
if (callee.computed)
|
|
19
|
+
return;
|
|
20
|
+
if (callee.property.type !== "Identifier")
|
|
21
|
+
return;
|
|
22
|
+
// something.replaceChild(parameter0, parameter1)
|
|
23
|
+
if (callee.property.name === REPLACE_CHILD_NAME) {
|
|
24
|
+
const argument0 = call.arguments[0];
|
|
25
|
+
const argument1 = call.arguments[1];
|
|
26
|
+
if (!isIdentifierNamed(argument0, parameter0Name))
|
|
27
|
+
return;
|
|
28
|
+
if (!isIdentifierNamed(argument1, parameter1Name))
|
|
29
|
+
return;
|
|
30
|
+
found = true;
|
|
31
|
+
callPath.stop();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// something.replaceChild.call(this, parameter0, parameter1)
|
|
35
|
+
if (callee.property.name !== "call")
|
|
36
|
+
return;
|
|
37
|
+
const target = callee.object;
|
|
38
|
+
if (target.type !== "MemberExpression")
|
|
39
|
+
return;
|
|
40
|
+
if (target.computed)
|
|
41
|
+
return;
|
|
42
|
+
if (target.property.type !== "Identifier")
|
|
43
|
+
return;
|
|
44
|
+
if (target.property.name !== REPLACE_CHILD_NAME)
|
|
45
|
+
return;
|
|
46
|
+
const argument1 = call.arguments[1];
|
|
47
|
+
const argument2 = call.arguments[2];
|
|
48
|
+
if (!isIdentifierNamed(argument1, parameter0Name))
|
|
49
|
+
return;
|
|
50
|
+
if (!isIdentifierNamed(argument2, parameter1Name))
|
|
51
|
+
return;
|
|
52
|
+
found = true;
|
|
53
|
+
callPath.stop();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return found;
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isAlreadyChildParameterName: (name: string, base: string) => boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isIdentifierNamed, isStringLiteralValue, } from "./ast-node-predicates.js";
|
|
2
|
+
import { REPLACE_CHILD_NAME } from "./constants.js";
|
|
3
|
+
const isReplaceChildKey = (key) => {
|
|
4
|
+
if (isIdentifierNamed(key, REPLACE_CHILD_NAME))
|
|
5
|
+
return true;
|
|
6
|
+
if (isStringLiteralValue(key, REPLACE_CHILD_NAME))
|
|
7
|
+
return true;
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
const isReplaceChildValueDescriptorFunction = (path) => {
|
|
11
|
+
const valueProperty = path.parentPath;
|
|
12
|
+
if (!valueProperty.isObjectProperty())
|
|
13
|
+
return false;
|
|
14
|
+
const valueKey = valueProperty.node.key;
|
|
15
|
+
const isValueKey = isIdentifierNamed(valueKey, "value") ||
|
|
16
|
+
isStringLiteralValue(valueKey, "value");
|
|
17
|
+
if (!isValueKey)
|
|
18
|
+
return false;
|
|
19
|
+
const descriptor = valueProperty.parentPath;
|
|
20
|
+
if (!descriptor.isObjectExpression())
|
|
21
|
+
return false;
|
|
22
|
+
const replaceChildProperty = descriptor.parentPath;
|
|
23
|
+
if (!replaceChildProperty.isObjectProperty())
|
|
24
|
+
return false;
|
|
25
|
+
return isReplaceChildKey(replaceChildProperty.node.key);
|
|
26
|
+
};
|
|
27
|
+
export const isReplaceChildNamedFunction = (path) => {
|
|
28
|
+
if ((path.isFunctionDeclaration() || path.isFunctionExpression()) &&
|
|
29
|
+
isIdentifierNamed(path.node.id, REPLACE_CHILD_NAME)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (path.isObjectMethod() || path.isClassMethod()) {
|
|
33
|
+
return isReplaceChildKey(path.node.key);
|
|
34
|
+
}
|
|
35
|
+
const parent = path.parentPath;
|
|
36
|
+
if (parent.isObjectProperty() && isReplaceChildKey(parent.node.key)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (path.isFunctionExpression() || path.isArrowFunctionExpression()) {
|
|
40
|
+
return isReplaceChildValueDescriptorFunction(path);
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
package/dist/transforms/rename-replace-child-parameters/rename-replace-child-parameters-transform.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { RenameGroup } from "../../core/stable-naming.js";
|
|
3
|
+
import { getFilesToProcess, } from "../../core/types.js";
|
|
4
|
+
import { collectReplaceChildParameterRenames } from "./collect-replace-child-parameter-renames.js";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
7
|
+
const traverse = require("@babel/traverse").default;
|
|
8
|
+
export const renameReplaceChildParametersTransform = {
|
|
9
|
+
id: "rename-replace-child-parameters",
|
|
10
|
+
description: "Renames replaceChild forwarding wrapper parameters to $newChild and $oldChild",
|
|
11
|
+
scope: "file",
|
|
12
|
+
parallelizable: true,
|
|
13
|
+
transform(context) {
|
|
14
|
+
let nodesVisited = 0;
|
|
15
|
+
let transformationsApplied = 0;
|
|
16
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
17
|
+
const group = new RenameGroup();
|
|
18
|
+
traverse(fileInfo.ast, {
|
|
19
|
+
FunctionDeclaration(path) {
|
|
20
|
+
nodesVisited++;
|
|
21
|
+
collectReplaceChildParameterRenames(path, group);
|
|
22
|
+
},
|
|
23
|
+
FunctionExpression(path) {
|
|
24
|
+
nodesVisited++;
|
|
25
|
+
collectReplaceChildParameterRenames(path, group);
|
|
26
|
+
},
|
|
27
|
+
ArrowFunctionExpression(path) {
|
|
28
|
+
nodesVisited++;
|
|
29
|
+
collectReplaceChildParameterRenames(path, group);
|
|
30
|
+
},
|
|
31
|
+
ObjectMethod(path) {
|
|
32
|
+
nodesVisited++;
|
|
33
|
+
collectReplaceChildParameterRenames(path, group);
|
|
34
|
+
},
|
|
35
|
+
ClassMethod(path) {
|
|
36
|
+
nodesVisited++;
|
|
37
|
+
collectReplaceChildParameterRenames(path, group);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
transformationsApplied += group.apply();
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/traverse";
|
|
2
|
+
import type { ArrowFunctionExpression, ClassMethod, FunctionDeclaration, FunctionExpression, ObjectMethod } from "@babel/types";
|
|
3
|
+
export type ReplaceChildFunctionPath = NodePath<FunctionDeclaration> | NodePath<FunctionExpression> | NodePath<ArrowFunctionExpression> | NodePath<ObjectMethod> | NodePath<ClassMethod>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,7 +6,10 @@ import { renameCatchParametersTransform } from "./rename-catch-parameters/rename
|
|
|
6
6
|
import { renameDestructuredAliasesTransform } from "./rename-destructured-aliases/rename-destructured-aliases-transform.js";
|
|
7
7
|
import { renameEventParametersTransform } from "./rename-event-parameters/rename-event-parameters-transform.js";
|
|
8
8
|
import { renameLoopIndexVariablesTransform } from "./rename-loop-index-variables/rename-loop-index-variables-transform.js";
|
|
9
|
+
import { renameLoopIndexVariablesV2Transform } from "./rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.js";
|
|
10
|
+
import { renameLoopIndexVariablesV3Transform } from "./rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.js";
|
|
9
11
|
import { renamePromiseExecutorParametersTransform } from "./rename-promise-executor-parameters/rename-promise-executor-parameters-transform.js";
|
|
12
|
+
import { renameReplaceChildParametersTransform } from "./rename-replace-child-parameters/rename-replace-child-parameters-transform.js";
|
|
10
13
|
import { renameTimeoutIdsTransform } from "./rename-timeout-ids/rename-timeout-ids-transform.js";
|
|
11
14
|
import { renameUseReferenceGuardsTransform } from "./rename-use-reference-guards/rename-use-reference-guards-transform.js";
|
|
12
15
|
import { renameUseReferenceGuardsV2Transform } from "./rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
@@ -20,7 +23,10 @@ export const transformRegistry = {
|
|
|
20
23
|
[renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
|
|
21
24
|
[renameEventParametersTransform.id]: renameEventParametersTransform,
|
|
22
25
|
[renameLoopIndexVariablesTransform.id]: renameLoopIndexVariablesTransform,
|
|
26
|
+
[renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
|
|
27
|
+
[renameLoopIndexVariablesV3Transform.id]: renameLoopIndexVariablesV3Transform,
|
|
23
28
|
[renamePromiseExecutorParametersTransform.id]: renamePromiseExecutorParametersTransform,
|
|
29
|
+
[renameReplaceChildParametersTransform.id]: renameReplaceChildParametersTransform,
|
|
24
30
|
[renameTimeoutIdsTransform.id]: renameTimeoutIdsTransform,
|
|
25
31
|
[renameUseReferenceGuardsTransform.id]: renameUseReferenceGuardsTransform,
|
|
26
32
|
[renameUseReferenceGuardsV2Transform.id]: renameUseReferenceGuardsV2Transform,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "miniread",
|
|
3
3
|
"author": "Łukasz Jerciński",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.10.0",
|
|
6
6
|
"description": "Transform minified JavaScript/TypeScript into a more readable form using deterministic AST-based transforms.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/transform-manifest.json
CHANGED
|
@@ -26,9 +26,31 @@
|
|
|
26
26
|
"scope": "file",
|
|
27
27
|
"parallelizable": true,
|
|
28
28
|
"diffReductionImpact": 0,
|
|
29
|
-
"recommended":
|
|
29
|
+
"recommended": false,
|
|
30
30
|
"evaluatedAt": "2026-01-21T21:06:19.512Z",
|
|
31
|
-
"notes": "
|
|
31
|
+
"notes": "Superseded by rename-loop-index-variables-v3.",
|
|
32
|
+
"supersededBy": "rename-loop-index-variables-v3"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "rename-loop-index-variables-v2",
|
|
36
|
+
"description": "Renames numeric for-loop counters in `for (var ...)` (single or multi-declarator) and `for (let ...)` (multi-declarator) inits to index/index2/...",
|
|
37
|
+
"scope": "file",
|
|
38
|
+
"parallelizable": true,
|
|
39
|
+
"diffReductionImpact": 0,
|
|
40
|
+
"recommended": false,
|
|
41
|
+
"evaluatedAt": "2026-01-23T16:34:06.000Z",
|
|
42
|
+
"notes": "Superseded by rename-loop-index-variables-v3.",
|
|
43
|
+
"supersededBy": "rename-loop-index-variables-v3"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "rename-loop-index-variables-v3",
|
|
47
|
+
"description": "Renames numeric for-loop counters (single or multi-declarator `for (var/let ...)`) to index/index2/... based on nesting depth",
|
|
48
|
+
"scope": "file",
|
|
49
|
+
"parallelizable": true,
|
|
50
|
+
"diffReductionImpact": 0,
|
|
51
|
+
"recommended": true,
|
|
52
|
+
"evaluatedAt": "2026-01-23T17:09:04.000Z",
|
|
53
|
+
"notes": "Unifies rename-loop-index-variables and rename-loop-index-variables-v2 without modifying older transforms. Measured with baseline none: 0.00%."
|
|
32
54
|
},
|
|
33
55
|
{
|
|
34
56
|
"id": "rename-catch-parameters",
|
|
@@ -119,6 +141,16 @@
|
|
|
119
141
|
"evaluatedAt": "2026-01-22T21:39:53.578Z",
|
|
120
142
|
"notes": "Auto-added by evaluation script."
|
|
121
143
|
},
|
|
144
|
+
{
|
|
145
|
+
"id": "rename-replace-child-parameters",
|
|
146
|
+
"description": "Renames replaceChild forwarding wrapper parameters to $newChild and $oldChild",
|
|
147
|
+
"scope": "file",
|
|
148
|
+
"parallelizable": true,
|
|
149
|
+
"diffReductionImpact": 0,
|
|
150
|
+
"recommended": false,
|
|
151
|
+
"evaluatedAt": "2026-01-23T17:28:09.184Z",
|
|
152
|
+
"notes": "Measured with baseline none: 0.00%."
|
|
153
|
+
},
|
|
122
154
|
{
|
|
123
155
|
"id": "expand-special-number-literals",
|
|
124
156
|
"description": "Expands 1/0 to Infinity, -1/0 (and 1/-0) to -Infinity, and 0/0 to NaN (when not shadowed)",
|