miniread 1.21.0 → 1.23.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.
@@ -75,6 +75,12 @@ const manifestData = {
75
75
  evaluatedAt: "2026-01-22T12:49:10.952Z",
76
76
  notes: "Auto-added by evaluation script. Measured with baseline none: 0.09%.",
77
77
  },
78
+ "rename-error-variables": {
79
+ diffReductionImpact: 0.00030157383846951547,
80
+ recommended: true,
81
+ evaluatedAt: "2026-01-24T10:58:07.496Z",
82
+ notes: "Auto-added by evaluation script.",
83
+ },
78
84
  "rename-event-parameters": {
79
85
  diffReductionImpact: 0,
80
86
  recommended: true,
@@ -101,9 +107,16 @@ const manifestData = {
101
107
  notes: "Unifies rename-loop-index-variables and rename-loop-index-variables-v2 without modifying older transforms. Measured with baseline none: 0.00%.",
102
108
  },
103
109
  "rename-parameters-to-match-properties": {
104
- diffReductionImpact: 0.00003774938185385768,
110
+ diffReductionImpact: 0,
111
+ recommended: false,
112
+ notes: "Superseded by rename-parameters-to-match-properties-v2.",
113
+ supersededBy: "rename-parameters-to-match-properties-v2",
114
+ },
115
+ "rename-parameters-to-match-properties-v2": {
116
+ diffReductionImpact: 0.00009424182452166807,
105
117
  recommended: true,
106
- notes: "Added manually based on high-confidence heuristic.",
118
+ evaluatedAt: "2026-01-24T09:58:42.363Z",
119
+ notes: "Extends v1 to also handle this.property = param assignments.",
107
120
  },
108
121
  "rename-promise-executor-parameters": {
109
122
  diffReductionImpact: 0,
@@ -12,11 +12,13 @@ import { renameCharcodeVariablesTransform } from "../rename-charcode-variables/r
12
12
  import { renameCharcodeVariablesV2Transform } from "../rename-charcode-variables-v2/rename-charcode-variables-v2-transform.js";
13
13
  import { renameComparisonFlagsTransform } from "../rename-comparison-flags/rename-comparison-flags-transform.js";
14
14
  import { renameDestructuredAliasesTransform } from "../rename-destructured-aliases/rename-destructured-aliases-transform.js";
15
+ import { renameErrorVariablesTransform } from "../rename-error-variables/rename-error-variables-transform.js";
15
16
  import { renameEventParametersTransform } from "../rename-event-parameters/rename-event-parameters-transform.js";
16
17
  import { renameLoopIndexVariablesTransform } from "../rename-loop-index-variables/rename-loop-index-variables-transform.js";
17
18
  import { renameLoopIndexVariablesV2Transform } from "../rename-loop-index-variables-v2/rename-loop-index-variables-v2-transform.js";
18
19
  import { renameLoopIndexVariablesV3Transform } from "../rename-loop-index-variables-v3/rename-loop-index-variables-v3-transform.js";
19
20
  import { renameParametersToMatchPropertiesTransform } from "../rename-parameters-to-match-properties/rename-parameters-to-match-properties-transform.js";
21
+ import { renameParametersToMatchPropertiesV2Transform } from "../rename-parameters-to-match-properties-v2/rename-parameters-to-match-properties-v2-transform.js";
20
22
  import { renamePromiseExecutorParametersTransform } from "../rename-promise-executor-parameters/rename-promise-executor-parameters-transform.js";
21
23
  import { renameReplaceChildParametersTransform } from "../rename-replace-child-parameters/rename-replace-child-parameters-transform.js";
22
24
  import { renameThisAliasesTransform } from "../rename-this-aliases/rename-this-aliases-transform.js";
@@ -39,11 +41,13 @@ export const transformRegistry = {
39
41
  [renameCharcodeVariablesV2Transform.id]: renameCharcodeVariablesV2Transform,
40
42
  [renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
41
43
  [renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
44
+ [renameErrorVariablesTransform.id]: renameErrorVariablesTransform,
42
45
  [renameEventParametersTransform.id]: renameEventParametersTransform,
43
46
  [renameLoopIndexVariablesTransform.id]: renameLoopIndexVariablesTransform,
44
47
  [renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
45
48
  [renameLoopIndexVariablesV3Transform.id]: renameLoopIndexVariablesV3Transform,
46
49
  [renameParametersToMatchPropertiesTransform.id]: renameParametersToMatchPropertiesTransform,
50
+ [renameParametersToMatchPropertiesV2Transform.id]: renameParametersToMatchPropertiesV2Transform,
47
51
  [renamePromiseExecutorParametersTransform.id]: renamePromiseExecutorParametersTransform,
48
52
  [renameReplaceChildParametersTransform.id]: renameReplaceChildParametersTransform,
49
53
  [renameThisAliasesTransform.id]: renameThisAliasesTransform,
@@ -0,0 +1,6 @@
1
+ {
2
+ "diffReductionImpact": 0.00030157383846951547,
3
+ "recommended": true,
4
+ "notes": "Auto-added by evaluation script.",
5
+ "evaluatedAt": "2026-01-24T10:58:07.496Z"
6
+ }
@@ -0,0 +1,2 @@
1
+ import { type Transform } from "../../core/types.js";
2
+ export declare const renameErrorVariablesTransform: Transform;
@@ -0,0 +1,81 @@
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
+ const BASE_NAME = "error";
8
+ const ERROR_CONSTRUCTORS = [
9
+ "Error",
10
+ "TypeError",
11
+ "RangeError",
12
+ "ReferenceError",
13
+ "SyntaxError",
14
+ "URIError",
15
+ "EvalError",
16
+ "AggregateError",
17
+ ];
18
+ /**
19
+ * Checks if a node is an Error call expression and returns the constructor name.
20
+ * Matches: Error("message"), new Error("message"), TypeError("..."), etc.
21
+ */
22
+ const getErrorConstructor = (node) => {
23
+ if (!node)
24
+ return undefined;
25
+ let calleeName = undefined;
26
+ if (node.type === "CallExpression" || node.type === "NewExpression") {
27
+ const callee = node.callee;
28
+ if (callee.type === "Identifier") {
29
+ calleeName = callee.name;
30
+ }
31
+ }
32
+ if (calleeName &&
33
+ ERROR_CONSTRUCTORS.includes(calleeName)) {
34
+ return calleeName;
35
+ }
36
+ return undefined;
37
+ };
38
+ export const renameErrorVariablesTransform = {
39
+ id: "rename-error-variables",
40
+ description: "Renames variables assigned error constructor calls (Error, TypeError, etc.) to $error/$error2/...",
41
+ scope: "file",
42
+ parallelizable: true,
43
+ transform(context) {
44
+ let nodesVisited = 0;
45
+ let transformationsApplied = 0;
46
+ for (const fileInfo of getFilesToProcess(context)) {
47
+ const group = new RenameGroup();
48
+ traverse(fileInfo.ast, {
49
+ VariableDeclarator(path) {
50
+ nodesVisited++;
51
+ const id = path.node.id;
52
+ const init = path.node.init;
53
+ // Only handle identifier bindings (not destructuring patterns)
54
+ if (id.type !== "Identifier")
55
+ return;
56
+ // Check if the init is an Error constructor call
57
+ const errorConstructor = getErrorConstructor(init);
58
+ if (!errorConstructor)
59
+ return;
60
+ // Skip if the error constructor is locally shadowed
61
+ if (path.scope.hasBinding(errorConstructor, true))
62
+ return;
63
+ const currentName = id.name;
64
+ // Skip already-stable names
65
+ if (isStableRenamed(currentName))
66
+ return;
67
+ group.add({
68
+ scope: path.scope,
69
+ currentName,
70
+ baseName: BASE_NAME,
71
+ });
72
+ },
73
+ });
74
+ transformationsApplied += group.apply();
75
+ }
76
+ return Promise.resolve({
77
+ nodesVisited,
78
+ transformationsApplied,
79
+ });
80
+ },
81
+ };
@@ -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.23.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",