miniread 1.31.0 → 1.33.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 +10 -0
- package/dist/transforms/_generated/registry.js +4 -0
- package/dist/transforms/rename-default-options-parameters/manifest.json +4 -0
- package/dist/transforms/rename-default-options-parameters/rename-default-options-parameters-transform.d.ts +2 -0
- package/dist/transforms/rename-default-options-parameters/rename-default-options-parameters-transform.js +110 -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
|
@@ -87,6 +87,10 @@ const manifestData = {
|
|
|
87
87
|
evaluatedAt: "2026-01-24T15:59:39.475Z",
|
|
88
88
|
notes: "Measured with baseline none: 0.00%. Added to recommended for readability.",
|
|
89
89
|
},
|
|
90
|
+
"rename-default-options-parameters": {
|
|
91
|
+
diffReductionImpact: 0,
|
|
92
|
+
recommended: true,
|
|
93
|
+
},
|
|
90
94
|
"rename-destructured-aliases": {
|
|
91
95
|
diffReductionImpact: 0.000943734546346775,
|
|
92
96
|
recommended: true,
|
|
@@ -215,6 +219,12 @@ const manifestData = {
|
|
|
215
219
|
evaluatedAt: "2026-01-23T05:45:27.981Z",
|
|
216
220
|
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.",
|
|
217
221
|
},
|
|
222
|
+
"use-object-property-shorthand": {
|
|
223
|
+
diffReductionImpact: 0,
|
|
224
|
+
recommended: true,
|
|
225
|
+
evaluatedAt: "2026-01-24T12:47:30.495Z",
|
|
226
|
+
notes: "Auto-added by evaluation script.",
|
|
227
|
+
},
|
|
218
228
|
"use-object-shorthand": {
|
|
219
229
|
diffReductionImpact: 0,
|
|
220
230
|
recommended: true,
|
|
@@ -14,6 +14,7 @@ import { renameCharcodeVariablesTransform } from "../rename-charcode-variables/r
|
|
|
14
14
|
import { renameCharcodeVariablesV2Transform } from "../rename-charcode-variables-v2/rename-charcode-variables-v2-transform.js";
|
|
15
15
|
import { renameComparisonFlagsTransform } from "../rename-comparison-flags/rename-comparison-flags-transform.js";
|
|
16
16
|
import { renameDateNowStartTimesTransform } from "../rename-date-now-start-times/rename-date-now-start-times-transform.js";
|
|
17
|
+
import { renameDefaultOptionsParametersTransform } from "../rename-default-options-parameters/rename-default-options-parameters-transform.js";
|
|
17
18
|
import { renameDestructuredAliasesTransform } from "../rename-destructured-aliases/rename-destructured-aliases-transform.js";
|
|
18
19
|
import { renameErrorVariablesTransform } from "../rename-error-variables/rename-error-variables-transform.js";
|
|
19
20
|
import { renameEventParametersTransform } from "../rename-event-parameters/rename-event-parameters-transform.js";
|
|
@@ -36,6 +37,7 @@ import { renameUseReferenceGuardsTransform } from "../rename-use-reference-guard
|
|
|
36
37
|
import { renameUseReferenceGuardsV2Transform } from "../rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
37
38
|
import { simplifyBooleanNegationsTransform } from "../simplify-boolean-negations/simplify-boolean-negations-transform.js";
|
|
38
39
|
import { splitVariableDeclarationsTransform } from "../split-variable-declarations/split-variable-declarations-transform.js";
|
|
40
|
+
import { useObjectPropertyShorthandTransform } from "../use-object-property-shorthand/use-object-property-shorthand-transform.js";
|
|
39
41
|
import { useObjectShorthandTransform } from "../use-object-shorthand/use-object-shorthand-transform.js";
|
|
40
42
|
export const transformRegistry = {
|
|
41
43
|
[expandBooleanLiteralsTransform.id]: expandBooleanLiteralsTransform,
|
|
@@ -52,6 +54,7 @@ export const transformRegistry = {
|
|
|
52
54
|
[renameCharcodeVariablesV2Transform.id]: renameCharcodeVariablesV2Transform,
|
|
53
55
|
[renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
|
|
54
56
|
[renameDateNowStartTimesTransform.id]: renameDateNowStartTimesTransform,
|
|
57
|
+
[renameDefaultOptionsParametersTransform.id]: renameDefaultOptionsParametersTransform,
|
|
55
58
|
[renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
|
|
56
59
|
[renameErrorVariablesTransform.id]: renameErrorVariablesTransform,
|
|
57
60
|
[renameEventParametersTransform.id]: renameEventParametersTransform,
|
|
@@ -74,6 +77,7 @@ export const transformRegistry = {
|
|
|
74
77
|
[renameUseReferenceGuardsV2Transform.id]: renameUseReferenceGuardsV2Transform,
|
|
75
78
|
[simplifyBooleanNegationsTransform.id]: simplifyBooleanNegationsTransform,
|
|
76
79
|
[splitVariableDeclarationsTransform.id]: splitVariableDeclarationsTransform,
|
|
80
|
+
[useObjectPropertyShorthandTransform.id]: useObjectPropertyShorthandTransform,
|
|
77
81
|
[useObjectShorthandTransform.id]: useObjectShorthandTransform,
|
|
78
82
|
};
|
|
79
83
|
export const allTransformIds = Object.keys(transformRegistry);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import * as t from "@babel/types";
|
|
3
|
+
import { isStableRenamed, RenameGroup } 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 BASE_NAME = "options";
|
|
9
|
+
const getSingleAssignmentExpression = (statement) => {
|
|
10
|
+
if (t.isExpressionStatement(statement)) {
|
|
11
|
+
const { expression } = statement;
|
|
12
|
+
return t.isAssignmentExpression(expression, { operator: "=" })
|
|
13
|
+
? expression
|
|
14
|
+
: undefined;
|
|
15
|
+
}
|
|
16
|
+
if (t.isBlockStatement(statement)) {
|
|
17
|
+
const [firstStatement] = statement.body;
|
|
18
|
+
if (!firstStatement)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (!t.isExpressionStatement(firstStatement))
|
|
21
|
+
return undefined;
|
|
22
|
+
const { expression } = firstStatement;
|
|
23
|
+
return t.isAssignmentExpression(expression, { operator: "=" })
|
|
24
|
+
? expression
|
|
25
|
+
: undefined;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
const getDefaultOptionsParameterNames = (path) => {
|
|
30
|
+
if (path.scope.hasBinding("undefined", true))
|
|
31
|
+
return [];
|
|
32
|
+
const body = path.node.body;
|
|
33
|
+
if (!t.isBlockStatement(body))
|
|
34
|
+
return [];
|
|
35
|
+
const parameterNames = new Set();
|
|
36
|
+
for (const parameter of path.node.params) {
|
|
37
|
+
if (!t.isIdentifier(parameter))
|
|
38
|
+
continue;
|
|
39
|
+
parameterNames.add(parameter.name);
|
|
40
|
+
}
|
|
41
|
+
const matches = [];
|
|
42
|
+
for (const statement of body.body) {
|
|
43
|
+
if (t.isExpressionStatement(statement) &&
|
|
44
|
+
t.isStringLiteral(statement.expression)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!t.isIfStatement(statement))
|
|
48
|
+
break;
|
|
49
|
+
if (statement.alternate)
|
|
50
|
+
break;
|
|
51
|
+
if (!t.isBinaryExpression(statement.test, { operator: "===" }))
|
|
52
|
+
break;
|
|
53
|
+
const { left, right } = statement.test;
|
|
54
|
+
const parameterName = t.isIdentifier(left) && t.isIdentifier(right, { name: "undefined" })
|
|
55
|
+
? left.name
|
|
56
|
+
: t.isIdentifier(left, { name: "undefined" }) && t.isIdentifier(right)
|
|
57
|
+
? right.name
|
|
58
|
+
: undefined;
|
|
59
|
+
if (!parameterName || parameterName === "undefined")
|
|
60
|
+
break;
|
|
61
|
+
if (!parameterNames.has(parameterName))
|
|
62
|
+
break;
|
|
63
|
+
const assignment = getSingleAssignmentExpression(statement.consequent);
|
|
64
|
+
if (!assignment)
|
|
65
|
+
break;
|
|
66
|
+
if (!t.isIdentifier(assignment.left, { name: parameterName }))
|
|
67
|
+
break;
|
|
68
|
+
if (!t.isObjectExpression(assignment.right))
|
|
69
|
+
break;
|
|
70
|
+
if (assignment.right.properties.length > 0)
|
|
71
|
+
break;
|
|
72
|
+
matches.push(parameterName);
|
|
73
|
+
}
|
|
74
|
+
return [...new Set(matches)];
|
|
75
|
+
};
|
|
76
|
+
export const renameDefaultOptionsParametersTransform = {
|
|
77
|
+
id: "rename-default-options-parameters",
|
|
78
|
+
description: "Renames parameters defaulted to {} into $options (or options/options2 when multiple)",
|
|
79
|
+
scope: "file",
|
|
80
|
+
parallelizable: true,
|
|
81
|
+
transform(context) {
|
|
82
|
+
let nodesVisited = 0;
|
|
83
|
+
let transformationsApplied = 0;
|
|
84
|
+
for (const fileInfo of getFilesToProcess(context)) {
|
|
85
|
+
const group = new RenameGroup();
|
|
86
|
+
traverse(fileInfo.ast, {
|
|
87
|
+
Function(path) {
|
|
88
|
+
nodesVisited++;
|
|
89
|
+
const parameterNames = getDefaultOptionsParameterNames(path);
|
|
90
|
+
for (const parameterName of parameterNames) {
|
|
91
|
+
if (parameterName === BASE_NAME)
|
|
92
|
+
continue;
|
|
93
|
+
if (isStableRenamed(parameterName))
|
|
94
|
+
continue;
|
|
95
|
+
group.add({
|
|
96
|
+
scope: path.scope,
|
|
97
|
+
currentName: parameterName,
|
|
98
|
+
baseName: BASE_NAME,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
transformationsApplied += group.apply();
|
|
104
|
+
}
|
|
105
|
+
return Promise.resolve({
|
|
106
|
+
nodesVisited,
|
|
107
|
+
transformationsApplied,
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
};
|
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.33.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",
|