miniread 1.21.0 → 1.22.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.
@@ -101,9 +101,16 @@ const manifestData = {
101
101
  notes: "Unifies rename-loop-index-variables and rename-loop-index-variables-v2 without modifying older transforms. Measured with baseline none: 0.00%.",
102
102
  },
103
103
  "rename-parameters-to-match-properties": {
104
- diffReductionImpact: 0.00003774938185385768,
104
+ diffReductionImpact: 0,
105
+ recommended: false,
106
+ notes: "Superseded by rename-parameters-to-match-properties-v2.",
107
+ supersededBy: "rename-parameters-to-match-properties-v2",
108
+ },
109
+ "rename-parameters-to-match-properties-v2": {
110
+ diffReductionImpact: 0.00009424182452166807,
105
111
  recommended: true,
106
- notes: "Added manually based on high-confidence heuristic.",
112
+ evaluatedAt: "2026-01-24T09:58:42.363Z",
113
+ notes: "Extends v1 to also handle this.property = param assignments.",
107
114
  },
108
115
  "rename-promise-executor-parameters": {
109
116
  diffReductionImpact: 0,
@@ -17,6 +17,7 @@ import { renameLoopIndexVariablesTransform } from "../rename-loop-index-variable
17
17
  import { renameLoopIndexVariablesV2Transform } from "../rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.js";
18
18
  import { renameLoopIndexVariablesV3Transform } from "../rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.js";
19
19
  import { renameParametersToMatchPropertiesTransform } from "../rename-parameters-to-match-properties/rename-parameters-to-match-properties-transform.js";
20
+ import { renameParametersToMatchPropertiesV2Transform } from "../rename-parameters-to-match-properties-v2/rename-parameters-to-match-properties-v2-transform.js";
20
21
  import { renamePromiseExecutorParametersTransform } from "../rename-promise-executor-parameters/rename-promise-executor-parameters-transform.js";
21
22
  import { renameReplaceChildParametersTransform } from "../rename-replace-child-parameters/rename-replace-child-parameters-transform.js";
22
23
  import { renameThisAliasesTransform } from "../rename-this-aliases/rename-this-aliases-transform.js";
@@ -44,6 +45,7 @@ export const transformRegistry = {
44
45
  [renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
45
46
  [renameLoopIndexVariablesV3Transform.id]: renameLoopIndexVariablesV3Transform,
46
47
  [renameParametersToMatchPropertiesTransform.id]: renameParametersToMatchPropertiesTransform,
48
+ [renameParametersToMatchPropertiesV2Transform.id]: renameParametersToMatchPropertiesV2Transform,
47
49
  [renamePromiseExecutorParametersTransform.id]: renamePromiseExecutorParametersTransform,
48
50
  [renameReplaceChildParametersTransform.id]: renameReplaceChildParametersTransform,
49
51
  [renameThisAliasesTransform.id]: renameThisAliasesTransform,
@@ -1,5 +1,6 @@
1
1
  {
2
- "diffReductionImpact": 0.00003774938185385768,
3
- "recommended": true,
4
- "notes": "Added manually based on high-confidence heuristic."
2
+ "diffReductionImpact": 0,
3
+ "recommended": false,
4
+ "notes": "Superseded by rename-parameters-to-match-properties-v2.",
5
+ "supersededBy": "rename-parameters-to-match-properties-v2"
5
6
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "diffReductionImpact": 0.00009424182452166807,
3
+ "recommended": true,
4
+ "notes": "Extends v1 to also handle this.property = param assignments.",
5
+ "evaluatedAt": "2026-01-24T09:58:42.363Z"
6
+ }
@@ -0,0 +1,2 @@
1
+ import { type Transform } from "../../core/types.js";
2
+ export declare const renameParametersToMatchPropertiesV2Transform: Transform;
@@ -0,0 +1,121 @@
1
+ import { createRequire } from "node:module";
2
+ import { isIdentifierName, isKeyword, isStrictBindReservedWord, } from "@babel/helper-validator-identifier";
3
+ import { getFilesToProcess, } from "../../core/types.js";
4
+ import { isStableRenamed } from "../../core/stable-naming.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
+ export const renameParametersToMatchPropertiesV2Transform = {
9
+ id: "rename-parameters-to-match-properties-v2",
10
+ description: "Renames parameters assigned to object properties or this.property",
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
+ Function(path) {
19
+ nodesVisited++;
20
+ const parameters = path.get("params");
21
+ for (const parameterPath of parameters) {
22
+ if (!parameterPath.isIdentifier())
23
+ continue;
24
+ const currentName = parameterPath.node.name;
25
+ if (isStableRenamed(currentName))
26
+ continue;
27
+ const binding = path.scope.getBinding(currentName);
28
+ if (!binding)
29
+ continue;
30
+ let candidateName;
31
+ let isConsistent = true;
32
+ // Analyze all references to this parameter
33
+ for (const referencePath of binding.referencePaths) {
34
+ const parent = referencePath.parentPath;
35
+ // Pattern 1: Value in object property { propName: param }
36
+ if (parent?.isObjectProperty()) {
37
+ // Ensure the param is the value, not the key
38
+ if (parent.node.value !== referencePath.node)
39
+ continue;
40
+ // Get the key name
41
+ const key = parent.node.key;
42
+ if (key.type === "Identifier" && !parent.node.computed) {
43
+ const propertyName = key.name;
44
+ if (candidateName === undefined) {
45
+ candidateName = propertyName;
46
+ }
47
+ else if (candidateName !== propertyName) {
48
+ // Conflicting property names (e.g. { x: a, y: a })
49
+ isConsistent = false;
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ // Pattern 2: Assignment to this.property - this.propName = param
55
+ // Only match simple assignment (=), not compound (+=, -=, etc.)
56
+ if (parent?.isAssignmentExpression() &&
57
+ parent.node.operator === "=") {
58
+ // Ensure the param is the right-hand side
59
+ if (parent.node.right !== referencePath.node)
60
+ continue;
61
+ const left = parent.node.left;
62
+ // Check if left side is this.propName (non-computed)
63
+ if (left.type === "MemberExpression" &&
64
+ !left.computed &&
65
+ left.object.type === "ThisExpression" &&
66
+ left.property.type === "Identifier") {
67
+ const propertyName = left.property.name;
68
+ if (candidateName === undefined) {
69
+ candidateName = propertyName;
70
+ }
71
+ else if (candidateName !== propertyName) {
72
+ // Conflicting property names (e.g. this.x = a; this.y = a)
73
+ isConsistent = false;
74
+ break;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ if (candidateName) {
80
+ // Check global references (conservative: if file uses 'console', don't use 'console')
81
+ const programScope = path.scope.getProgramParent();
82
+ if (Object.hasOwn(programScope.globals, candidateName)) {
83
+ isConsistent = false;
84
+ }
85
+ // Check for nested scope shadowing
86
+ // If we rename `a` -> `b`, and a nested scope has `b` bound,
87
+ // and we use `a` in that nested scope, it will become `b` (referring to inner `b`).
88
+ const wouldBeShadowed = binding.referencePaths.some((referencePath) => referencePath.scope !== path.scope &&
89
+ referencePath.scope.hasBinding(candidateName));
90
+ if (wouldBeShadowed) {
91
+ isConsistent = false;
92
+ }
93
+ }
94
+ // Constraints:
95
+ // 1. New name must be valid identifier
96
+ // 2. New name must not be a keyword/reserved word
97
+ // 3. New name must be longer than current, OR current is very short (<= 2 chars)
98
+ // 4. New name must be different from current
99
+ // 5. New name must not already exist in the scope
100
+ if (isConsistent &&
101
+ candidateName &&
102
+ candidateName !== currentName &&
103
+ (candidateName.length > currentName.length ||
104
+ currentName.length <= 2) &&
105
+ isIdentifierName(candidateName) &&
106
+ !isKeyword(candidateName) &&
107
+ !isStrictBindReservedWord(candidateName, true) &&
108
+ !path.scope.hasBinding(candidateName)) {
109
+ path.scope.rename(currentName, candidateName);
110
+ transformationsApplied++;
111
+ }
112
+ }
113
+ },
114
+ });
115
+ }
116
+ return Promise.resolve({
117
+ nodesVisited,
118
+ transformationsApplied,
119
+ });
120
+ },
121
+ };
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.21.0",
5
+ "version": "1.22.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",