miniread 1.12.0 → 1.13.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/transforms/rename-comparison-flags/rename-comparison-flags-transform.d.ts +2 -0
- package/dist/transforms/rename-comparison-flags/rename-comparison-flags-transform.js +86 -0
- package/dist/transforms/transform-registry.js +2 -0
- package/package.json +1 -1
- package/transform-manifest.json +10 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { RenameGroup, isStableRenamed } 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 renameComparisonFlagsTransform = {
|
|
8
|
+
id: "rename-comparison-flags",
|
|
9
|
+
description: "Rename boolean variables assigned from string comparisons to descriptive flag names",
|
|
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 renameGroup = new RenameGroup();
|
|
17
|
+
traverse(fileInfo.ast, {
|
|
18
|
+
VariableDeclarator(path) {
|
|
19
|
+
nodesVisited++;
|
|
20
|
+
const { id, init } = path.node;
|
|
21
|
+
if (!init || id.type !== "Identifier") {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (init.type !== "BinaryExpression" ||
|
|
25
|
+
(init.operator !== "===" &&
|
|
26
|
+
init.operator !== "!==" &&
|
|
27
|
+
init.operator !== "==" &&
|
|
28
|
+
init.operator !== "!=")) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let stringValue;
|
|
32
|
+
if (init.right.type === "StringLiteral" &&
|
|
33
|
+
init.left.type === "Identifier") {
|
|
34
|
+
stringValue = init.right.value;
|
|
35
|
+
}
|
|
36
|
+
else if (init.left.type === "StringLiteral" &&
|
|
37
|
+
init.right.type === "Identifier") {
|
|
38
|
+
stringValue = init.left.value;
|
|
39
|
+
}
|
|
40
|
+
if (stringValue === undefined) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const currentName = id.name;
|
|
44
|
+
if (isStableRenamed(currentName)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const operator = init.operator;
|
|
48
|
+
const parts = stringValue.split(/[^\dA-Za-z]+/u).filter(Boolean);
|
|
49
|
+
const capitalizedValue = parts.length === 0
|
|
50
|
+
? stringValue === ""
|
|
51
|
+
? "EmptyString"
|
|
52
|
+
: "Flag"
|
|
53
|
+
: parts
|
|
54
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
55
|
+
.join("");
|
|
56
|
+
let baseName;
|
|
57
|
+
switch (operator) {
|
|
58
|
+
case "===": {
|
|
59
|
+
baseName = `is${capitalizedValue}`;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "!==": {
|
|
63
|
+
baseName = `isNot${capitalizedValue}`;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "==": {
|
|
67
|
+
baseName = `equals${capitalizedValue}`;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "!=": {
|
|
71
|
+
baseName = `notEquals${capitalizedValue}`;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
renameGroup.add({
|
|
76
|
+
scope: path.scope,
|
|
77
|
+
currentName,
|
|
78
|
+
baseName,
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
transformationsApplied += renameGroup.apply();
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -4,6 +4,7 @@ import { expandSequenceExpressionsV4Transform } from "./expand-sequence-expressi
|
|
|
4
4
|
import { expandSequenceExpressionsV5Transform } from "./expand-sequence-expressions-v5/expand-sequence-expressions-v5-transform.js";
|
|
5
5
|
import { expandUndefinedLiteralsTransform } from "./expand-undefined-literals/expand-undefined-literals-transform.js";
|
|
6
6
|
import { renameCatchParametersTransform } from "./rename-catch-parameters/rename-catch-parameters-transform.js";
|
|
7
|
+
import { renameComparisonFlagsTransform } from "./rename-comparison-flags/rename-comparison-flags-transform.js";
|
|
7
8
|
import { renameDestructuredAliasesTransform } from "./rename-destructured-aliases/rename-destructured-aliases-transform.js";
|
|
8
9
|
import { renameEventParametersTransform } from "./rename-event-parameters/rename-event-parameters-transform.js";
|
|
9
10
|
import { renameLoopIndexVariablesTransform } from "./rename-loop-index-variables/rename-loop-index-variables-transform.js";
|
|
@@ -23,6 +24,7 @@ export const transformRegistry = {
|
|
|
23
24
|
[expandSequenceExpressionsV5Transform.id]: expandSequenceExpressionsV5Transform,
|
|
24
25
|
[expandUndefinedLiteralsTransform.id]: expandUndefinedLiteralsTransform,
|
|
25
26
|
[renameCatchParametersTransform.id]: renameCatchParametersTransform,
|
|
27
|
+
[renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
|
|
26
28
|
[renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
|
|
27
29
|
[renameEventParametersTransform.id]: renameEventParametersTransform,
|
|
28
30
|
[renameLoopIndexVariablesTransform.id]: renameLoopIndexVariablesTransform,
|
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.13.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
|
@@ -141,6 +141,16 @@
|
|
|
141
141
|
"evaluatedAt": "2026-01-23T10:29:23.279Z",
|
|
142
142
|
"notes": "Measured with baseline none: 0.00%. Added to recommended for readability."
|
|
143
143
|
},
|
|
144
|
+
{
|
|
145
|
+
"id": "rename-comparison-flags",
|
|
146
|
+
"description": "Rename boolean variables assigned from string comparisons to descriptive flag names",
|
|
147
|
+
"scope": "file",
|
|
148
|
+
"parallelizable": true,
|
|
149
|
+
"diffReductionImpact": 0,
|
|
150
|
+
"recommended": true,
|
|
151
|
+
"evaluatedAt": "2026-01-23T17:54:14.000Z",
|
|
152
|
+
"notes": "Measured with baseline none: 0%. Improves readability by renaming minified variables like 'saA === \"darwin\"' to '$isDarwin'."
|
|
153
|
+
},
|
|
144
154
|
{
|
|
145
155
|
"id": "split-variable-declarations",
|
|
146
156
|
"description": "Splits multi-declarator variable declarations into separate statements",
|