miniread 1.31.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 +6 -0
- package/dist/transforms/_generated/registry.js +2 -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
|
@@ -215,6 +215,12 @@ const manifestData = {
|
|
|
215
215
|
evaluatedAt: "2026-01-23T05:45:27.981Z",
|
|
216
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.",
|
|
217
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
|
+
},
|
|
218
224
|
"use-object-shorthand": {
|
|
219
225
|
diffReductionImpact: 0,
|
|
220
226
|
recommended: true,
|
|
@@ -36,6 +36,7 @@ import { renameUseReferenceGuardsTransform } from "../rename-use-reference-guard
|
|
|
36
36
|
import { renameUseReferenceGuardsV2Transform } from "../rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
|
|
37
37
|
import { simplifyBooleanNegationsTransform } from "../simplify-boolean-negations/simplify-boolean-negations-transform.js";
|
|
38
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";
|
|
39
40
|
import { useObjectShorthandTransform } from "../use-object-shorthand/use-object-shorthand-transform.js";
|
|
40
41
|
export const transformRegistry = {
|
|
41
42
|
[expandBooleanLiteralsTransform.id]: expandBooleanLiteralsTransform,
|
|
@@ -74,6 +75,7 @@ export const transformRegistry = {
|
|
|
74
75
|
[renameUseReferenceGuardsV2Transform.id]: renameUseReferenceGuardsV2Transform,
|
|
75
76
|
[simplifyBooleanNegationsTransform.id]: simplifyBooleanNegationsTransform,
|
|
76
77
|
[splitVariableDeclarationsTransform.id]: splitVariableDeclarationsTransform,
|
|
78
|
+
[useObjectPropertyShorthandTransform.id]: useObjectPropertyShorthandTransform,
|
|
77
79
|
[useObjectShorthandTransform.id]: useObjectShorthandTransform,
|
|
78
80
|
};
|
|
79
81
|
export const allTransformIds = Object.keys(transformRegistry);
|
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",
|