@putout/printer 14.0.0 → 14.1.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
+ 2025.03.22, v14.1.0
2
+
3
+ feature:
4
+ - 10da896 @putout/printer: ExportNamedDeclaration inside BlockStatement
5
+
6
+ 2025.03.22, v14.0.1
7
+
8
+ feature:
9
+ - ba190fc @putout/printer: IfStatement: newline
10
+
1
11
  2025.03.22, v14.0.0
2
12
 
3
13
  feature:
@@ -5,6 +5,9 @@ const {markAfter} = require('../../mark');
5
5
  const {isNext, isNextParent} = require('../../is');
6
6
  const {printParams} = require('./params');
7
7
 
8
+ const not = (fn) => (...a) => !fn(...a);
9
+ const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
10
+
8
11
  const {
9
12
  isAssignmentExpression,
10
13
  isTSModuleBlock,
@@ -12,6 +15,7 @@ const {
12
15
  isExportNamedDeclaration,
13
16
  isExpressionStatement,
14
17
  isFunctionDeclaration,
18
+ isExportDefaultDeclaration,
15
19
  } = types;
16
20
 
17
21
  const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
@@ -50,11 +54,11 @@ module.exports.FunctionDeclaration = {
50
54
  print('__body');
51
55
  },
52
56
  afterSatisfy: () => [isNext, isNextParent, isInsideBlockStatement],
53
- after(path, {write, indent}) {
57
+ after(path, {indent, maybe}) {
54
58
  if (isNextAssign(path) || isNextFunction(path))
55
59
  indent();
56
60
 
57
- write.newline();
61
+ maybe.write.newline(notInsideExportDefaultWithBody(path));
58
62
  markAfter(path);
59
63
  },
60
64
  };
@@ -84,3 +88,10 @@ function isInsideBlockStatement(path) {
84
88
 
85
89
  return !path.node.body.body.length;
86
90
  }
91
+
92
+ function isInsideExportDefaultWithBody(path) {
93
+ if (!isExportDefaultDeclaration(path.parentPath))
94
+ return false;
95
+
96
+ return path.node.body.body.length;
97
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {types} = require('@putout/babel');
4
4
 
5
+ const {isParentBlock} = require('#is');
5
6
  const {markAfter, isMarkedAfter} = require('../../mark');
6
7
 
7
8
  const {
@@ -115,7 +116,10 @@ module.exports.ExportNamedDeclaration = {
115
116
  if (isDeclarationNewline(path))
116
117
  return false;
117
118
 
118
- return isNewlineBetweenSiblings(path);
119
+ if (isNewlineBetweenSiblings(path))
120
+ return true;
121
+
122
+ return isParentBlock(path);
119
123
  },
120
124
  after(path, {print}) {
121
125
  print.newline();
@@ -12,6 +12,7 @@ const {
12
12
  const {
13
13
  isBlockStatement,
14
14
  isFunctionDeclaration,
15
+ isExpressionStatement,
15
16
  } = types;
16
17
 
17
18
  const isInside = ({parentPath}) => !parentPath.parentPath.isProgram();
@@ -103,7 +104,9 @@ module.exports.IfStatement = {
103
104
  if (!isNext(path) && !consequent.isBlockStatement())
104
105
  return;
105
106
 
106
- if (path === partOfAlternate && isInside(path))
107
+ const nextPath = path.parentPath.getNextSibling();
108
+
109
+ if (path === partOfAlternate && isInside(path) && !isExpressionStatement(nextPath))
107
110
  print.newline();
108
111
 
109
112
  if (isLastEmptyInsideBody(path))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "14.0.0",
3
+ "version": "14.1.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",