miniread 1.14.0 → 1.15.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.
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { isStableRenamed, RenameGroup } from "../../core/stable-naming.js";
|
|
3
|
+
import { getFilesToProcess, } from "../../core/types.js";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
6
|
+
const traverse = require("@babel/traverse").default;
|
|
7
|
+
export const renameCharCodeAtTransform = {
|
|
8
|
+
id: "rename-char-code-at",
|
|
9
|
+
description: "Renames variables used in charCodeAt calls (str.charCodeAt(index))",
|
|
10
|
+
scope: "file",
|
|
11
|
+
parallelizable: true,
|
|
12
|
+
transform(context) {
|
|
13
|
+
let nodesVisited = 0;
|
|
14
|
+
let transformationsApplied = 0;
|
|
15
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
16
|
+
const group = new RenameGroup();
|
|
17
|
+
const processedBindings = new Set();
|
|
18
|
+
traverse(fileInfo.ast, {
|
|
19
|
+
CallExpression(path) {
|
|
20
|
+
nodesVisited++;
|
|
21
|
+
const node = path.node;
|
|
22
|
+
if (node.callee.type !== "MemberExpression")
|
|
23
|
+
return;
|
|
24
|
+
const callee = node.callee;
|
|
25
|
+
if (callee.computed)
|
|
26
|
+
return;
|
|
27
|
+
if (callee.property.type !== "Identifier")
|
|
28
|
+
return;
|
|
29
|
+
if (callee.property.name !== "charCodeAt")
|
|
30
|
+
return;
|
|
31
|
+
// Rename object (str)
|
|
32
|
+
if (callee.object.type === "Identifier") {
|
|
33
|
+
const currentName = callee.object.name;
|
|
34
|
+
const binding = path.scope.getBinding(currentName);
|
|
35
|
+
if (binding &&
|
|
36
|
+
!processedBindings.has(binding) &&
|
|
37
|
+
!isStableRenamed(currentName)) {
|
|
38
|
+
processedBindings.add(binding);
|
|
39
|
+
group.add({
|
|
40
|
+
scope: binding.scope,
|
|
41
|
+
currentName,
|
|
42
|
+
baseName: "str",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Rename first argument (index)
|
|
47
|
+
if (node.arguments.length > 0) {
|
|
48
|
+
const firstArgument = node.arguments[0];
|
|
49
|
+
if (firstArgument?.type === "Identifier") {
|
|
50
|
+
const currentName = firstArgument.name;
|
|
51
|
+
const binding = path.scope.getBinding(currentName);
|
|
52
|
+
if (binding &&
|
|
53
|
+
!processedBindings.has(binding) &&
|
|
54
|
+
!isStableRenamed(currentName)) {
|
|
55
|
+
processedBindings.add(binding);
|
|
56
|
+
group.add({
|
|
57
|
+
scope: binding.scope,
|
|
58
|
+
currentName,
|
|
59
|
+
baseName: "index",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
transformationsApplied += group.apply();
|
|
67
|
+
}
|
|
68
|
+
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -17,8 +17,10 @@ import { renameTimeoutIdsTransform } from "./rename-timeout-ids/rename-timeout-i
|
|
|
17
17
|
import { renameUseReferenceGuardsTransform } from "./rename-use-reference-guards/rename-use-reference-guards-transform.js";
|
|
18
18
|
import { renameUseReferenceGuardsV2Transform } from "./rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
19
19
|
import { splitVariableDeclarationsTransform } from "./split-variable-declarations/split-variable-declarations-transform.js";
|
|
20
|
+
import { renameCharCodeAtTransform } from "./rename-char-code-at/rename-char-code-at-transform.js";
|
|
20
21
|
import { renameParametersToMatchPropertiesTransform } from "./rename-parameters-to-match-properties/rename-parameters-to-match-properties-transform.js";
|
|
21
22
|
export const transformRegistry = {
|
|
23
|
+
[renameCharCodeAtTransform.id]: renameCharCodeAtTransform,
|
|
22
24
|
[expandBooleanLiteralsTransform.id]: expandBooleanLiteralsTransform,
|
|
23
25
|
[expandSpecialNumberLiteralsTransform.id]: expandSpecialNumberLiteralsTransform,
|
|
24
26
|
[expandSequenceExpressionsV4Transform.id]: expandSequenceExpressionsV4Transform,
|
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.15.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
|
@@ -191,6 +191,16 @@
|
|
|
191
191
|
"evaluatedAt": "2026-01-23T08:17:45.579Z",
|
|
192
192
|
"notes": "Auto-added by evaluation script."
|
|
193
193
|
},
|
|
194
|
+
{
|
|
195
|
+
"id": "rename-char-code-at",
|
|
196
|
+
"description": "Renames variables used in charCodeAt calls (str.charCodeAt(index))",
|
|
197
|
+
"scope": "file",
|
|
198
|
+
"parallelizable": true,
|
|
199
|
+
"diffReductionImpact": 0,
|
|
200
|
+
"recommended": true,
|
|
201
|
+
"evaluatedAt": "2026-01-23T18:00:00.000Z",
|
|
202
|
+
"notes": "Measured with baseline none: 0.00%. Renames variables used in charCodeAt to improve readability."
|
|
203
|
+
},
|
|
194
204
|
{
|
|
195
205
|
"id": "rename-parameters-to-match-properties",
|
|
196
206
|
"description": "Renames parameters that are assigned to object properties of the same name",
|