@putout/printer 18.0.11 → 18.0.13

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.03.05, v18.0.13
2
+
3
+ feature:
4
+ - 5a991b6 @putout/printer: FunctionDeclaration: simplify
5
+
6
+ 2026.03.05, v18.0.12
7
+
8
+ fix:
9
+ - 9766539 @putout/printer: ArrayExpression: newline
10
+
1
11
  2026.03.05, v18.0.11
2
12
 
3
13
  feature:
@@ -61,23 +61,18 @@ const isSiblingIsArray = (path) => {
61
61
 
62
62
  const isEmptyArray = (path) => !path.node.elements.length;
63
63
 
64
- const isAllLiterals = (path) => {
65
- const {elements} = path.node;
66
- const literals = elements.filter(isStringLiteral);
67
-
68
- return literals.length !== elements.length;
69
- };
70
-
71
64
  const isMoreThenMaxLiteralLength = (path, {maxElementLengthInOneLine}) => {
72
65
  const [first] = path.node.elements;
73
66
 
67
+ if (!first.value)
68
+ return false;
69
+
74
70
  return first.value.length > maxElementLengthInOneLine;
75
71
  };
76
72
 
77
73
  const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
78
74
  ['-', isEmptyArray],
79
75
  ['-: -> !', isInsideCall],
80
- ['-', isAllLiterals],
81
76
  ['+', isMoreThenMaxLiteralLength],
82
77
  ]);
83
78
 
@@ -5,7 +5,6 @@ import {isNext, isNextParent} from '#is';
5
5
  import {createTypeChecker} from '#type-checker';
6
6
 
7
7
  const {
8
- isAssignmentExpression,
9
8
  isExportNamedDeclaration,
10
9
  isExpressionStatement,
11
10
  isFunctionDeclaration,
@@ -13,15 +12,24 @@ const {
13
12
 
14
13
  const hasFnBody = ({node}) => node.body.body.length;
15
14
 
16
- const isInsideExportDefaultWithBody = createTypeChecker([
17
- '-: parentPath -> !ExportDefaultDeclaration',
18
- ['+', hasFnBody],
15
+ const getNext = (fn) => (path) => fn(path.getNextSibling());
16
+
17
+ const isIndentAfter = createTypeChecker([
18
+ ['+', getNext(isFunctionDeclaration)],
19
+ ['+', isNext],
20
+ ['-: -> !', getNext(isExpressionStatement)],
19
21
  ]);
20
22
 
21
- const isInsideBlockLike = createTypeChecker(['+: parentPath.parentPath -> TSModuleBlock', '-: parentPath -> !BlockStatement', ['+: -> !', hasFnBody]]);
23
+ const isNotInsideExportDefaultWithBody = createTypeChecker([
24
+ '+: parentPath -> !ExportDefaultDeclaration',
25
+ ['+: -> !', hasFnBody],
26
+ ]);
22
27
 
23
- const not = (fn) => (...a) => !fn(...a);
24
- const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
28
+ const isInsideBlockLike = createTypeChecker([
29
+ '+: parentPath.parentPath -> TSModuleBlock',
30
+ '-: parentPath -> !BlockStatement',
31
+ ['+: -> !', hasFnBody],
32
+ ]);
25
33
 
26
34
  const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
27
35
 
@@ -60,24 +68,10 @@ export const FunctionDeclaration = {
60
68
  },
61
69
  afterSatisfy: () => [isNext, isNextParent, isInsideBlockLike],
62
70
  after(path, {indent, maybe}) {
63
- if (isNextAssign(path) || isNextFunction(path) || isNext(path))
71
+ if (isIndentAfter(path))
64
72
  indent();
65
73
 
66
- maybe.write.newline(notInsideExportDefaultWithBody(path));
74
+ maybe.write.newline(isNotInsideExportDefaultWithBody(path));
67
75
  markAfter(path);
68
76
  },
69
77
  };
70
-
71
- const isNextFunction = (path) => {
72
- const next = path.getNextSibling();
73
- return isFunctionDeclaration(next);
74
- };
75
-
76
- const isNextAssign = (path) => {
77
- const next = path.getNextSibling();
78
-
79
- if (!isExpressionStatement(next))
80
- return false;
81
-
82
- return isAssignmentExpression(next.node.expression);
83
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.11",
3
+ "version": "18.0.13",
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",