@putout/printer 1.99.0 → 1.100.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,8 @@
1
+ 2023.05.17, v1.100.0
2
+
3
+ feature:
4
+ - 1b2c36b @putout/printer: IfStatement: improve newline support when nested
5
+
1
6
  2023.05.16, v1.99.0
2
7
 
3
8
  feature:
@@ -5,6 +5,9 @@ const {exists} = require('../is');
5
5
 
6
6
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
7
7
 
8
+ const isInsideIf = (path) => path.parentPath.parentPath?.isIfStatement();
9
+ const isEmptyBody = (path) => !path.node.body.length;
10
+
8
11
  module.exports.IfStatement = {
9
12
  print: (path, {indent, print, maybe, write, traverse}) => {
10
13
  indent();
@@ -21,6 +24,7 @@ module.exports.IfStatement = {
21
24
  if (isConsequentBlock) {
22
25
  print.space();
23
26
  print(consequent);
27
+ maybe.print.newline(isEmptyBody(consequent) && isInsideIf(path));
24
28
  } else {
25
29
  const is = !isEmptyConsequent(path);
26
30
  maybe.print.newline(is);
@@ -49,7 +53,7 @@ module.exports.IfStatement = {
49
53
  afterIf: (path) => {
50
54
  const next = path.getNextSibling();
51
55
 
52
- if (!next.node)
56
+ if (!exists(next))
53
57
  return false;
54
58
 
55
59
  if (next.isReturnStatement())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.99.0",
3
+ "version": "1.100.0",
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",