miniread 1.15.0 → 1.16.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.
@@ -0,0 +1,2 @@
1
+ import { type Transform } from "../../core/types.js";
2
+ export declare const removeRedundantElseTransform: Transform;
@@ -0,0 +1,61 @@
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
+ export const removeRedundantElseTransform = {
9
+ id: "remove-redundant-else",
10
+ description: "Removes redundant else blocks after return/throw/break/continue",
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
+ IfStatement(path) {
19
+ nodesVisited++;
20
+ const { consequent, alternate } = path.node;
21
+ if (!alternate)
22
+ return;
23
+ let interrupts = false;
24
+ if (isInterrupting(consequent)) {
25
+ interrupts = true;
26
+ }
27
+ else if (consequent.type === "BlockStatement" &&
28
+ consequent.body.length > 0) {
29
+ const last = consequent.body.at(-1);
30
+ if (isInterrupting(last)) {
31
+ interrupts = true;
32
+ }
33
+ }
34
+ if (interrupts) {
35
+ // Remove alternate
36
+ // eslint-disable-next-line unicorn/no-null
37
+ path.node.alternate = null;
38
+ // Insert alternate content after
39
+ path.insertAfter(alternate);
40
+ transformationsApplied++;
41
+ }
42
+ },
43
+ });
44
+ }
45
+ return Promise.resolve({
46
+ nodesVisited,
47
+ transformationsApplied,
48
+ });
49
+ },
50
+ };
51
+ function isInterrupting(node) {
52
+ return (
53
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
54
+ (t.isReturnStatement(node) ||
55
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
56
+ t.isThrowStatement(node) ||
57
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
58
+ t.isBreakStatement(node) ||
59
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
60
+ t.isContinueStatement(node)));
61
+ }
@@ -3,6 +3,7 @@ import { expandSpecialNumberLiteralsTransform } from "./expand-special-number-li
3
3
  import { expandSequenceExpressionsV4Transform } from "./expand-sequence-expressions-v4/expand-sequence-expressions-v4-transform.js";
4
4
  import { expandSequenceExpressionsV5Transform } from "./expand-sequence-expressions-v5/expand-sequence-expressions-v5-transform.js";
5
5
  import { expandUndefinedLiteralsTransform } from "./expand-undefined-literals/expand-undefined-literals-transform.js";
6
+ import { removeRedundantElseTransform } from "./remove-redundant-else/remove-redundant-else-transform.js";
6
7
  import { renameCatchParametersTransform } from "./rename-catch-parameters/rename-catch-parameters-transform.js";
7
8
  import { renameComparisonFlagsTransform } from "./rename-comparison-flags/rename-comparison-flags-transform.js";
8
9
  import { renameDestructuredAliasesTransform } from "./rename-destructured-aliases/rename-destructured-aliases-transform.js";
@@ -26,6 +27,7 @@ export const transformRegistry = {
26
27
  [expandSequenceExpressionsV4Transform.id]: expandSequenceExpressionsV4Transform,
27
28
  [expandSequenceExpressionsV5Transform.id]: expandSequenceExpressionsV5Transform,
28
29
  [expandUndefinedLiteralsTransform.id]: expandUndefinedLiteralsTransform,
30
+ [removeRedundantElseTransform.id]: removeRedundantElseTransform,
29
31
  [renameCatchParametersTransform.id]: renameCatchParametersTransform,
30
32
  [renameComparisonFlagsTransform.id]: renameComparisonFlagsTransform,
31
33
  [renameDestructuredAliasesTransform.id]: renameDestructuredAliasesTransform,
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.15.0",
5
+ "version": "1.16.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",
@@ -191,6 +191,16 @@
191
191
  "evaluatedAt": "2026-01-23T08:17:45.579Z",
192
192
  "notes": "Auto-added by evaluation script."
193
193
  },
194
+ {
195
+ "id": "remove-redundant-else",
196
+ "description": "Removes redundant else blocks after return/throw/break/continue",
197
+ "scope": "file",
198
+ "parallelizable": true,
199
+ "diffReductionImpact": 0,
200
+ "recommended": true,
201
+ "evaluatedAt": "2026-01-23T18:15:00.000Z",
202
+ "notes": "Added manually; improves readability by reducing nesting."
203
+ },
194
204
  {
195
205
  "id": "rename-char-code-at",
196
206
  "description": "Renames variables used in charCodeAt calls (str.charCodeAt(index))",