miniread 1.22.0 → 1.24.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,
@@ -124,6 +130,10 @@ const manifestData = {
124
130
  evaluatedAt: "2026-01-23T17:28:09.184Z",
125
131
  notes: "Measured with baseline none: 0.00%.",
126
132
  },
133
+ "rename-rest-parameters": {
134
+ diffReductionImpact: 0,
135
+ recommended: true,
136
+ },
127
137
  "rename-this-aliases": {
128
138
  diffReductionImpact: 0.00003774938185385768,
129
139
  recommended: true,
@@ -12,6 +12,7 @@ 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";
@@ -20,6 +21,7 @@ import { renameParametersToMatchPropertiesTransform } from "../rename-parameters
20
21
  import { renameParametersToMatchPropertiesV2Transform } from "../rename-parameters-to-match-properties-v2/rename-parameters-to-match-properties-v2-transform.js";
21
22
  import { renamePromiseExecutorParametersTransform } from "../rename-promise-executor-parameters/rename-promise-executor-parameters-transform.js";
22
23
  import { renameReplaceChildParametersTransform } from "../rename-replace-child-parameters/rename-replace-child-parameters-transform.js";
24
+ import { renameRestParametersTransform } from "../rename-rest-parameters/rename-rest-parameters-transform.js";
23
25
  import { renameThisAliasesTransform } from "../rename-this-aliases/rename-this-aliases-transform.js";
24
26
  import { renameTimeoutIdsTransform } from "../rename-timeout-ids/rename-timeout-ids-transform.js";
25
27
  import { renameTypeofVariablesTransform } from "../rename-typeof-variables/rename-typeof-variables-transform.js";
@@ -40,6 +42,7 @@ export const transformRegistry = {
40
42
  [renameCharcodeVariablesV2Transform.id]: renameCharcodeVariablesV2Transform,
41
43
  [renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
42
44
  [renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
45
+ [renameErrorVariablesTransform.id]: renameErrorVariablesTransform,
43
46
  [renameEventParametersTransform.id]: renameEventParametersTransform,
44
47
  [renameLoopIndexVariablesTransform.id]: renameLoopIndexVariablesTransform,
45
48
  [renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
@@ -48,6 +51,7 @@ export const transformRegistry = {
48
51
  [renameParametersToMatchPropertiesV2Transform.id]: renameParametersToMatchPropertiesV2Transform,
49
52
  [renamePromiseExecutorParametersTransform.id]: renamePromiseExecutorParametersTransform,
50
53
  [renameReplaceChildParametersTransform.id]: renameReplaceChildParametersTransform,
54
+ [renameRestParametersTransform.id]: renameRestParametersTransform,
51
55
  [renameThisAliasesTransform.id]: renameThisAliasesTransform,
52
56
  [renameTimeoutIdsTransform.id]: renameTimeoutIdsTransform,
53
57
  [renameTypeofVariablesTransform.id]: renameTypeofVariablesTransform,
@@ -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
+ };
@@ -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 renameRestParametersTransform: Transform;
@@ -0,0 +1,62 @@
1
+ import { createRequire } from "node:module";
2
+ import { isIdentifier } from "@babel/types";
3
+ import { RenameGroup, isStableRenamed } 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 = "args";
9
+ const getRestParameter = (parameters) => {
10
+ const lastParameter = parameters.at(-1);
11
+ if (!lastParameter)
12
+ return undefined;
13
+ if (lastParameter.type !== "RestElement")
14
+ return undefined;
15
+ return lastParameter;
16
+ };
17
+ export const renameRestParametersTransform = {
18
+ id: "rename-rest-parameters",
19
+ description: "Renames rest parameters to $args (stable when unique)",
20
+ scope: "file",
21
+ parallelizable: true,
22
+ transform(context) {
23
+ let nodesVisited = 0;
24
+ let transformationsApplied = 0;
25
+ for (const fileInfo of getFilesToProcess(context)) {
26
+ const group = new RenameGroup();
27
+ traverse(fileInfo.ast, {
28
+ Function(path) {
29
+ nodesVisited++;
30
+ const restParameter = getRestParameter(path.node.params);
31
+ if (!restParameter)
32
+ return;
33
+ const argument = restParameter.argument;
34
+ if (!isIdentifier(argument))
35
+ return;
36
+ const currentName = argument.name;
37
+ if (isStableRenamed(currentName))
38
+ return;
39
+ if (currentName.length > 2)
40
+ return;
41
+ const binding = path.scope.getBinding(currentName);
42
+ if (!binding)
43
+ return;
44
+ if (!binding.constant)
45
+ return;
46
+ if (binding.referencePaths.length === 0)
47
+ return;
48
+ group.add({
49
+ scope: path.scope,
50
+ currentName,
51
+ baseName: BASE_NAME,
52
+ });
53
+ },
54
+ });
55
+ transformationsApplied += group.apply();
56
+ }
57
+ return Promise.resolve({
58
+ nodesVisited,
59
+ transformationsApplied,
60
+ });
61
+ },
62
+ };
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.22.0",
5
+ "version": "1.24.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",