miniread 1.22.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.
- package/dist/transforms/_generated/manifest.js +6 -0
- package/dist/transforms/_generated/registry.js +2 -0
- package/dist/transforms/rename-error-variables/manifest.json +6 -0
- package/dist/transforms/rename-error-variables/rename-error-variables-transform.d.ts +2 -0
- package/dist/transforms/rename-error-variables/rename-error-variables-transform.js +81 -0
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -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";
|
|
@@ -40,6 +41,7 @@ export const transformRegistry = {
|
|
|
40
41
|
[renameCharcodeVariablesV2Transform.id]: renameCharcodeVariablesV2Transform,
|
|
41
42
|
[renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
|
|
42
43
|
[renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
|
|
44
|
+
[renameErrorVariablesTransform.id]: renameErrorVariablesTransform,
|
|
43
45
|
[renameEventParametersTransform.id]: renameEventParametersTransform,
|
|
44
46
|
[renameLoopIndexVariablesTransform.id]: renameLoopIndexVariablesTransform,
|
|
45
47
|
[renameLoopIndexVariablesV2Transform.id]: renameLoopIndexVariablesV2Transform,
|
|
@@ -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
|
+
};
|
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.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",
|