miniread 1.20.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,
@@ -129,6 +136,10 @@ const manifestData = {
129
136
  evaluatedAt: "2026-01-23T10:29:23.279Z",
130
137
  notes: "Measured with baseline none: 0.00%. Added to recommended for readability.",
131
138
  },
139
+ "rename-typeof-variables": {
140
+ diffReductionImpact: 0,
141
+ recommended: true,
142
+ },
132
143
  "rename-use-reference-guards": {
133
144
  diffReductionImpact: 0,
134
145
  recommended: false,
@@ -17,10 +17,12 @@ 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";
23
24
  import { renameTimeoutIdsTransform } from "../rename-timeout-ids/rename-timeout-ids-transform.js";
25
+ import { renameTypeofVariablesTransform } from "../rename-typeof-variables/rename-typeof-variables-transform.js";
24
26
  import { renameUseReferenceGuardsTransform } from "../rename-use-reference-guards/rename-use-reference-guards-transform.js";
25
27
  import { renameUseReferenceGuardsV2Transform } from "../rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js";
26
28
  import { simplifyBooleanNegationsTransform } from "../simplify-boolean-negations/simplify-boolean-negations-transform.js";
@@ -43,10 +45,12 @@ export const transformRegistry = {
43
45
  [renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
44
46
  [renameLoopIndexVariablesV3Transform.id]: renameLoopIndexVariablesV3Transform,
45
47
  [renameParametersToMatchPropertiesTransform.id]: renameParametersToMatchPropertiesTransform,
48
+ [renameParametersToMatchPropertiesV2Transform.id]: renameParametersToMatchPropertiesV2Transform,
46
49
  [renamePromiseExecutorParametersTransform.id]: renamePromiseExecutorParametersTransform,
47
50
  [renameReplaceChildParametersTransform.id]: renameReplaceChildParametersTransform,
48
51
  [renameThisAliasesTransform.id]: renameThisAliasesTransform,
49
52
  [renameTimeoutIdsTransform.id]: renameTimeoutIdsTransform,
53
+ [renameTypeofVariablesTransform.id]: renameTypeofVariablesTransform,
50
54
  [renameUseReferenceGuardsTransform.id]: renameUseReferenceGuardsTransform,
51
55
  [renameUseReferenceGuardsV2Transform.id]: renameUseReferenceGuardsV2Transform,
52
56
  [simplifyBooleanNegationsTransform.id]: simplifyBooleanNegationsTransform,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "recommended": {
3
- "diffReductionImpact": 0.003690002076215948,
4
- "notes": "Measured with baseline none: 0.37%."
3
+ "diffReductionImpact": 0.001470172462538888,
4
+ "notes": "Measured with baseline none: 0.15%."
5
5
  }
6
6
  }
@@ -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
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "diffReductionImpact": 0,
3
+ "recommended": true
4
+ }
@@ -0,0 +1,2 @@
1
+ import { type Transform } from "../../core/types.js";
2
+ export declare const renameTypeofVariablesTransform: Transform;
@@ -0,0 +1,132 @@
1
+ import { createRequire } from "node:module";
2
+ import { isArrayPattern, isAssignmentPattern, isClassDeclaration, isExportNamedDeclaration, isExportSpecifier, isFunctionDeclaration, isIdentifier, isObjectPattern, isObjectProperty, isRestElement, isVariableDeclaration, } 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 = "type";
9
+ const addBindingNamesFromNode = (node, out) => {
10
+ const babelNode = node;
11
+ if (!babelNode)
12
+ return;
13
+ if (babelNode.type === "VoidPattern")
14
+ return;
15
+ if (isIdentifier(babelNode)) {
16
+ out.add(babelNode.name);
17
+ return;
18
+ }
19
+ if (isObjectPattern(babelNode)) {
20
+ for (const property of babelNode.properties) {
21
+ if (isRestElement(property)) {
22
+ addBindingNamesFromNode(property.argument, out);
23
+ continue;
24
+ }
25
+ if (!isObjectProperty(property))
26
+ continue;
27
+ addBindingNamesFromNode(property.value, out);
28
+ }
29
+ return;
30
+ }
31
+ if (isArrayPattern(babelNode)) {
32
+ for (const element of babelNode.elements) {
33
+ addBindingNamesFromNode(element, out);
34
+ }
35
+ return;
36
+ }
37
+ if (isRestElement(babelNode)) {
38
+ addBindingNamesFromNode(babelNode.argument, out);
39
+ return;
40
+ }
41
+ if (isAssignmentPattern(babelNode)) {
42
+ addBindingNamesFromNode(babelNode.left, out);
43
+ }
44
+ };
45
+ const collectExportedNames = (program) => {
46
+ const exportedNames = new Set();
47
+ for (const statement of program.body) {
48
+ if (!isExportNamedDeclaration(statement))
49
+ continue;
50
+ const declaration = statement.declaration;
51
+ if (declaration) {
52
+ if (isVariableDeclaration(declaration)) {
53
+ for (const declarator of declaration.declarations) {
54
+ addBindingNamesFromNode(declarator.id, exportedNames);
55
+ }
56
+ }
57
+ else if (isFunctionDeclaration(declaration) ||
58
+ isClassDeclaration(declaration)) {
59
+ const id = declaration.id;
60
+ if (!id)
61
+ continue;
62
+ exportedNames.add(id.name);
63
+ }
64
+ }
65
+ for (const specifier of statement.specifiers) {
66
+ if (!isExportSpecifier(specifier))
67
+ continue;
68
+ const local = specifier.local;
69
+ if (!isIdentifier(local))
70
+ continue;
71
+ exportedNames.add(local.name);
72
+ }
73
+ }
74
+ return exportedNames;
75
+ };
76
+ export const renameTypeofVariablesTransform = {
77
+ id: "rename-typeof-variables",
78
+ description: "Renames variables assigned from typeof expressions to $type (stable when unique) or type/type2/...",
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
+ const exportedNames = collectExportedNames(fileInfo.ast.program);
87
+ traverse(fileInfo.ast, {
88
+ VariableDeclarator(path) {
89
+ nodesVisited++;
90
+ const id = path.node.id;
91
+ if (id.type !== "Identifier")
92
+ return;
93
+ const init = path.node.init;
94
+ if (!init)
95
+ return;
96
+ if (init.type !== "UnaryExpression")
97
+ return;
98
+ if (init.operator !== "typeof")
99
+ return;
100
+ const currentName = id.name;
101
+ // Skip already-stable names
102
+ if (isStableRenamed(currentName))
103
+ return;
104
+ // Skip non-minified names (more than 1 character)
105
+ if (currentName.length > 1)
106
+ return;
107
+ const binding = path.scope.getBinding(currentName);
108
+ if (!binding)
109
+ return;
110
+ // Skip reassigned variables (name would be misleading)
111
+ if (!binding.constant)
112
+ return;
113
+ // Skip exported names at program scope
114
+ if (binding.scope.block.type === "Program" &&
115
+ exportedNames.has(currentName)) {
116
+ return;
117
+ }
118
+ group.add({
119
+ scope: binding.scope,
120
+ currentName,
121
+ baseName: BASE_NAME,
122
+ });
123
+ },
124
+ });
125
+ transformationsApplied += group.apply();
126
+ }
127
+ return Promise.resolve({
128
+ nodesVisited,
129
+ transformationsApplied,
130
+ });
131
+ },
132
+ };
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.20.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",