@putout/printer 11.11.0 → 11.12.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
+ 2024.12.25, v11.12.0
2
+
3
+ feature:
4
+ - 516a7ae @putout/printer: IfStatement: newline when empty and last inside FunctionDeclaration
5
+
1
6
  2024.12.22, v11.11.0
2
7
 
3
8
  feature:
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const {isLast, isNext} = require('../../is');
4
-
5
4
  const {maybeParens} = require('../../maybe/maybe-parens');
6
5
 
7
6
  const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
@@ -1,8 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
4
+
3
5
  const {markAfter} = require('../../mark');
4
6
  const {exists, isNext} = require('../../is');
5
-
7
+ const {
8
+ isBlockStatement,
9
+ isFunctionDeclaration,
10
+ } = types;
6
11
  const isInside = ({parentPath}) => !parentPath.parentPath.isProgram();
7
12
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
8
13
 
@@ -16,6 +21,21 @@ const isInsideNestedBody = ({parentPath}) => {
16
21
  const isInsideIf = (path) => path.parentPath.parentPath?.isIfStatement();
17
22
  const isEmptyBody = (path) => !path.node.body.length;
18
23
 
24
+ const isLastEmptyInsideBody = (path) => {
25
+ const {parentPath} = path;
26
+
27
+ if (!isBlockStatement(parentPath))
28
+ return false;
29
+
30
+ if (!isBlockStatement(path.node.consequent))
31
+ return false;
32
+
33
+ if (path.node.consequent.body.length)
34
+ return false;
35
+
36
+ return isFunctionDeclaration(path.parentPath.parentPath);
37
+ };
38
+
19
39
  module.exports.IfStatement = {
20
40
  print: (path, {indent, print, maybe, write, traverse}) => {
21
41
  const partOfAlternate = path.parentPath.get('alternate');
@@ -79,6 +99,9 @@ module.exports.IfStatement = {
79
99
 
80
100
  if (path === partOfAlternate && isInside(path))
81
101
  print.newline();
102
+
103
+ if (isLastEmptyInsideBody(path))
104
+ print.newline();
82
105
  },
83
106
  afterSatisfy: () => [isNext],
84
107
  after: (path, {print}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.11.0",
3
+ "version": "11.12.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",