@putout/printer 17.5.0 → 17.7.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/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.02.16, v17.7.0
2
+
3
+ feature:
4
+ - 1512671 @putout/printer: types: maybeVisitor, visitors
5
+
6
+ 2026.02.15, v17.6.0
7
+
8
+ feature:
9
+ - a27d2f6 @putout/printer: ReturnStatement after TryStatement
10
+
1
11
  2026.02.13, v17.5.0
2
12
 
3
13
  feature:
package/lib/printer.d.ts CHANGED
@@ -59,3 +59,7 @@ interface Options {
59
59
 
60
60
  export function print(ast: types.Node, options?: Options): string;
61
61
 
62
+ declare function maybeVisitor(plugin: Visitor, path: types.Path, printer: Print, semantics: Semantics);
63
+
64
+ export const visitors = Visitors;
65
+
@@ -11,6 +11,7 @@ const {
11
11
  isArrayExpression,
12
12
  isObjectExpression,
13
13
  isLabeledStatement,
14
+ isTryStatement,
14
15
  } = types;
15
16
 
16
17
  export const isParentProgram = (path) => path.parentPath?.isProgram();
@@ -25,6 +26,12 @@ export const isNext = (path) => {
25
26
  return !next.isEmptyStatement();
26
27
  };
27
28
 
29
+ export const isNextTry = (path) => {
30
+ return isTryStatement(path.getNextSibling());
31
+ };
32
+
33
+ export const isPrevTry = (path) => isTryStatement(path.getPrevSibling());
34
+
28
35
  export const isPrev = (path) => {
29
36
  const next = path.getPrevSibling();
30
37
  return next.node;
@@ -4,6 +4,7 @@ import {
4
4
  isPrevBody,
5
5
  noTrailingComment,
6
6
  isLast,
7
+ isPrevTry,
7
8
  } from '#is';
8
9
  import {hasPrevNewline} from '../../mark.js';
9
10
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
@@ -15,6 +16,9 @@ const isInsideIfWithElse = ({parentPath}) => parentPath.isIfStatement() && paren
15
16
 
16
17
  export const ReturnStatement = {
17
18
  beforeIf(path) {
19
+ if (isPrevTry(path))
20
+ return true;
21
+
18
22
  return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
19
23
  },
20
24
  before(path, {print}) {
@@ -1,7 +1,10 @@
1
- import {isNext} from '#is';
1
+ import {types} from '@putout/babel';
2
+ import {isNext, isNextTry} from '#is';
3
+
4
+ const {isExpressionStatement} = types;
2
5
 
3
6
  export const TryStatement = {
4
- print(path, {print}) {
7
+ print(path, {print, maybe}) {
5
8
  const finalizer = path.get('finalizer');
6
9
  print.indent();
7
10
  print('try');
@@ -14,16 +17,22 @@ export const TryStatement = {
14
17
  print('finally');
15
18
  print.space();
16
19
  print(finalizer);
17
- print.newline();
20
+ maybe.print.newline(!isNext(path));
18
21
  }
19
22
  },
20
23
  afterSatisfy: () => [isNext],
21
- after(path, {maybe, print}) {
22
- maybe.print.newline(!path.node.finalizer);
23
- print.breakline();
24
+ after(path, {print}) {
25
+ print.newline();
26
+
27
+ if (isNextExpression(path) || isNextTry(path))
28
+ print.breakline();
24
29
  },
25
30
  };
26
31
 
32
+ const isNextExpression = (path) => {
33
+ return isExpressionStatement(path.getNextSibling());
34
+ };
35
+
27
36
  export const CatchClause = (path, {print, maybe}) => {
28
37
  const param = path.get('param');
29
38
  const body = path.get('body');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "17.5.0",
3
+ "version": "17.7.0",
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",