miniread 1.30.0 → 1.32.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/_generated/manifest.js +12 -0
- package/dist/transforms/_generated/registry.js +4 -0
- package/dist/transforms/rename-arguments-length-flags/manifest.json +6 -0
- package/dist/transforms/rename-arguments-length-flags/rename-arguments-length-flags-transform.d.ts +2 -0
- package/dist/transforms/rename-arguments-length-flags/rename-arguments-length-flags-transform.js +106 -0
- package/dist/transforms/use-object-property-shorthand/manifest.json +6 -0
- package/dist/transforms/use-object-property-shorthand/use-object-property-shorthand-transform.d.ts +2 -0
- package/dist/transforms/use-object-property-shorthand/use-object-property-shorthand-transform.js +45 -0
- package/package.json +1 -1
|
@@ -38,6 +38,12 @@ const manifestData = {
|
|
|
38
38
|
evaluatedAt: "2026-01-23T18:15:00.000Z",
|
|
39
39
|
notes: "Added manually; improves readability by reducing nesting.",
|
|
40
40
|
},
|
|
41
|
+
"rename-arguments-length-flags": {
|
|
42
|
+
diffReductionImpact: 0,
|
|
43
|
+
recommended: true,
|
|
44
|
+
evaluatedAt: "2026-01-24T15:56:12.512Z",
|
|
45
|
+
notes: "Measured with baseline none: 0.00%. Added to recommended for readability.",
|
|
46
|
+
},
|
|
41
47
|
"rename-awaiter-parameters": {
|
|
42
48
|
diffReductionImpact: 0,
|
|
43
49
|
recommended: true,
|
|
@@ -209,6 +215,12 @@ const manifestData = {
|
|
|
209
215
|
evaluatedAt: "2026-01-23T05:45:27.981Z",
|
|
210
216
|
notes: "Auto-added by evaluation script. Measured with baseline none: -0.28%. Enabled in the recommended preset for readability and to normalize variable declarations even when line diffs increase.",
|
|
211
217
|
},
|
|
218
|
+
"use-object-property-shorthand": {
|
|
219
|
+
diffReductionImpact: 0,
|
|
220
|
+
recommended: true,
|
|
221
|
+
evaluatedAt: "2026-01-24T12:47:30.495Z",
|
|
222
|
+
notes: "Auto-added by evaluation script.",
|
|
223
|
+
},
|
|
212
224
|
"use-object-shorthand": {
|
|
213
225
|
diffReductionImpact: 0,
|
|
214
226
|
recommended: true,
|
|
@@ -6,6 +6,7 @@ import { expandSequenceExpressionsV5Transform } from "../expand-sequence-express
|
|
|
6
6
|
import { expandSpecialNumberLiteralsTransform } from "../expand-special-number-literals/expand-special-number-literals-transform.js";
|
|
7
7
|
import { expandUndefinedLiteralsTransform } from "../expand-undefined-literals/expand-undefined-literals-transform.js";
|
|
8
8
|
import { removeRedundantElseTransform } from "../remove-redundant-else/remove-redundant-else-transform.js";
|
|
9
|
+
import { renameArgumentsLengthFlagsTransform } from "../rename-arguments-length-flags/rename-arguments-length-flags-transform.js";
|
|
9
10
|
import { renameAwaiterParametersTransform } from "../rename-awaiter-parameters/rename-awaiter-parameters-transform.js";
|
|
10
11
|
import { renameCatchParametersTransform } from "../rename-catch-parameters/rename-catch-parameters-transform.js";
|
|
11
12
|
import { renameCharCodeAtTransform } from "../rename-char-code-at/rename-char-code-at-transform.js";
|
|
@@ -35,6 +36,7 @@ import { renameUseReferenceGuardsTransform } from "../rename-use-reference-guard
|
|
|
35
36
|
import { renameUseReferenceGuardsV2Transform } from "../rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
36
37
|
import { simplifyBooleanNegationsTransform } from "../simplify-boolean-negations/simplify-boolean-negations-transform.js";
|
|
37
38
|
import { splitVariableDeclarationsTransform } from "../split-variable-declarations/split-variable-declarations-transform.js";
|
|
39
|
+
import { useObjectPropertyShorthandTransform } from "../use-object-property-shorthand/use-object-property-shorthand-transform.js";
|
|
38
40
|
import { useObjectShorthandTransform } from "../use-object-shorthand/use-object-shorthand-transform.js";
|
|
39
41
|
export const transformRegistry = {
|
|
40
42
|
[expandBooleanLiteralsTransform.id]: expandBooleanLiteralsTransform,
|
|
@@ -43,6 +45,7 @@ export const transformRegistry = {
|
|
|
43
45
|
[expandSpecialNumberLiteralsTransform.id]: expandSpecialNumberLiteralsTransform,
|
|
44
46
|
[expandUndefinedLiteralsTransform.id]: expandUndefinedLiteralsTransform,
|
|
45
47
|
[removeRedundantElseTransform.id]: removeRedundantElseTransform,
|
|
48
|
+
[renameArgumentsLengthFlagsTransform.id]: renameArgumentsLengthFlagsTransform,
|
|
46
49
|
[renameAwaiterParametersTransform.id]: renameAwaiterParametersTransform,
|
|
47
50
|
[renameCatchParametersTransform.id]: renameCatchParametersTransform,
|
|
48
51
|
[renameCharCodeAtTransform.id]: renameCharCodeAtTransform,
|
|
@@ -72,6 +75,7 @@ export const transformRegistry = {
|
|
|
72
75
|
[renameUseReferenceGuardsV2Transform.id]: renameUseReferenceGuardsV2Transform,
|
|
73
76
|
[simplifyBooleanNegationsTransform.id]: simplifyBooleanNegationsTransform,
|
|
74
77
|
[splitVariableDeclarationsTransform.id]: splitVariableDeclarationsTransform,
|
|
78
|
+
[useObjectPropertyShorthandTransform.id]: useObjectPropertyShorthandTransform,
|
|
75
79
|
[useObjectShorthandTransform.id]: useObjectShorthandTransform,
|
|
76
80
|
};
|
|
77
81
|
export const allTransformIds = Object.keys(transformRegistry);
|
package/dist/transforms/rename-arguments-length-flags/rename-arguments-length-flags-transform.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { isIdentifier, isMemberExpression, isNumericLiteral, isPrivateName, } from "@babel/types";
|
|
3
|
+
import { RenameGroup, isStableRenamed } from "../../core/stable-naming.js";
|
|
4
|
+
import { getFilesToProcess, } from "../../core/types.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
|
+
const isArgumentsLengthExpression = (expression) => {
|
|
9
|
+
if (!isMemberExpression(expression))
|
|
10
|
+
return false;
|
|
11
|
+
if (expression.computed)
|
|
12
|
+
return false;
|
|
13
|
+
if (!isIdentifier(expression.object))
|
|
14
|
+
return false;
|
|
15
|
+
if (!isIdentifier(expression.property))
|
|
16
|
+
return false;
|
|
17
|
+
return (expression.object.name === "arguments" &&
|
|
18
|
+
expression.property.name === "length");
|
|
19
|
+
};
|
|
20
|
+
const getExpression = (node) => {
|
|
21
|
+
if (isPrivateName(node))
|
|
22
|
+
return undefined;
|
|
23
|
+
return node;
|
|
24
|
+
};
|
|
25
|
+
const getNumericLiteralValue = (node) => {
|
|
26
|
+
if (!isNumericLiteral(node))
|
|
27
|
+
return undefined;
|
|
28
|
+
if (!Number.isInteger(node.value))
|
|
29
|
+
return undefined;
|
|
30
|
+
return node.value;
|
|
31
|
+
};
|
|
32
|
+
const getAtLeastArgumentsThreshold = (init) => {
|
|
33
|
+
if (init.operator === ">" || init.operator === ">=") {
|
|
34
|
+
const left = getExpression(init.left);
|
|
35
|
+
const right = getExpression(init.right);
|
|
36
|
+
if (!left || !right)
|
|
37
|
+
return undefined;
|
|
38
|
+
if (!isArgumentsLengthExpression(left))
|
|
39
|
+
return undefined;
|
|
40
|
+
const value = getNumericLiteralValue(right);
|
|
41
|
+
if (value === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
return init.operator === ">" ? value + 1 : value;
|
|
44
|
+
}
|
|
45
|
+
if (init.operator === "<" || init.operator === "<=") {
|
|
46
|
+
const left = getExpression(init.left);
|
|
47
|
+
const right = getExpression(init.right);
|
|
48
|
+
if (!left || !right)
|
|
49
|
+
return undefined;
|
|
50
|
+
if (!isArgumentsLengthExpression(right))
|
|
51
|
+
return undefined;
|
|
52
|
+
const value = getNumericLiteralValue(left);
|
|
53
|
+
if (value === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
return init.operator === "<" ? value + 1 : value;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
};
|
|
59
|
+
const getBaseName = (threshold) => {
|
|
60
|
+
if (threshold === 1)
|
|
61
|
+
return "hasAtLeast1Arg";
|
|
62
|
+
return `hasAtLeast${threshold}Args`;
|
|
63
|
+
};
|
|
64
|
+
export const renameArgumentsLengthFlagsTransform = {
|
|
65
|
+
id: "rename-arguments-length-flags",
|
|
66
|
+
description: "Rename arguments.length guards (>= N) to $hasAtLeastNArgs when stable",
|
|
67
|
+
scope: "file",
|
|
68
|
+
parallelizable: true,
|
|
69
|
+
transform(context) {
|
|
70
|
+
let nodesVisited = 0;
|
|
71
|
+
let transformationsApplied = 0;
|
|
72
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
73
|
+
const renameGroup = new RenameGroup();
|
|
74
|
+
traverse(fileInfo.ast, {
|
|
75
|
+
VariableDeclarator(path) {
|
|
76
|
+
nodesVisited++;
|
|
77
|
+
const id = path.node.id;
|
|
78
|
+
if (id.type !== "Identifier")
|
|
79
|
+
return;
|
|
80
|
+
if (isStableRenamed(id.name))
|
|
81
|
+
return;
|
|
82
|
+
if (id.name.length > 1)
|
|
83
|
+
return;
|
|
84
|
+
const init = path.node.init;
|
|
85
|
+
if (init?.type !== "BinaryExpression")
|
|
86
|
+
return;
|
|
87
|
+
if (path.scope.getBinding("arguments"))
|
|
88
|
+
return;
|
|
89
|
+
const threshold = getAtLeastArgumentsThreshold(init);
|
|
90
|
+
if (threshold === undefined || threshold < 1)
|
|
91
|
+
return;
|
|
92
|
+
const binding = path.scope.getBinding(id.name);
|
|
93
|
+
if (!binding?.constant)
|
|
94
|
+
return;
|
|
95
|
+
renameGroup.add({
|
|
96
|
+
scope: binding.scope,
|
|
97
|
+
currentName: id.name,
|
|
98
|
+
baseName: getBaseName(threshold),
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
transformationsApplied += renameGroup.apply();
|
|
103
|
+
}
|
|
104
|
+
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
105
|
+
},
|
|
106
|
+
};
|
package/dist/transforms/use-object-property-shorthand/use-object-property-shorthand-transform.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const isShorthandCandidate = (path) => {
|
|
7
|
+
const isObjectExpression = path.parentPath.isObjectExpression();
|
|
8
|
+
const isObjectPattern = path.parentPath.isObjectPattern();
|
|
9
|
+
if (!isObjectExpression && !isObjectPattern)
|
|
10
|
+
return false;
|
|
11
|
+
const { node } = path;
|
|
12
|
+
if (node.computed || node.shorthand)
|
|
13
|
+
return false;
|
|
14
|
+
if (node.key.type !== "Identifier")
|
|
15
|
+
return false;
|
|
16
|
+
if (node.value.type !== "Identifier")
|
|
17
|
+
return false;
|
|
18
|
+
// `{ __proto__: x }` has special prototype-setting semantics in object literals,
|
|
19
|
+
// while `{ __proto__ }` is a normal data property. Avoid changing runtime shape.
|
|
20
|
+
if (isObjectExpression && node.key.name === "__proto__")
|
|
21
|
+
return false;
|
|
22
|
+
return node.key.name === node.value.name;
|
|
23
|
+
};
|
|
24
|
+
export const useObjectPropertyShorthandTransform = {
|
|
25
|
+
id: "use-object-property-shorthand",
|
|
26
|
+
description: "Converts object properties with identical key/value identifiers to shorthand",
|
|
27
|
+
scope: "file",
|
|
28
|
+
parallelizable: true,
|
|
29
|
+
transform(context) {
|
|
30
|
+
let nodesVisited = 0;
|
|
31
|
+
let transformationsApplied = 0;
|
|
32
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
33
|
+
traverse(fileInfo.ast, {
|
|
34
|
+
ObjectProperty(path) {
|
|
35
|
+
nodesVisited++;
|
|
36
|
+
if (!isShorthandCandidate(path))
|
|
37
|
+
return;
|
|
38
|
+
path.node.shorthand = true;
|
|
39
|
+
transformationsApplied++;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
44
|
+
},
|
|
45
|
+
};
|
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.32.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",
|