miniread 1.14.0 → 1.16.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/remove-redundant-else/remove-redundant-else-transform.d.ts +2 -0
- package/dist/transforms/remove-redundant-else/remove-redundant-else-transform.js +61 -0
- package/dist/transforms/rename-char-code-at/rename-char-code-at-transform.d.ts +2 -0
- package/dist/transforms/rename-char-code-at/rename-char-code-at-transform.js +70 -0
- package/dist/transforms/transform-registry.js +4 -0
- package/package.json +1 -1
- package/transform-manifest.json +20 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { getFilesToProcess, } from "../../core/types.js";
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
5
|
+
const traverse = require("@babel/traverse").default;
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
|
+
const t = require("@babel/types");
|
|
8
|
+
export const removeRedundantElseTransform = {
|
|
9
|
+
id: "remove-redundant-else",
|
|
10
|
+
description: "Removes redundant else blocks after return/throw/break/continue",
|
|
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
|
+
traverse(fileInfo.ast, {
|
|
18
|
+
IfStatement(path) {
|
|
19
|
+
nodesVisited++;
|
|
20
|
+
const { consequent, alternate } = path.node;
|
|
21
|
+
if (!alternate)
|
|
22
|
+
return;
|
|
23
|
+
let interrupts = false;
|
|
24
|
+
if (isInterrupting(consequent)) {
|
|
25
|
+
interrupts = true;
|
|
26
|
+
}
|
|
27
|
+
else if (consequent.type === "BlockStatement" &&
|
|
28
|
+
consequent.body.length > 0) {
|
|
29
|
+
const last = consequent.body.at(-1);
|
|
30
|
+
if (isInterrupting(last)) {
|
|
31
|
+
interrupts = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (interrupts) {
|
|
35
|
+
// Remove alternate
|
|
36
|
+
// eslint-disable-next-line unicorn/no-null
|
|
37
|
+
path.node.alternate = null;
|
|
38
|
+
// Insert alternate content after
|
|
39
|
+
path.insertAfter(alternate);
|
|
40
|
+
transformationsApplied++;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return Promise.resolve({
|
|
46
|
+
nodesVisited,
|
|
47
|
+
transformationsApplied,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
function isInterrupting(node) {
|
|
52
|
+
return (
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
54
|
+
(t.isReturnStatement(node) ||
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
56
|
+
t.isThrowStatement(node) ||
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
58
|
+
t.isBreakStatement(node) ||
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
60
|
+
t.isContinueStatement(node)));
|
|
61
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -3,6 +3,7 @@ import { expandSpecialNumberLiteralsTransform } from "./expand-special-number-li
|
|
|
3
3
|
import { expandSequenceExpressionsV4Transform } from "./expand-sequence-expressions-v4/expand-sequence-expressions-v4-transform.js";
|
|
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
|
+
import { removeRedundantElseTransform } from "./remove-redundant-else/remove-redundant-else-transform.js";
|
|
6
7
|
import { renameCatchParametersTransform } from "./rename-catch-parameters/rename-catch-parameters-transform.js";
|
|
7
8
|
import { renameComparisonFlagsTransform } from "./rename-comparison-flags/rename-comparison-flags-transform.js";
|
|
8
9
|
import { renameDestructuredAliasesTransform } from "./rename-destructured-aliases/rename-destructured-aliases-transform.js";
|
|
@@ -17,13 +18,16 @@ import { renameTimeoutIdsTransform } from "./rename-timeout-ids/rename-timeout-i
|
|
|
17
18
|
import { renameUseReferenceGuardsTransform } from "./rename-use-reference-guards/rename-use-reference-guards-transform.js";
|
|
18
19
|
import { renameUseReferenceGuardsV2Transform } from "./rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
19
20
|
import { splitVariableDeclarationsTransform } from "./split-variable-declarations/split-variable-declarations-transform.js";
|
|
21
|
+
import { renameCharCodeAtTransform } from "./rename-char-code-at/rename-char-code-at-transform.js";
|
|
20
22
|
import { renameParametersToMatchPropertiesTransform } from "./rename-parameters-to-match-properties/rename-parameters-to-match-properties-transform.js";
|
|
21
23
|
export const transformRegistry = {
|
|
24
|
+
[renameCharCodeAtTransform.id]: renameCharCodeAtTransform,
|
|
22
25
|
[expandBooleanLiteralsTransform.id]: expandBooleanLiteralsTransform,
|
|
23
26
|
[expandSpecialNumberLiteralsTransform.id]: expandSpecialNumberLiteralsTransform,
|
|
24
27
|
[expandSequenceExpressionsV4Transform.id]: expandSequenceExpressionsV4Transform,
|
|
25
28
|
[expandSequenceExpressionsV5Transform.id]: expandSequenceExpressionsV5Transform,
|
|
26
29
|
[expandUndefinedLiteralsTransform.id]: expandUndefinedLiteralsTransform,
|
|
30
|
+
[removeRedundantElseTransform.id]: removeRedundantElseTransform,
|
|
27
31
|
[renameCatchParametersTransform.id]: renameCatchParametersTransform,
|
|
28
32
|
[renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
|
|
29
33
|
[renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
|
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.16.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,26 @@
|
|
|
191
191
|
"evaluatedAt": "2026-01-23T08:17:45.579Z",
|
|
192
192
|
"notes": "Auto-added by evaluation script."
|
|
193
193
|
},
|
|
194
|
+
{
|
|
195
|
+
"id": "remove-redundant-else",
|
|
196
|
+
"description": "Removes redundant else blocks after return/throw/break/continue",
|
|
197
|
+
"scope": "file",
|
|
198
|
+
"parallelizable": true,
|
|
199
|
+
"diffReductionImpact": 0,
|
|
200
|
+
"recommended": true,
|
|
201
|
+
"evaluatedAt": "2026-01-23T18:15:00.000Z",
|
|
202
|
+
"notes": "Added manually; improves readability by reducing nesting."
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"id": "rename-char-code-at",
|
|
206
|
+
"description": "Renames variables used in charCodeAt calls (str.charCodeAt(index))",
|
|
207
|
+
"scope": "file",
|
|
208
|
+
"parallelizable": true,
|
|
209
|
+
"diffReductionImpact": 0,
|
|
210
|
+
"recommended": true,
|
|
211
|
+
"evaluatedAt": "2026-01-23T18:00:00.000Z",
|
|
212
|
+
"notes": "Measured with baseline none: 0.00%. Renames variables used in charCodeAt to improve readability."
|
|
213
|
+
},
|
|
194
214
|
{
|
|
195
215
|
"id": "rename-parameters-to-match-properties",
|
|
196
216
|
"description": "Renames parameters that are assigned to object properties of the same name",
|