miniread 1.115.4 → 1.116.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/preset-stats.json +2 -2
- package/dist/transforms-by-id/rename-char-code-at/manifest.json +7 -7
- package/dist/transforms-by-id/rename-char-code-at/rename-char-code-at-transform.js +91 -43
- package/dist/transforms-by-id/rename-client-aliases/manifest.json +6 -6
- package/dist/transforms-by-id/rename-client-aliases/rename-client-aliases-transform.js +40 -9
- package/dist/transforms-by-id/rename-file-reader-variables/manifest.json +4 -4
- package/dist/transforms-by-id/rename-file-reader-variables/rename-file-reader-variables-transform.js +3 -6
- package/dist/transforms-by-id/rename-indexeddb-request-variables/manifest.json +7 -7
- package/dist/transforms-by-id/rename-indexeddb-request-variables/rename-indexeddb-request-variables-transform.js +5 -2
- package/dist/transforms-by-id/rename-interval-ids/is-allowed-interval-handle-reference.d.ts +2 -0
- package/dist/transforms-by-id/rename-interval-ids/is-allowed-interval-handle-reference.js +3 -0
- package/dist/transforms-by-id/rename-interval-ids/manifest.json +6 -6
- package/dist/transforms-by-id/rename-interval-ids/rename-interval-ids-transform.js +35 -9
- package/dist/transforms-by-id/rename-loop-length-variables/get-loop-length-identifier.d.ts +4 -0
- package/dist/transforms-by-id/rename-loop-length-variables/get-loop-length-identifier.js +101 -0
- package/dist/transforms-by-id/rename-loop-length-variables/manifest.json +6 -6
- package/dist/transforms-by-id/rename-loop-length-variables/rename-loop-length-variables-transform.js +4 -43
- package/dist/transforms-by-id/rename-object-property-value-variables/collect-local-dynamic-lookup-scopes.d.ts +3 -0
- package/dist/transforms-by-id/rename-object-property-value-variables/collect-local-dynamic-lookup-scopes.js +37 -0
- package/dist/transforms-by-id/rename-object-property-value-variables/manifest.json +8 -8
- package/dist/transforms-by-id/rename-object-property-value-variables/rename-object-property-value-variables-transform.js +14 -8
- package/dist/transforms-by-id/rename-queue-traversal-variables/get-queue-traversal-loop.d.ts +9 -0
- package/dist/transforms-by-id/rename-queue-traversal-variables/get-queue-traversal-loop.js +58 -0
- package/dist/transforms-by-id/rename-queue-traversal-variables/get-queue-traversal-usage.d.ts +8 -0
- package/dist/transforms-by-id/rename-queue-traversal-variables/get-queue-traversal-usage.js +150 -0
- package/dist/transforms-by-id/rename-queue-traversal-variables/manifest.json +8 -8
- package/dist/transforms-by-id/rename-queue-traversal-variables/rename-queue-traversal-variables-transform.js +69 -18
- package/dist/transforms-by-id/rename-queue-traversal-variables/should-skip-queue-traversal-rename.d.ts +1 -0
- package/dist/transforms-by-id/rename-queue-traversal-variables/should-skip-queue-traversal-rename.js +8 -0
- package/dist/transforms-by-id/rename-read-file-lines/is-read-file-sync-wrapper-call.d.ts +3 -0
- package/dist/transforms-by-id/rename-read-file-lines/is-read-file-sync-wrapper-call.js +51 -0
- package/dist/transforms-by-id/rename-read-file-lines/manifest.json +7 -7
- package/dist/transforms-by-id/rename-read-file-lines/read-file-lines-call-pattern.js +6 -3
- package/dist/transforms-by-id/rename-replace-child-parameters/collect-replace-child-parameter-renames.js +2 -1
- package/dist/transforms-by-id/rename-replace-child-parameters/manifest.json +6 -6
- package/dist/transforms-by-id/rename-rest-parameters/manifest.json +6 -6
- package/dist/transforms-by-id/rename-rest-parameters/rename-rest-parameters-transform.js +12 -3
- package/dist/transforms-by-id/rename-typeof-variables/manifest.json +6 -6
- package/dist/transforms-by-id/rename-typeof-variables/rename-typeof-variables-transform.js +0 -3
- package/dist/transforms-by-id/rename-typescript-helper-aliases/manifest.json +8 -8
- package/dist/transforms-by-id/rename-typescript-helper-aliases/rename-typescript-helper-aliases-transform.js +22 -7
- package/package.json +1 -1
- package/dist/transforms-by-id/rename-queue-traversal-variables/queue-traversal-heuristics.d.ts +0 -14
- package/dist/transforms-by-id/rename-queue-traversal-variables/queue-traversal-heuristics.js +0 -145
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"recommended": true,
|
|
3
|
-
"recommendedOrder": 100,
|
|
4
2
|
"notes": "Measured with baseline none: 0.00%. Renames variables used in charCodeAt to improve readability.",
|
|
5
3
|
"evaluations": {
|
|
6
4
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
7
|
-
"diffSizePercent":
|
|
8
|
-
"evaluatedAt": "2026-02-
|
|
9
|
-
"changedLines":
|
|
10
|
-
"durationSeconds":
|
|
5
|
+
"diffSizePercent": 100,
|
|
6
|
+
"evaluatedAt": "2026-02-21T14:03:29.674Z",
|
|
7
|
+
"changedLines": 1766,
|
|
8
|
+
"durationSeconds": 49.117882333000004,
|
|
11
9
|
"stableNames": 1362
|
|
12
10
|
}
|
|
13
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"recommended": true,
|
|
13
|
+
"recommendedOrder": 100
|
|
14
14
|
}
|
|
@@ -4,6 +4,92 @@ import { getFilesToProcess, } from "../../core/types.js";
|
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
6
6
|
const traverse = require("@babel/traverse").default;
|
|
7
|
+
const visitCharCodeAtCall = (path, group, processedBindings) => {
|
|
8
|
+
const node = path.node;
|
|
9
|
+
const callee = node.callee;
|
|
10
|
+
if (callee.type !== "MemberExpression" &&
|
|
11
|
+
callee.type !== "OptionalMemberExpression")
|
|
12
|
+
return;
|
|
13
|
+
if (callee.computed)
|
|
14
|
+
return;
|
|
15
|
+
if (callee.property.type !== "Identifier")
|
|
16
|
+
return;
|
|
17
|
+
if (callee.property.name !== "charCodeAt")
|
|
18
|
+
return;
|
|
19
|
+
// Rename object (str)
|
|
20
|
+
if (callee.object.type === "Identifier") {
|
|
21
|
+
const currentName = callee.object.name;
|
|
22
|
+
const binding = path.scope.getBinding(currentName);
|
|
23
|
+
if (binding &&
|
|
24
|
+
!processedBindings.has(binding) &&
|
|
25
|
+
!isStableRenamed(currentName)) {
|
|
26
|
+
processedBindings.add(binding);
|
|
27
|
+
group.add({
|
|
28
|
+
scope: binding.scope,
|
|
29
|
+
currentName,
|
|
30
|
+
baseName: "str",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const argumentPaths = path.get("arguments");
|
|
35
|
+
if (!Array.isArray(argumentPaths))
|
|
36
|
+
return;
|
|
37
|
+
const firstArgumentPath = argumentPaths[0];
|
|
38
|
+
if (!firstArgumentPath)
|
|
39
|
+
return;
|
|
40
|
+
if (firstArgumentPath.isIdentifier()) {
|
|
41
|
+
const currentName = firstArgumentPath.node.name;
|
|
42
|
+
const binding = firstArgumentPath.scope.getBinding(currentName);
|
|
43
|
+
if (binding &&
|
|
44
|
+
!processedBindings.has(binding) &&
|
|
45
|
+
!isStableRenamed(currentName)) {
|
|
46
|
+
processedBindings.add(binding);
|
|
47
|
+
group.add({
|
|
48
|
+
scope: binding.scope,
|
|
49
|
+
currentName,
|
|
50
|
+
baseName: "index",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
firstArgumentPath.traverse({
|
|
56
|
+
Identifier(argumentIdentifierPath) {
|
|
57
|
+
if (!argumentIdentifierPath.isReferencedIdentifier())
|
|
58
|
+
return;
|
|
59
|
+
const parentPath = argumentIdentifierPath.parentPath;
|
|
60
|
+
if (parentPath.isMemberExpression({
|
|
61
|
+
object: argumentIdentifierPath.node,
|
|
62
|
+
}) ||
|
|
63
|
+
parentPath.isOptionalMemberExpression({
|
|
64
|
+
object: argumentIdentifierPath.node,
|
|
65
|
+
}) ||
|
|
66
|
+
parentPath.isCallExpression({
|
|
67
|
+
callee: argumentIdentifierPath.node,
|
|
68
|
+
}) ||
|
|
69
|
+
parentPath.isOptionalCallExpression({
|
|
70
|
+
callee: argumentIdentifierPath.node,
|
|
71
|
+
}) ||
|
|
72
|
+
parentPath.isNewExpression({
|
|
73
|
+
callee: argumentIdentifierPath.node,
|
|
74
|
+
})) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const currentName = argumentIdentifierPath.node.name;
|
|
78
|
+
const binding = argumentIdentifierPath.scope.getBinding(currentName);
|
|
79
|
+
if (!binding ||
|
|
80
|
+
processedBindings.has(binding) ||
|
|
81
|
+
isStableRenamed(currentName)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
processedBindings.add(binding);
|
|
85
|
+
group.add({
|
|
86
|
+
scope: binding.scope,
|
|
87
|
+
currentName,
|
|
88
|
+
baseName: "index",
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
};
|
|
7
93
|
export const renameCharCodeAtTransform = {
|
|
8
94
|
id: "rename-char-code-at",
|
|
9
95
|
description: "Renames variables used in charCodeAt calls (str.charCodeAt(index))",
|
|
@@ -18,49 +104,11 @@ export const renameCharCodeAtTransform = {
|
|
|
18
104
|
traverse(fileInfo.ast, {
|
|
19
105
|
CallExpression(path) {
|
|
20
106
|
nodesVisited++;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
if (callee.property.type !== "Identifier")
|
|
28
|
-
return;
|
|
29
|
-
if (callee.property.name !== "charCodeAt")
|
|
30
|
-
return;
|
|
31
|
-
// Rename object (str)
|
|
32
|
-
if (callee.object.type === "Identifier") {
|
|
33
|
-
const currentName = callee.object.name;
|
|
34
|
-
const binding = path.scope.getBinding(currentName);
|
|
35
|
-
if (binding &&
|
|
36
|
-
!processedBindings.has(binding) &&
|
|
37
|
-
!isStableRenamed(currentName)) {
|
|
38
|
-
processedBindings.add(binding);
|
|
39
|
-
group.add({
|
|
40
|
-
scope: binding.scope,
|
|
41
|
-
currentName,
|
|
42
|
-
baseName: "str",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Rename first argument (index)
|
|
47
|
-
if (node.arguments.length > 0) {
|
|
48
|
-
const firstArgument = node.arguments[0];
|
|
49
|
-
if (firstArgument?.type === "Identifier") {
|
|
50
|
-
const currentName = firstArgument.name;
|
|
51
|
-
const binding = path.scope.getBinding(currentName);
|
|
52
|
-
if (binding &&
|
|
53
|
-
!processedBindings.has(binding) &&
|
|
54
|
-
!isStableRenamed(currentName)) {
|
|
55
|
-
processedBindings.add(binding);
|
|
56
|
-
group.add({
|
|
57
|
-
scope: binding.scope,
|
|
58
|
-
currentName,
|
|
59
|
-
baseName: "index",
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
107
|
+
visitCharCodeAtCall(path, group, processedBindings);
|
|
108
|
+
},
|
|
109
|
+
OptionalCallExpression(path) {
|
|
110
|
+
nodesVisited++;
|
|
111
|
+
visitCharCodeAtCall(path, group, processedBindings);
|
|
64
112
|
},
|
|
65
113
|
});
|
|
66
114
|
transformationsApplied += group.apply();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"recommended": true,
|
|
3
|
-
"recommendedOrder": 100,
|
|
4
2
|
"notes": "Measured with baseline none: 0.00%. Added to recommended for readability.",
|
|
5
3
|
"evaluations": {
|
|
6
4
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
7
5
|
"diffSizePercent": 100,
|
|
8
|
-
"evaluatedAt": "2026-02-
|
|
9
|
-
"changedLines":
|
|
10
|
-
"durationSeconds":
|
|
6
|
+
"evaluatedAt": "2026-02-21T13:20:37.557Z",
|
|
7
|
+
"changedLines": 190,
|
|
8
|
+
"durationSeconds": 142.81505346600002,
|
|
11
9
|
"stableNames": 1358
|
|
12
10
|
}
|
|
13
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"recommended": true,
|
|
13
|
+
"recommendedOrder": 100
|
|
14
14
|
}
|
|
@@ -16,6 +16,37 @@ const isClientMemberExpression = (node) => {
|
|
|
16
16
|
}
|
|
17
17
|
return node.property.type === "Identifier" && node.property.name === "client";
|
|
18
18
|
};
|
|
19
|
+
const isClientProperty = (node) => {
|
|
20
|
+
if (node.computed)
|
|
21
|
+
return false;
|
|
22
|
+
if (node.key.type === "Identifier")
|
|
23
|
+
return node.key.name === "client";
|
|
24
|
+
if (node.key.type === "StringLiteral")
|
|
25
|
+
return node.key.value === "client";
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
const getClientAliasName = (path) => {
|
|
29
|
+
const id = path.node.id;
|
|
30
|
+
if (id.type === "Identifier")
|
|
31
|
+
return id.name;
|
|
32
|
+
if (id.type !== "ObjectPattern")
|
|
33
|
+
return undefined;
|
|
34
|
+
if (!path.node.init)
|
|
35
|
+
return undefined;
|
|
36
|
+
for (const property of id.properties) {
|
|
37
|
+
if (property.type !== "ObjectProperty")
|
|
38
|
+
continue;
|
|
39
|
+
if (!isClientProperty(property))
|
|
40
|
+
continue;
|
|
41
|
+
if (property.value.type === "Identifier")
|
|
42
|
+
return property.value.name;
|
|
43
|
+
if (property.value.type === "AssignmentPattern" &&
|
|
44
|
+
property.value.left.type === "Identifier") {
|
|
45
|
+
return property.value.left.name;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
19
50
|
export const renameClientAliasesTransform = {
|
|
20
51
|
id: "rename-client-aliases",
|
|
21
52
|
description: "Renames aliases of *.client to $client/$client2/...",
|
|
@@ -30,17 +61,17 @@ export const renameClientAliasesTransform = {
|
|
|
30
61
|
traverse(fileInfo.ast, {
|
|
31
62
|
VariableDeclarator(path) {
|
|
32
63
|
nodesVisited++;
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
64
|
+
const clientAliasName = getClientAliasName(path);
|
|
65
|
+
if (!clientAliasName)
|
|
35
66
|
return;
|
|
36
|
-
if (isStableRenamed(
|
|
67
|
+
if (isStableRenamed(clientAliasName))
|
|
37
68
|
return;
|
|
38
69
|
const init = path.node.init;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!
|
|
70
|
+
const fromMemberExpression = init?.type === "MemberExpression" && isClientMemberExpression(init);
|
|
71
|
+
const fromObjectPattern = path.node.id.type === "ObjectPattern";
|
|
72
|
+
if (!fromMemberExpression && !fromObjectPattern)
|
|
42
73
|
return;
|
|
43
|
-
const binding = path.scope.getBinding(
|
|
74
|
+
const binding = path.scope.getBinding(clientAliasName);
|
|
44
75
|
if (!binding)
|
|
45
76
|
return;
|
|
46
77
|
if (!binding.constant)
|
|
@@ -48,12 +79,12 @@ export const renameClientAliasesTransform = {
|
|
|
48
79
|
if (binding.referencePaths.length === 0)
|
|
49
80
|
return;
|
|
50
81
|
if (binding.scope.block.type === "Program" &&
|
|
51
|
-
exportedNames.has(
|
|
82
|
+
exportedNames.has(clientAliasName)) {
|
|
52
83
|
return;
|
|
53
84
|
}
|
|
54
85
|
group.add({
|
|
55
86
|
scope: binding.scope,
|
|
56
|
-
currentName:
|
|
87
|
+
currentName: clientAliasName,
|
|
57
88
|
baseName: BASE_NAME,
|
|
58
89
|
});
|
|
59
90
|
},
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"evaluations": {
|
|
4
4
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
5
5
|
"diffSizePercent": 100,
|
|
6
|
-
"evaluatedAt": "2026-02-
|
|
7
|
-
"changedLines":
|
|
8
|
-
"durationSeconds":
|
|
9
|
-
"stableNames":
|
|
6
|
+
"evaluatedAt": "2026-02-21T10:23:01.538Z",
|
|
7
|
+
"changedLines": 46,
|
|
8
|
+
"durationSeconds": 38.284109375,
|
|
9
|
+
"stableNames": 1358
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"recommended": true,
|
package/dist/transforms-by-id/rename-file-reader-variables/rename-file-reader-variables-transform.js
CHANGED
|
@@ -6,8 +6,6 @@ import { queueFileReaderEventRename } from "./queue-file-reader-event-rename.js"
|
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
8
8
|
const traverse = require("@babel/traverse").default;
|
|
9
|
-
const FILE_READER_BINDING_PATTERN = /^\$?fileReader(?:Instance)?\d*$/u;
|
|
10
|
-
const isTrackedFileReaderBindingName = (name) => FILE_READER_BINDING_PATTERN.test(name);
|
|
11
9
|
const getMemberPropertyName = (memberExpression) => {
|
|
12
10
|
if (!memberExpression.computed) {
|
|
13
11
|
if (!t.isIdentifier(memberExpression.property))
|
|
@@ -61,7 +59,9 @@ export const renameFileReaderVariablesTransform = {
|
|
|
61
59
|
nodesVisited++;
|
|
62
60
|
if (path.node.id.type !== "Identifier")
|
|
63
61
|
return;
|
|
64
|
-
if (!
|
|
62
|
+
if (!path.node.init)
|
|
63
|
+
return;
|
|
64
|
+
if (!isFileReaderConstructorExpression(path.node.init))
|
|
65
65
|
return;
|
|
66
66
|
const binding = path.scope.getBinding(path.node.id.name);
|
|
67
67
|
if (!binding)
|
|
@@ -76,9 +76,6 @@ export const renameFileReaderVariablesTransform = {
|
|
|
76
76
|
if (!binding) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
if (!isTrackedFileReaderBindingName(binding.identifier.name)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
79
|
if (operator !== "=") {
|
|
83
80
|
fileReaderBindings.delete(binding);
|
|
84
81
|
return;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"recommended": true,
|
|
3
|
-
"recommendedOrder": 100,
|
|
4
2
|
"evaluations": {
|
|
5
3
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
6
4
|
"diffSizePercent": 100,
|
|
7
|
-
"evaluatedAt": "2026-02-
|
|
8
|
-
"changedLines":
|
|
9
|
-
"durationSeconds":
|
|
10
|
-
"stableNames":
|
|
5
|
+
"evaluatedAt": "2026-02-21T10:25:57.574Z",
|
|
6
|
+
"changedLines": 30,
|
|
7
|
+
"durationSeconds": 29.580905417,
|
|
8
|
+
"stableNames": 1358
|
|
11
9
|
}
|
|
12
|
-
}
|
|
10
|
+
},
|
|
11
|
+
"recommended": true,
|
|
12
|
+
"recommendedOrder": 100
|
|
13
13
|
}
|
|
@@ -4,7 +4,7 @@ import { collectExportedNames } from "../../core/collect-exported-names.js";
|
|
|
4
4
|
import { isStableRenamed, RenameGroup } from "../../core/stable-naming.js";
|
|
5
5
|
import { getFilesToProcess, } from "../../core/types.js";
|
|
6
6
|
import { getBindingStableStart } from "../../transforms/get-binding-stable-start.js";
|
|
7
|
-
import {
|
|
7
|
+
import { detectDynamicNameLookup } from "../../transforms/dynamic-name-lookup/detect-dynamic-name-lookup.js";
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
10
10
|
const traverse = require("@babel/traverse").default;
|
|
@@ -25,7 +25,10 @@ export const renameIndexeddbRequestVariablesTransform = {
|
|
|
25
25
|
let nodesVisited = 0;
|
|
26
26
|
let transformationsApplied = 0;
|
|
27
27
|
for (const fileInfo of getFilesToProcess(context)) {
|
|
28
|
-
|
|
28
|
+
const dynamicNameLookup = detectDynamicNameLookup(fileInfo.ast, {
|
|
29
|
+
stopEarly: true,
|
|
30
|
+
});
|
|
31
|
+
if (dynamicNameLookup.hasLocalScopeDynamicNameLookup)
|
|
29
32
|
continue;
|
|
30
33
|
const renameCandidatesByScope = new Map();
|
|
31
34
|
const isScript = fileInfo.ast.program.sourceType === "script";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"recommended": true,
|
|
3
|
-
"recommendedOrder": 100,
|
|
4
2
|
"evaluations": {
|
|
5
3
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
6
4
|
"diffSizePercent": 100,
|
|
7
|
-
"evaluatedAt": "2026-02-
|
|
8
|
-
"changedLines":
|
|
9
|
-
"durationSeconds":
|
|
5
|
+
"evaluatedAt": "2026-02-21T13:56:01.303Z",
|
|
6
|
+
"changedLines": 74,
|
|
7
|
+
"durationSeconds": 40.303941625,
|
|
10
8
|
"stableNames": 1358
|
|
11
9
|
}
|
|
12
|
-
}
|
|
10
|
+
},
|
|
11
|
+
"recommended": true,
|
|
12
|
+
"recommendedOrder": 100
|
|
13
13
|
}
|
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { isStableRenamed, RenameGroup } from "../../core/stable-naming.js";
|
|
3
|
+
import { isAllowedIntervalHandleReference } from "./is-allowed-interval-handle-reference.js";
|
|
3
4
|
import { getFilesToProcess, } from "../../core/types.js";
|
|
4
5
|
const require = createRequire(import.meta.url);
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
6
7
|
const traverse = require("@babel/traverse").default;
|
|
7
8
|
const BASE_NAME = "intervalId";
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
9
|
+
const hasExpectedMemberProperty = (callee, expectedMethodName) => {
|
|
10
|
+
if (!callee.computed) {
|
|
11
|
+
if (callee.property.type !== "Identifier")
|
|
12
|
+
return false;
|
|
13
|
+
return callee.property.name === expectedMethodName;
|
|
14
|
+
}
|
|
15
|
+
if (callee.property.type !== "StringLiteral")
|
|
16
|
+
return false;
|
|
17
|
+
return callee.property.value === expectedMethodName;
|
|
18
|
+
};
|
|
19
|
+
const isGlobalTimerMemberCall = (callee, expectedMethodName, hasLocalBinding) => {
|
|
20
|
+
if (callee.type !== "MemberExpression")
|
|
21
|
+
return false;
|
|
22
|
+
if (callee.object.type !== "Identifier")
|
|
10
23
|
return false;
|
|
11
|
-
if (
|
|
24
|
+
if (!hasExpectedMemberProperty(callee, expectedMethodName))
|
|
25
|
+
return false;
|
|
26
|
+
if (callee.object.name !== "window" &&
|
|
27
|
+
callee.object.name !== "globalThis" &&
|
|
28
|
+
callee.object.name !== "self")
|
|
29
|
+
return false;
|
|
30
|
+
if (hasLocalBinding(callee.object.name))
|
|
31
|
+
return false;
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const isSetIntervalCall = (path, init) => {
|
|
35
|
+
if (!((init.callee.type === "Identifier" &&
|
|
36
|
+
init.callee.name === "setInterval") ||
|
|
37
|
+
isGlobalTimerMemberCall(init.callee, "setInterval", (name) => path.scope.hasBinding(name, true))))
|
|
12
38
|
return false;
|
|
13
39
|
// If setInterval is locally bound (imported or declared), semantics may differ.
|
|
14
40
|
if (path.scope.hasBinding("setInterval", true))
|
|
@@ -22,9 +48,9 @@ const isClearIntervalCallArgument = (referencePath, bindingName) => {
|
|
|
22
48
|
if (!callPath.isCallExpression())
|
|
23
49
|
return false;
|
|
24
50
|
const call = callPath.node;
|
|
25
|
-
if (call.callee.type
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
if (!((call.callee.type === "Identifier" &&
|
|
52
|
+
call.callee.name === "clearInterval") ||
|
|
53
|
+
isGlobalTimerMemberCall(call.callee, "clearInterval", (name) => callPath.scope.hasBinding(name, true))))
|
|
28
54
|
return false;
|
|
29
55
|
// If clearInterval is locally bound (imported or declared), semantics may differ.
|
|
30
56
|
if (callPath.scope.hasBinding("clearInterval", true))
|
|
@@ -65,11 +91,11 @@ export const renameIntervalIdsTransform = {
|
|
|
65
91
|
const binding = path.scope.getBinding(id.name);
|
|
66
92
|
if (!binding)
|
|
67
93
|
return;
|
|
68
|
-
if (!binding.constant)
|
|
69
|
-
return;
|
|
70
94
|
if (binding.referencePaths.length === 0)
|
|
71
95
|
return;
|
|
72
|
-
if (!binding.referencePaths.
|
|
96
|
+
if (!binding.referencePaths.some((referencePath) => isClearIntervalCallArgument(referencePath, id.name)))
|
|
97
|
+
return;
|
|
98
|
+
if (!binding.referencePaths.every((referencePath) => isAllowedIntervalHandleReference(referencePath, (path) => isClearIntervalCallArgument(path, id.name))))
|
|
73
99
|
return;
|
|
74
100
|
group.add({
|
|
75
101
|
scope: path.scope,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/traverse";
|
|
2
|
+
import type { ForStatement, Identifier, VariableDeclaration } from "@babel/types";
|
|
3
|
+
export declare const LOOP_LENGTH_BASE_NAME = "length";
|
|
4
|
+
export declare const getLoopLengthIdentifier: (loopPath: NodePath<ForStatement>, init: VariableDeclaration) => Identifier | undefined;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export const LOOP_LENGTH_BASE_NAME = "length";
|
|
2
|
+
const isLengthMemberExpression = (init) => {
|
|
3
|
+
if (!init)
|
|
4
|
+
return false;
|
|
5
|
+
if (init.type !== "MemberExpression")
|
|
6
|
+
return false;
|
|
7
|
+
if (init.computed) {
|
|
8
|
+
return (init.property.type === "StringLiteral" &&
|
|
9
|
+
init.property.value === LOOP_LENGTH_BASE_NAME);
|
|
10
|
+
}
|
|
11
|
+
return (init.property.type === "Identifier" &&
|
|
12
|
+
init.property.name === LOOP_LENGTH_BASE_NAME);
|
|
13
|
+
};
|
|
14
|
+
const isReferenceInLoopTest = (referencePath, loopPath) => {
|
|
15
|
+
const test = loopPath.node.test;
|
|
16
|
+
if (!test)
|
|
17
|
+
return false;
|
|
18
|
+
return (referencePath.findParent((ancestorPath) => ancestorPath.node === test) !==
|
|
19
|
+
null);
|
|
20
|
+
};
|
|
21
|
+
const isReferenceInDeclaratorInit = (referencePath, declarator) => {
|
|
22
|
+
const init = declarator.init;
|
|
23
|
+
if (!init)
|
|
24
|
+
return false;
|
|
25
|
+
return (referencePath.findParent((ancestorPath) => ancestorPath.node === init) !==
|
|
26
|
+
null);
|
|
27
|
+
};
|
|
28
|
+
const getDeclaratorsByName = (init) => {
|
|
29
|
+
const declaratorsByName = new Map();
|
|
30
|
+
for (const declarator of init.declarations) {
|
|
31
|
+
if (declarator.id.type !== "Identifier")
|
|
32
|
+
continue;
|
|
33
|
+
declaratorsByName.set(declarator.id.name, declarator);
|
|
34
|
+
}
|
|
35
|
+
return declaratorsByName;
|
|
36
|
+
};
|
|
37
|
+
const getDirectTestReferenceNames = (loopPath, declaratorsByName) => {
|
|
38
|
+
const directNames = new Set();
|
|
39
|
+
for (const name of declaratorsByName.keys()) {
|
|
40
|
+
const binding = loopPath.scope.getBinding(name);
|
|
41
|
+
if (!binding)
|
|
42
|
+
continue;
|
|
43
|
+
if (binding.referencePaths.some((referencePath) => isReferenceInLoopTest(referencePath, loopPath))) {
|
|
44
|
+
directNames.add(name);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return directNames;
|
|
48
|
+
};
|
|
49
|
+
const getDeclaratorDependencyNames = (loopPath, declaratorsByName, seedNames) => {
|
|
50
|
+
const dependencyNames = new Set(seedNames);
|
|
51
|
+
let didChange = true;
|
|
52
|
+
while (didChange) {
|
|
53
|
+
didChange = false;
|
|
54
|
+
for (const [name] of declaratorsByName) {
|
|
55
|
+
if (dependencyNames.has(name))
|
|
56
|
+
continue;
|
|
57
|
+
const binding = loopPath.scope.getBinding(name);
|
|
58
|
+
if (!binding)
|
|
59
|
+
continue;
|
|
60
|
+
let contributesToSeed = false;
|
|
61
|
+
for (const dependentName of dependencyNames) {
|
|
62
|
+
const dependentDeclarator = declaratorsByName.get(dependentName);
|
|
63
|
+
if (!dependentDeclarator)
|
|
64
|
+
continue;
|
|
65
|
+
if (binding.referencePaths.some((referencePath) => isReferenceInDeclaratorInit(referencePath, dependentDeclarator))) {
|
|
66
|
+
contributesToSeed = true;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!contributesToSeed)
|
|
71
|
+
continue;
|
|
72
|
+
dependencyNames.add(name);
|
|
73
|
+
didChange = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return dependencyNames;
|
|
77
|
+
};
|
|
78
|
+
const findLengthIdentifier = (loopPath, init, candidateNames) => {
|
|
79
|
+
for (const declarator of init.declarations) {
|
|
80
|
+
if (declarator.id.type !== "Identifier")
|
|
81
|
+
continue;
|
|
82
|
+
if (!isLengthMemberExpression(declarator.init))
|
|
83
|
+
continue;
|
|
84
|
+
if (!candidateNames.has(declarator.id.name))
|
|
85
|
+
continue;
|
|
86
|
+
const binding = loopPath.scope.getBinding(declarator.id.name);
|
|
87
|
+
if (!binding)
|
|
88
|
+
continue;
|
|
89
|
+
return declarator.id;
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
};
|
|
93
|
+
export const getLoopLengthIdentifier = (loopPath, init) => {
|
|
94
|
+
const declaratorsByName = getDeclaratorsByName(init);
|
|
95
|
+
const directTestReferenceNames = getDirectTestReferenceNames(loopPath, declaratorsByName);
|
|
96
|
+
const direct = findLengthIdentifier(loopPath, init, directTestReferenceNames);
|
|
97
|
+
if (direct)
|
|
98
|
+
return direct;
|
|
99
|
+
const dependencyNames = getDeclaratorDependencyNames(loopPath, declaratorsByName, directTestReferenceNames);
|
|
100
|
+
return findLengthIdentifier(loopPath, init, dependencyNames);
|
|
101
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"recommended": true,
|
|
3
|
-
"recommendedOrder": 100,
|
|
4
2
|
"notes": "Measured with baseline none: 0.00%.",
|
|
5
3
|
"evaluations": {
|
|
6
4
|
"claude-code-2.1.10:claude-code-2.1.11": {
|
|
7
5
|
"diffSizePercent": 100,
|
|
8
|
-
"evaluatedAt": "2026-02-
|
|
9
|
-
"changedLines":
|
|
10
|
-
"durationSeconds":
|
|
6
|
+
"evaluatedAt": "2026-02-21T14:03:56.369Z",
|
|
7
|
+
"changedLines": 214,
|
|
8
|
+
"durationSeconds": 41.69858095800001,
|
|
11
9
|
"stableNames": 1358
|
|
12
10
|
}
|
|
13
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"recommended": true,
|
|
13
|
+
"recommendedOrder": 100
|
|
14
14
|
}
|