@putout/printer 18.0.3 → 18.0.5

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/ChangeLog CHANGED
@@ -1,3 +1,14 @@
1
+ 2026.03.04, v18.0.5
2
+
3
+ feature:
4
+ - a19962d @putout/printer: IfStatement: simplify
5
+ - fc6658a @putout/printer: IfStatement: apply typeChecker
6
+
7
+ 2026.03.04, v18.0.4
8
+
9
+ feature:
10
+ - e81d579 @putout/printer: type-checker: export
11
+
1
12
  2026.03.04, v18.0.3
2
13
 
3
14
  fix:
@@ -31,10 +31,12 @@ const isTopLevelWithNoNext = (path) => {
31
31
  };
32
32
 
33
33
  const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
34
+
34
35
  const isMethodOrArrow = createTypeChecker([
35
36
  'ArrowFunctionExpression',
36
37
  'ObjectMethod',
37
38
  ]);
39
+
38
40
  const isInsideFn = (path) => path.find(isMethodOrArrow);
39
41
 
40
42
  const isInsideIfWithoutElseInsideFn = createTypeChecker([
@@ -1,10 +1,12 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {markAfter} from '#mark';
3
+ import {createTypeChecker} from '#type-checker';
3
4
  import {
4
5
  exists,
5
6
  isNext,
6
7
  isInsideIf,
7
8
  hasEmptyBody,
9
+ isInsideBlock,
8
10
  } from '#is';
9
11
  import {
10
12
  printTrailingCommentBlock,
@@ -13,7 +15,6 @@ import {
13
15
 
14
16
  const {
15
17
  isBlockStatement,
16
- isFunctionDeclaration,
17
18
  isStatement,
18
19
  isExpressionStatement,
19
20
  isReturnStatement,
@@ -33,30 +34,22 @@ const isStatementNotExpression = (path) => {
33
34
  return !isExpressionStatement(path);
34
35
  };
35
36
 
37
+ const isInsideNestedBody = createTypeChecker([
38
+ ['-: -> !', isInsideBlock],
39
+ '+: parentPath.parentPath -> BlockStatement',
40
+ ]);
41
+
36
42
  const isTopLevel = ({parentPath}) => parentPath.parentPath.isProgram();
37
43
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
44
+ const isBlockConsequent = (path) => isBlockStatement(path.node.consequent);
45
+ const isConsequentHasBody = (path) => path.node.consequent.body.length;
38
46
 
39
- const isInsideNestedBody = ({parentPath}) => {
40
- if (parentPath.type !== 'BlockStatement')
41
- return false;
42
-
43
- return parentPath.parentPath.type === 'BlockStatement';
44
- };
45
-
46
- const isLastEmptyInsideBody = (path) => {
47
- const {parentPath} = path;
48
-
49
- if (!isBlockStatement(parentPath))
50
- return false;
51
-
52
- if (!isBlockStatement(path.node.consequent))
53
- return false;
54
-
55
- if (path.node.consequent.body.length)
56
- return false;
57
-
58
- return isFunctionDeclaration(path.parentPath.parentPath);
59
- };
47
+ const isLastEmptyInsideBody = createTypeChecker([
48
+ ['-: -> !', isInsideBlock],
49
+ ['-: -> !', isBlockConsequent],
50
+ ['-', isConsequentHasBody],
51
+ '+: parentPath.parentPath -> FunctionDeclaration',
52
+ ]);
60
53
 
61
54
  export const IfStatement = {
62
55
  printTrailingCommentBlock,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.3",
3
+ "version": "18.0.5",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -9,7 +9,8 @@
9
9
  "exports": {
10
10
  ".": "./lib/printer.js",
11
11
  "./is": "./lib/tokenize/is.js",
12
- "./params": "./lib/tokenize/expressions/function/params.js"
12
+ "./params": "./lib/tokenize/expressions/function/params.js",
13
+ "./type-checker": "./lib/tokenize/type-checker/type-checker.js"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",