miniread 1.6.0 → 1.8.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/bin/miniread-snapshot +17 -0
- package/dist/core/normalize-code.d.ts +17 -0
- package/dist/core/normalize-code.js +35 -0
- package/dist/core/stable-naming.d.ts +61 -0
- package/dist/core/stable-naming.js +121 -0
- package/dist/scripts/evaluate/check-expected-evaluations.js +2 -0
- package/dist/scripts/evaluate/check-recommended-snapshot.d.ts +11 -0
- package/dist/scripts/evaluate/check-recommended-snapshot.js +53 -0
- package/dist/scripts/evaluate/check-snapshots.d.ts +1 -0
- package/dist/scripts/evaluate/check-snapshots.js +21 -2
- package/dist/scripts/evaluate/transform-content.d.ts +5 -0
- package/dist/scripts/evaluate/transform-content.js +23 -13
- package/dist/scripts/snapshot/create-snapshot-command.d.ts +9 -0
- package/dist/scripts/snapshot/create-snapshot-command.js +32 -0
- package/dist/scripts/snapshot/run-snapshot-cli.d.ts +1 -0
- package/dist/scripts/snapshot/run-snapshot-cli.js +162 -0
- package/dist/scripts/snapshot.d.ts +2 -0
- package/dist/scripts/snapshot.js +13 -0
- package/dist/transforms/rename-catch-parameters/rename-catch-parameters-transform.js +15 -38
- package/dist/transforms/rename-destructured-aliases/rename-destructured-aliases-transform.js +13 -12
- package/dist/transforms/rename-event-parameters/process-event-handler-function.d.ts +2 -3
- package/dist/transforms/rename-event-parameters/process-event-handler-function.js +13 -9
- package/dist/transforms/rename-event-parameters/rename-event-parameters-transform.d.ts +1 -1
- package/dist/transforms/rename-event-parameters/rename-event-parameters-transform.js +10 -7
- package/dist/transforms/rename-loop-index-variables/rename-loop-index-variables-transform.js +19 -13
- package/dist/transforms/rename-promise-executor-parameters/rename-promise-executor-parameters-transform.js +12 -5
- package/dist/transforms/rename-timeout-ids/rename-timeout-ids-transform.d.ts +1 -1
- package/dist/transforms/rename-timeout-ids/rename-timeout-ids-transform.js +10 -11
- package/dist/transforms/rename-use-reference-guards/rename-use-reference-guards-transform.js +10 -11
- package/dist/transforms/rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.d.ts +1 -1
- package/dist/transforms/rename-use-reference-guards-v2/rename-use-reference-guards-v2-transform.js +14 -12
- package/dist/transforms/transform-registry.js +0 -10
- package/package.json +4 -2
- package/transform-manifest.json +3 -53
- package/dist/transforms/expand-return-sequence/expand-return-sequence-transform.d.ts +0 -2
- package/dist/transforms/expand-return-sequence/expand-return-sequence-transform.js +0 -91
- package/dist/transforms/expand-sequence-expressions/expand-expression-statement-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions/expand-expression-statement-sequence.js +0 -57
- package/dist/transforms/expand-sequence-expressions/expand-sequence-expressions-transform.d.ts +0 -2
- package/dist/transforms/expand-sequence-expressions/expand-sequence-expressions-transform.js +0 -34
- package/dist/transforms/expand-sequence-expressions/expand-variable-declaration-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions/expand-variable-declaration-sequence.js +0 -93
- package/dist/transforms/expand-sequence-expressions-v2/expand-expression-statement-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v2/expand-expression-statement-sequence.js +0 -55
- package/dist/transforms/expand-sequence-expressions-v2/expand-return-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v2/expand-return-sequence.js +0 -86
- package/dist/transforms/expand-sequence-expressions-v2/expand-sequence-expressions-v2-transform.d.ts +0 -2
- package/dist/transforms/expand-sequence-expressions-v2/expand-sequence-expressions-v2-transform.js +0 -41
- package/dist/transforms/expand-sequence-expressions-v2/expand-variable-declaration-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v2/expand-variable-declaration-sequence.js +0 -93
- package/dist/transforms/expand-sequence-expressions-v3/expand-expression-statement-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v3/expand-expression-statement-sequence.js +0 -64
- package/dist/transforms/expand-sequence-expressions-v3/expand-return-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v3/expand-return-sequence.js +0 -91
- package/dist/transforms/expand-sequence-expressions-v3/expand-sequence-expressions-v3-transform.d.ts +0 -2
- package/dist/transforms/expand-sequence-expressions-v3/expand-sequence-expressions-v3-transform.js +0 -48
- package/dist/transforms/expand-sequence-expressions-v3/expand-throw-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v3/expand-throw-sequence.js +0 -101
- package/dist/transforms/expand-sequence-expressions-v3/expand-variable-declaration-sequence.d.ts +0 -3
- package/dist/transforms/expand-sequence-expressions-v3/expand-variable-declaration-sequence.js +0 -99
- package/dist/transforms/expand-throw-sequence/expand-throw-sequence-transform.d.ts +0 -2
- package/dist/transforms/expand-throw-sequence/expand-throw-sequence-transform.js +0 -117
- package/dist/transforms/rename-binding/get-target-name.d.ts +0 -4
- package/dist/transforms/rename-binding/get-target-name.js +0 -25
- package/dist/transforms/rename-binding/is-valid-binding-identifier.d.ts +0 -1
- package/dist/transforms/rename-binding/is-valid-binding-identifier.js +0 -10
- package/dist/transforms/rename-use-reference-guards/get-target-name.d.ts +0 -2
- package/dist/transforms/rename-use-reference-guards/get-target-name.js +0 -23
- package/dist/transforms/rename-use-reference-guards/is-valid-binding-identifier.d.ts +0 -1
- package/dist/transforms/rename-use-reference-guards/is-valid-binding-identifier.js +0 -10
- package/dist/transforms/rename-use-reference-guards-v2/get-target-name.d.ts +0 -2
- package/dist/transforms/rename-use-reference-guards-v2/get-target-name.js +0 -23
- package/dist/transforms/rename-use-reference-guards-v2/is-valid-binding-identifier.d.ts +0 -1
- package/dist/transforms/rename-use-reference-guards-v2/is-valid-binding-identifier.js +0 -10
package/transform-manifest.json
CHANGED
|
@@ -59,46 +59,6 @@
|
|
|
59
59
|
"evaluatedAt": "2026-01-22T12:49:10.952Z",
|
|
60
60
|
"notes": "Auto-added by evaluation script. Measured with baseline none: 0.09%."
|
|
61
61
|
},
|
|
62
|
-
{
|
|
63
|
-
"id": "expand-return-sequence",
|
|
64
|
-
"description": "Expands return sequences like `return a(), b();`",
|
|
65
|
-
"scope": "file",
|
|
66
|
-
"parallelizable": true,
|
|
67
|
-
"diffReductionImpact": -0.0012834789830316051,
|
|
68
|
-
"recommended": false,
|
|
69
|
-
"evaluatedAt": "2026-01-22T15:19:04.615Z",
|
|
70
|
-
"notes": "Auto-added by evaluation script. Measured with baseline none: -0.13%. Superseded by expand-sequence-expressions-v2 in the recommended preset."
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"id": "expand-sequence-expressions",
|
|
74
|
-
"description": "Expands comma operator sequences in statements and variable initializers",
|
|
75
|
-
"scope": "file",
|
|
76
|
-
"parallelizable": true,
|
|
77
|
-
"diffReductionImpact": -0.01282535248485317,
|
|
78
|
-
"recommended": false,
|
|
79
|
-
"evaluatedAt": "2026-01-22T17:15:48.528Z",
|
|
80
|
-
"notes": "Auto-added by evaluation script. Measured with baseline none: -1.28%. Enabled for readability even when line diffs increase. Kept separate from expand-return-sequence to avoid modifying existing transforms and to allow independent enabling."
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"id": "expand-sequence-expressions-v2",
|
|
84
|
-
"description": "Expands comma operator sequences in returns, statements, and variable initializers",
|
|
85
|
-
"scope": "file",
|
|
86
|
-
"parallelizable": true,
|
|
87
|
-
"diffReductionImpact": -0.014316453068081048,
|
|
88
|
-
"recommended": false,
|
|
89
|
-
"evaluatedAt": "2026-01-22T18:22:48.609Z",
|
|
90
|
-
"notes": "Superseded by expand-sequence-expressions-v3."
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"id": "expand-sequence-expressions-v3",
|
|
94
|
-
"description": "Expands comma operator sequences in returns, throws, statements, and variable initializers",
|
|
95
|
-
"scope": "file",
|
|
96
|
-
"parallelizable": true,
|
|
97
|
-
"diffReductionImpact": -0.014391951831788763,
|
|
98
|
-
"recommended": false,
|
|
99
|
-
"evaluatedAt": "2026-01-23T08:21:23.662Z",
|
|
100
|
-
"notes": "Supersedes expand-sequence-expressions-v2 in the recommended preset. Measured with baseline none: -1.44%. Enabled for readability even when line diffs increase."
|
|
101
|
-
},
|
|
102
62
|
{
|
|
103
63
|
"id": "expand-sequence-expressions-v4",
|
|
104
64
|
"description": "Expands comma operator sequences in returns, throws, statements (including control-flow bodies), and variable initializers",
|
|
@@ -107,7 +67,7 @@
|
|
|
107
67
|
"diffReductionImpact": -0.01730809158000035,
|
|
108
68
|
"recommended": true,
|
|
109
69
|
"evaluatedAt": "2026-01-23T10:57:45.082Z",
|
|
110
|
-
"notes": "Measured with baseline none: -1.73%. Supersedes
|
|
70
|
+
"notes": "Measured with baseline none: -1.73%. Supersedes all prior sequence expression transforms."
|
|
111
71
|
},
|
|
112
72
|
{
|
|
113
73
|
"id": "rename-use-reference-guards",
|
|
@@ -135,9 +95,9 @@
|
|
|
135
95
|
"scope": "file",
|
|
136
96
|
"parallelizable": true,
|
|
137
97
|
"diffReductionImpact": 0.00003774938185385768,
|
|
138
|
-
"recommended":
|
|
98
|
+
"recommended": true,
|
|
139
99
|
"evaluatedAt": "2026-01-23T10:29:23.279Z",
|
|
140
|
-
"notes": "Measured with baseline none: 0.00%.
|
|
100
|
+
"notes": "Measured with baseline none: 0.00%. Added to recommended for readability."
|
|
141
101
|
},
|
|
142
102
|
{
|
|
143
103
|
"id": "split-variable-declarations",
|
|
@@ -149,16 +109,6 @@
|
|
|
149
109
|
"evaluatedAt": "2026-01-23T05:45:27.981Z",
|
|
150
110
|
"notes": "Auto-added by evaluation script. Measured with baseline none: -0.28%. Enabled in the recommended preset for readability and to normalize variable declarations even when line diffs increase."
|
|
151
111
|
},
|
|
152
|
-
{
|
|
153
|
-
"id": "expand-throw-sequence",
|
|
154
|
-
"description": "Expands throw sequences like `throw (a(), b)`",
|
|
155
|
-
"scope": "file",
|
|
156
|
-
"parallelizable": true,
|
|
157
|
-
"diffReductionImpact": -0.00007549876370771536,
|
|
158
|
-
"recommended": false,
|
|
159
|
-
"evaluatedAt": "2026-01-23T07:48:29.356Z",
|
|
160
|
-
"notes": "Largely superseded by expand-sequence-expressions-v3 (which also expands throw sequences), but kept for isolated runs and comparison."
|
|
161
|
-
},
|
|
162
112
|
{
|
|
163
113
|
"id": "rename-promise-executor-parameters",
|
|
164
114
|
"description": "Renames promise-like executor parameters in `new X(executor)` to resolve/reject when usage is high-confidence",
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { getFilesToProcess, } from "../../core/types.js";
|
|
3
|
-
const require = createRequire(import.meta.url);
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
5
|
-
const traverse = require("@babel/traverse").default;
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
|
-
const t = require("@babel/types");
|
|
8
|
-
const isSupportedParent = (path) => {
|
|
9
|
-
return path.parentPath.isBlockStatement() || path.parentPath.isSwitchCase();
|
|
10
|
-
};
|
|
11
|
-
const getSequenceExpressions = (node) => {
|
|
12
|
-
const argument = node.argument;
|
|
13
|
-
if (!argument)
|
|
14
|
-
return;
|
|
15
|
-
if (argument.type !== "SequenceExpression")
|
|
16
|
-
return;
|
|
17
|
-
if (argument.expressions.length < 2)
|
|
18
|
-
return;
|
|
19
|
-
return argument.expressions;
|
|
20
|
-
};
|
|
21
|
-
const createExpressionStatement = (expression) => {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
23
|
-
return t.expressionStatement(expression);
|
|
24
|
-
};
|
|
25
|
-
const createReturnStatement = (expression) => {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
27
|
-
return t.returnStatement(expression);
|
|
28
|
-
};
|
|
29
|
-
const isDirectiveProloguePosition = (path) => {
|
|
30
|
-
if (!path.parentPath.isBlockStatement())
|
|
31
|
-
return false;
|
|
32
|
-
const siblings = path.parentPath.get("body");
|
|
33
|
-
if (!Array.isArray(siblings))
|
|
34
|
-
return false;
|
|
35
|
-
const index = siblings.findIndex((sibling) => sibling.node === path.node);
|
|
36
|
-
if (index === -1)
|
|
37
|
-
return false;
|
|
38
|
-
for (let bodyIndex = 0; bodyIndex < index; bodyIndex++) {
|
|
39
|
-
const sibling = siblings[bodyIndex];
|
|
40
|
-
if (!sibling)
|
|
41
|
-
return false;
|
|
42
|
-
if (!sibling.isExpressionStatement())
|
|
43
|
-
return false;
|
|
44
|
-
if (sibling.node.expression.type !== "StringLiteral")
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
};
|
|
49
|
-
export const expandReturnSequenceTransform = {
|
|
50
|
-
id: "expand-return-sequence",
|
|
51
|
-
description: "Expands return sequences like `return a(), b();`",
|
|
52
|
-
scope: "file",
|
|
53
|
-
parallelizable: true,
|
|
54
|
-
transform(context) {
|
|
55
|
-
let nodesVisited = 0;
|
|
56
|
-
let transformationsApplied = 0;
|
|
57
|
-
for (const fileInfo of getFilesToProcess(context)) {
|
|
58
|
-
traverse(fileInfo.ast, {
|
|
59
|
-
ReturnStatement(path) {
|
|
60
|
-
nodesVisited++;
|
|
61
|
-
if (!isSupportedParent(path))
|
|
62
|
-
return;
|
|
63
|
-
const expressions = getSequenceExpressions(path.node);
|
|
64
|
-
if (!expressions)
|
|
65
|
-
return;
|
|
66
|
-
const leadingExpressions = expressions.slice(0, -1);
|
|
67
|
-
const lastExpression = expressions.at(-1);
|
|
68
|
-
if (!lastExpression)
|
|
69
|
-
return;
|
|
70
|
-
const firstExpression = leadingExpressions[0];
|
|
71
|
-
if (firstExpression?.type === "StringLiteral" &&
|
|
72
|
-
isDirectiveProloguePosition(path)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const statements = leadingExpressions.map((expression) => createExpressionStatement(
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
77
|
-
t.cloneNode(expression, true)));
|
|
78
|
-
statements.push(createReturnStatement(
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
80
|
-
t.cloneNode(lastExpression, true)));
|
|
81
|
-
path.replaceWithMultiple(statements);
|
|
82
|
-
transformationsApplied++;
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return Promise.resolve({
|
|
87
|
-
nodesVisited,
|
|
88
|
-
transformationsApplied,
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4
|
-
const t = require("@babel/types");
|
|
5
|
-
const isSupportedStatementContainer = (path) => {
|
|
6
|
-
const parentPath = path.parentPath;
|
|
7
|
-
if (!parentPath)
|
|
8
|
-
return false;
|
|
9
|
-
return (parentPath.isProgram() ||
|
|
10
|
-
parentPath.isBlockStatement() ||
|
|
11
|
-
parentPath.isSwitchCase());
|
|
12
|
-
};
|
|
13
|
-
const isDirectiveProloguePosition = (path) => {
|
|
14
|
-
const parentPath = path.parentPath;
|
|
15
|
-
if (!parentPath)
|
|
16
|
-
return false;
|
|
17
|
-
if (!parentPath.isProgram() && !parentPath.isBlockStatement())
|
|
18
|
-
return false;
|
|
19
|
-
const siblings = parentPath.get("body");
|
|
20
|
-
if (!Array.isArray(siblings))
|
|
21
|
-
return false;
|
|
22
|
-
const index = siblings.findIndex((sibling) => sibling.node === path.node);
|
|
23
|
-
if (index === -1)
|
|
24
|
-
return false;
|
|
25
|
-
for (let bodyIndex = 0; bodyIndex < index; bodyIndex++) {
|
|
26
|
-
const sibling = siblings[bodyIndex];
|
|
27
|
-
if (!sibling)
|
|
28
|
-
return false;
|
|
29
|
-
if (!sibling.isExpressionStatement())
|
|
30
|
-
return false;
|
|
31
|
-
if (sibling.node.expression.type !== "StringLiteral")
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
36
|
-
export const tryExpandExpressionStatementSequence = (path) => {
|
|
37
|
-
if (!isSupportedStatementContainer(path))
|
|
38
|
-
return false;
|
|
39
|
-
const expression = path.node.expression;
|
|
40
|
-
if (expression.type !== "SequenceExpression")
|
|
41
|
-
return false;
|
|
42
|
-
if (expression.expressions.length < 2)
|
|
43
|
-
return false;
|
|
44
|
-
const firstExpression = expression.expressions[0];
|
|
45
|
-
if (firstExpression?.type === "StringLiteral" &&
|
|
46
|
-
isDirectiveProloguePosition(path)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const statements = expression.expressions.map((expr) => {
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
51
|
-
return t.expressionStatement(
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
53
|
-
t.cloneNode(expr, true));
|
|
54
|
-
});
|
|
55
|
-
path.replaceWithMultiple(statements);
|
|
56
|
-
return true;
|
|
57
|
-
};
|
package/dist/transforms/expand-sequence-expressions/expand-sequence-expressions-transform.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { getFilesToProcess, } from "../../core/types.js";
|
|
3
|
-
import { tryExpandExpressionStatementSequence } from "./expand-expression-statement-sequence.js";
|
|
4
|
-
import { tryExpandVariableDeclarationSequenceInitializers } from "./expand-variable-declaration-sequence.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 expandSequenceExpressionsTransform = {
|
|
9
|
-
id: "expand-sequence-expressions",
|
|
10
|
-
description: "Expands comma operator sequences in statements and variable initializers",
|
|
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
|
-
ExpressionStatement(path) {
|
|
19
|
-
nodesVisited++;
|
|
20
|
-
if (!tryExpandExpressionStatementSequence(path))
|
|
21
|
-
return;
|
|
22
|
-
transformationsApplied += 1;
|
|
23
|
-
},
|
|
24
|
-
VariableDeclaration(path) {
|
|
25
|
-
nodesVisited++;
|
|
26
|
-
if (!tryExpandVariableDeclarationSequenceInitializers(path))
|
|
27
|
-
return;
|
|
28
|
-
transformationsApplied += 1;
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
33
|
-
},
|
|
34
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4
|
-
const t = require("@babel/types");
|
|
5
|
-
const createExpressionStatement = (expression) => {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
7
|
-
return t.expressionStatement(
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
9
|
-
t.cloneNode(expression, true));
|
|
10
|
-
};
|
|
11
|
-
const createVariableDeclarationStatement = (kind, declarator) => {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
13
|
-
return t.variableDeclaration(kind, [declarator]);
|
|
14
|
-
};
|
|
15
|
-
const createVariableDeclarator = (id, init) => {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
17
|
-
return t.variableDeclarator(
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
19
|
-
t.cloneNode(id, true), init
|
|
20
|
-
? // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
21
|
-
t.cloneNode(init, true)
|
|
22
|
-
: undefined);
|
|
23
|
-
};
|
|
24
|
-
const isSupportedStatementContainer = (path) => {
|
|
25
|
-
const parentPath = path.parentPath;
|
|
26
|
-
if (!parentPath)
|
|
27
|
-
return false;
|
|
28
|
-
return (parentPath.isProgram() ||
|
|
29
|
-
parentPath.isBlockStatement() ||
|
|
30
|
-
parentPath.isSwitchCase());
|
|
31
|
-
};
|
|
32
|
-
const isDirectiveProloguePosition = (path) => {
|
|
33
|
-
const parentPath = path.parentPath;
|
|
34
|
-
if (!parentPath)
|
|
35
|
-
return false;
|
|
36
|
-
if (!parentPath.isProgram() && !parentPath.isBlockStatement())
|
|
37
|
-
return false;
|
|
38
|
-
const siblings = parentPath.get("body");
|
|
39
|
-
if (!Array.isArray(siblings))
|
|
40
|
-
return false;
|
|
41
|
-
const index = siblings.findIndex((sibling) => sibling.node === path.node);
|
|
42
|
-
if (index === -1)
|
|
43
|
-
return false;
|
|
44
|
-
for (let bodyIndex = 0; bodyIndex < index; bodyIndex++) {
|
|
45
|
-
const sibling = siblings[bodyIndex];
|
|
46
|
-
if (!sibling)
|
|
47
|
-
return false;
|
|
48
|
-
if (!sibling.isExpressionStatement())
|
|
49
|
-
return false;
|
|
50
|
-
if (sibling.node.expression.type !== "StringLiteral")
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
};
|
|
55
|
-
export const tryExpandVariableDeclarationSequenceInitializers = (path) => {
|
|
56
|
-
if (!isSupportedStatementContainer(path))
|
|
57
|
-
return false;
|
|
58
|
-
if (path.node.kind !== "var" && path.node.declarations.length > 1) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
if (isDirectiveProloguePosition(path)) {
|
|
62
|
-
const wouldInsertStringLiteral = path.node.declarations.some((declarator) => declarator.init?.type === "SequenceExpression" &&
|
|
63
|
-
declarator.init.expressions[0]?.type === "StringLiteral");
|
|
64
|
-
if (wouldInsertStringLiteral)
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const hasAnySequence = path.node.declarations.some((declarator) => declarator.init?.type === "SequenceExpression" &&
|
|
68
|
-
declarator.init.expressions.length >= 2);
|
|
69
|
-
if (!hasAnySequence)
|
|
70
|
-
return false;
|
|
71
|
-
const kind = path.node.kind;
|
|
72
|
-
const statements = [];
|
|
73
|
-
for (const declarator of path.node.declarations) {
|
|
74
|
-
const init = declarator.init;
|
|
75
|
-
if (init?.type !== "SequenceExpression") {
|
|
76
|
-
statements.push(createVariableDeclarationStatement(kind, declarator));
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const leadingExpressions = init.expressions.slice(0, -1);
|
|
80
|
-
const lastExpression = init.expressions.at(-1);
|
|
81
|
-
if (!lastExpression) {
|
|
82
|
-
statements.push(createVariableDeclarationStatement(kind, declarator));
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
for (const expression of leadingExpressions) {
|
|
86
|
-
statements.push(createExpressionStatement(expression));
|
|
87
|
-
}
|
|
88
|
-
const newDeclarator = createVariableDeclarator(declarator.id, lastExpression);
|
|
89
|
-
statements.push(createVariableDeclarationStatement(kind, newDeclarator));
|
|
90
|
-
}
|
|
91
|
-
path.replaceWithMultiple(statements);
|
|
92
|
-
return true;
|
|
93
|
-
};
|
package/dist/transforms/expand-sequence-expressions-v2/expand-expression-statement-sequence.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4
|
-
const t = require("@babel/types");
|
|
5
|
-
const isSupportedStatementContainer = (path) => {
|
|
6
|
-
const parentPath = path.parentPath;
|
|
7
|
-
if (!parentPath)
|
|
8
|
-
return false;
|
|
9
|
-
return (parentPath.isProgram() ||
|
|
10
|
-
parentPath.isBlockStatement() ||
|
|
11
|
-
parentPath.isSwitchCase());
|
|
12
|
-
};
|
|
13
|
-
const isDirectiveProloguePosition = (path) => {
|
|
14
|
-
const parentPath = path.parentPath;
|
|
15
|
-
if (!parentPath.isProgram() && !parentPath.isBlockStatement())
|
|
16
|
-
return false;
|
|
17
|
-
const siblings = parentPath.get("body");
|
|
18
|
-
if (!Array.isArray(siblings))
|
|
19
|
-
return false;
|
|
20
|
-
const index = siblings.findIndex((sibling) => sibling.node === path.node);
|
|
21
|
-
if (index === -1)
|
|
22
|
-
return false;
|
|
23
|
-
for (let bodyIndex = 0; bodyIndex < index; bodyIndex++) {
|
|
24
|
-
const sibling = siblings[bodyIndex];
|
|
25
|
-
if (!sibling)
|
|
26
|
-
return false;
|
|
27
|
-
if (!sibling.isExpressionStatement())
|
|
28
|
-
return false;
|
|
29
|
-
if (sibling.node.expression.type !== "StringLiteral")
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
};
|
|
34
|
-
export const tryExpandExpressionStatementSequence = (path) => {
|
|
35
|
-
if (!isSupportedStatementContainer(path))
|
|
36
|
-
return false;
|
|
37
|
-
const expression = path.node.expression;
|
|
38
|
-
if (expression.type !== "SequenceExpression")
|
|
39
|
-
return false;
|
|
40
|
-
if (expression.expressions.length < 2)
|
|
41
|
-
return false;
|
|
42
|
-
const firstExpression = expression.expressions[0];
|
|
43
|
-
if (firstExpression?.type === "StringLiteral" &&
|
|
44
|
-
isDirectiveProloguePosition(path)) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
const statements = expression.expressions.map((expr) => {
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
49
|
-
return t.expressionStatement(
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
51
|
-
t.cloneNode(expr, true));
|
|
52
|
-
});
|
|
53
|
-
path.replaceWithMultiple(statements);
|
|
54
|
-
return true;
|
|
55
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4
|
-
const t = require("@babel/types");
|
|
5
|
-
const canReplaceWithMultiple = (path) => {
|
|
6
|
-
return path.parentPath.isBlockStatement() || path.parentPath.isSwitchCase();
|
|
7
|
-
};
|
|
8
|
-
const canWrapInBlock = (path) => {
|
|
9
|
-
const parentPath = path.parentPath;
|
|
10
|
-
if (parentPath.isIfStatement() &&
|
|
11
|
-
(path.key === "consequent" || path.key === "alternate")) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
if ((parentPath.isForStatement() ||
|
|
15
|
-
parentPath.isForInStatement() ||
|
|
16
|
-
parentPath.isForOfStatement() ||
|
|
17
|
-
parentPath.isWhileStatement() ||
|
|
18
|
-
parentPath.isDoWhileStatement() ||
|
|
19
|
-
parentPath.isWithStatement()) &&
|
|
20
|
-
path.key === "body") {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
const replaceReturnWithStatements = (path, statements) => {
|
|
26
|
-
if (canReplaceWithMultiple(path)) {
|
|
27
|
-
path.replaceWithMultiple(statements);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
if (canWrapInBlock(path)) {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
32
|
-
path.replaceWith(t.blockStatement(statements));
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
};
|
|
37
|
-
const isDirectiveProloguePosition = (path) => {
|
|
38
|
-
if (!path.parentPath.isBlockStatement())
|
|
39
|
-
return false;
|
|
40
|
-
const siblings = path.parentPath.get("body");
|
|
41
|
-
if (!Array.isArray(siblings))
|
|
42
|
-
return false;
|
|
43
|
-
const index = siblings.findIndex((sibling) => sibling.node === path.node);
|
|
44
|
-
if (index === -1)
|
|
45
|
-
return false;
|
|
46
|
-
for (let bodyIndex = 0; bodyIndex < index; bodyIndex++) {
|
|
47
|
-
const sibling = siblings[bodyIndex];
|
|
48
|
-
if (!sibling)
|
|
49
|
-
return false;
|
|
50
|
-
if (!sibling.isExpressionStatement())
|
|
51
|
-
return false;
|
|
52
|
-
if (sibling.node.expression.type !== "StringLiteral")
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
56
|
-
};
|
|
57
|
-
export const tryExpandReturnSequence = (path) => {
|
|
58
|
-
if (!canReplaceWithMultiple(path) && !canWrapInBlock(path))
|
|
59
|
-
return false;
|
|
60
|
-
const argument = path.node.argument;
|
|
61
|
-
if (!argument)
|
|
62
|
-
return false;
|
|
63
|
-
if (argument.type !== "SequenceExpression")
|
|
64
|
-
return false;
|
|
65
|
-
if (argument.expressions.length < 2)
|
|
66
|
-
return false;
|
|
67
|
-
const leadingExpressions = argument.expressions.slice(0, -1);
|
|
68
|
-
const lastExpression = argument.expressions.at(-1);
|
|
69
|
-
if (!lastExpression)
|
|
70
|
-
return false;
|
|
71
|
-
const firstExpression = leadingExpressions[0];
|
|
72
|
-
if (firstExpression?.type === "StringLiteral" &&
|
|
73
|
-
isDirectiveProloguePosition(path)) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
const statements = leadingExpressions.map((expression) => {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
78
|
-
return t.expressionStatement(
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
80
|
-
t.cloneNode(expression, true));
|
|
81
|
-
});
|
|
82
|
-
statements.push(
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
84
|
-
t.returnStatement(t.cloneNode(lastExpression, true)));
|
|
85
|
-
return replaceReturnWithStatements(path, statements);
|
|
86
|
-
};
|
package/dist/transforms/expand-sequence-expressions-v2/expand-sequence-expressions-v2-transform.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { getFilesToProcess, } from "../../core/types.js";
|
|
3
|
-
import { tryExpandExpressionStatementSequence } from "./expand-expression-statement-sequence.js";
|
|
4
|
-
import { tryExpandReturnSequence } from "./expand-return-sequence.js";
|
|
5
|
-
import { tryExpandVariableDeclarationSequenceInitializers } from "./expand-variable-declaration-sequence.js";
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
8
|
-
const traverse = require("@babel/traverse").default;
|
|
9
|
-
export const expandSequenceExpressionsV2Transform = {
|
|
10
|
-
id: "expand-sequence-expressions-v2",
|
|
11
|
-
description: "Expands comma operator sequences in returns, statements, and variable initializers",
|
|
12
|
-
scope: "file",
|
|
13
|
-
parallelizable: true,
|
|
14
|
-
transform(context) {
|
|
15
|
-
let nodesVisited = 0;
|
|
16
|
-
let transformationsApplied = 0;
|
|
17
|
-
for (const fileInfo of getFilesToProcess(context)) {
|
|
18
|
-
traverse(fileInfo.ast, {
|
|
19
|
-
ReturnStatement(path) {
|
|
20
|
-
nodesVisited++;
|
|
21
|
-
if (!tryExpandReturnSequence(path))
|
|
22
|
-
return;
|
|
23
|
-
transformationsApplied += 1;
|
|
24
|
-
},
|
|
25
|
-
ExpressionStatement(path) {
|
|
26
|
-
nodesVisited++;
|
|
27
|
-
if (!tryExpandExpressionStatementSequence(path))
|
|
28
|
-
return;
|
|
29
|
-
transformationsApplied += 1;
|
|
30
|
-
},
|
|
31
|
-
VariableDeclaration(path) {
|
|
32
|
-
nodesVisited++;
|
|
33
|
-
if (!tryExpandVariableDeclarationSequenceInitializers(path))
|
|
34
|
-
return;
|
|
35
|
-
transformationsApplied += 1;
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return Promise.resolve({ nodesVisited, transformationsApplied });
|
|
40
|
-
},
|
|
41
|
-
};
|