@putout/printer 18.7.0 → 18.7.1

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,8 @@
1
+ 2026.03.14, v18.7.1
2
+
3
+ feature:
4
+ - 5003310 @putout/printer: ReturnStatement: simplify
5
+
1
6
  2026.03.14, v18.7.0
2
7
 
3
8
  feature:
@@ -35,6 +35,7 @@ export const maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
35
35
  const {leadingComments} = path.node;
36
36
 
37
37
  print.breakline();
38
+
38
39
  for (const {type, value} of leadingComments) {
39
40
  if (type === 'CommentLine')
40
41
  print(`//${value}`);
@@ -51,8 +51,6 @@ export const isNextTry = (path) => {
51
51
  return isTryStatement(path.getNextSibling());
52
52
  };
53
53
 
54
- export const isPrevTry = (path) => isTryStatement(path.getPrevSibling());
55
-
56
54
  export const isPrev = (path) => {
57
55
  const next = path.getPrevSibling();
58
56
  return next.node;
@@ -62,10 +60,6 @@ export const isNextParent = (path) => isNext(path.parentPath);
62
60
  export const isLast = (path) => isInsideProgram(path) && !isNext(path);
63
61
 
64
62
  export const isFirst = (path) => path.node === path.parentPath.node.body?.[0];
65
- export const isPrevBody = (path) => path
66
- .getPrevSibling()
67
- .isBlockStatement();
68
-
69
63
  export const isParentLast = (path) => isLast(path.parentPath);
70
64
 
71
65
  export function isCoupleLines(path) {
@@ -1,26 +1,36 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {hasPrevNewline} from '#mark';
3
+ import {createTypeChecker} from '#type-checker';
3
4
  import {
4
5
  isInsideLabel,
5
- isPrevBody,
6
6
  noTrailingComment,
7
7
  isLast,
8
- isPrevTry,
8
+ callWithPrev,
9
9
  } from '#is';
10
10
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
11
11
 
12
- const {isJSXElement} = types;
12
+ const {
13
+ isJSXElement,
14
+ isTryStatement,
15
+ isBlockStatement,
16
+ } = types;
17
+
13
18
  const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
14
19
 
15
- const isInsideIfWithElse = ({parentPath}) => parentPath.isIfStatement() && parentPath.node.alternate;
20
+ const isInsideIfWithElse = createTypeChecker([
21
+ ['-: parentPath -> !IfStatement'],
22
+ ['+: parentPath.node.alternate', Boolean],
23
+ ]);
24
+
25
+ const beforeIf = createTypeChecker([
26
+ ['+', callWithPrev(isTryStatement)],
27
+ ['-: ->', hasPrevNewline],
28
+ ['+: ->', isBodyLength],
29
+ ['+: ->', callWithPrev(isBlockStatement)],
30
+ ]);
16
31
 
17
32
  export const ReturnStatement = {
18
- beforeIf(path) {
19
- if (isPrevTry(path))
20
- return true;
21
-
22
- return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
23
- },
33
+ beforeIf,
24
34
  before(path, {print}) {
25
35
  print.linebreak();
26
36
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.7.0",
3
+ "version": "18.7.1",
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",