@putout/printer 15.26.1 → 15.26.2

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
+ 2025.11.07, v15.26.2
2
+
3
+ feature:
4
+ - c388dfa @putout/printer: IfStatement: consiquent is TryCatchStatement: add newline before else
5
+
1
6
  2025.10.31, v15.26.1
2
7
 
3
8
  feature:
@@ -13,8 +13,24 @@ const {
13
13
  isBlockStatement,
14
14
  isFunctionDeclaration,
15
15
  isStatement,
16
+ isExpressionStatement,
17
+ isReturnStatement,
18
+ isContinueStatement,
16
19
  } = types;
17
20
 
21
+ const isStatementNotExpression = (path) => {
22
+ if (isBlockStatement(path))
23
+ return false;
24
+
25
+ if (isReturnStatement(path))
26
+ return false;
27
+
28
+ if (isContinueStatement(path))
29
+ return false;
30
+
31
+ return !isExpressionStatement(path);
32
+ };
33
+
18
34
  const isTopLevel = ({parentPath}) => parentPath.parentPath.isProgram();
19
35
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
20
36
 
@@ -83,15 +99,17 @@ module.exports.IfStatement = {
83
99
  write.space();
84
100
  traverse(alternate);
85
101
  } else if (alternate.isIfStatement()) {
86
- if (alternate.get('consequent').isBlockStatement())
102
+ if (alternate.get('consequent').isBlockStatement()) {
87
103
  write.space();
88
- else
104
+ } else {
105
+ maybe.write.newline(isStatementNotExpression(consequent));
89
106
  indent();
107
+ }
90
108
 
91
109
  write('else ');
92
110
  traverse(alternate);
93
111
  } else if (exists(alternate)) {
94
- maybe.write.newline(isVar);
112
+ maybe.write.newline(isVar || isStatementNotExpression(consequent));
95
113
  maybe.indent(!isConsequentBlock);
96
114
  maybe.write.space(isConsequentBlock);
97
115
  write('else');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.26.1",
3
+ "version": "15.26.2",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",