@putout/printer 18.4.4 → 18.4.6

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,14 @@
1
+ 2026.03.12, v18.4.6
2
+
3
+ feature:
4
+ - 7c290de @putout/printer: BlockStatement: simplify
5
+ - 0dc390f @putout/printer: BlockStatement: indent
6
+
7
+ 2026.03.12, v18.4.5
8
+
9
+ feature:
10
+ - e18f600 @putout/printer: ArrayExpression: isCommaAfterElement
11
+
1
12
  2026.03.11, v18.4.4
2
13
 
3
14
  feature:
@@ -59,12 +59,6 @@ export const ArrayExpression = {
59
59
  multiline,
60
60
  });
61
61
 
62
- const needsComma = isCommaAfterElement(path, {
63
- trailingComma,
64
- isLast,
65
- needsIndentBeforeElement,
66
- });
67
-
68
62
  if (isNewlineBeforeElement(element))
69
63
  print.newline();
70
64
 
@@ -73,8 +67,11 @@ export const ArrayExpression = {
73
67
 
74
68
  print(element);
75
69
 
76
- if (needsComma)
77
- print(',');
70
+ maybe.print(isCommaAfterElement(path, {
71
+ trailingComma,
72
+ isLast,
73
+ needsIndentBeforeElement,
74
+ }), ',');
78
75
 
79
76
  if (isNewlineAfterComma(element, {multiline})) {
80
77
  print.newline();
@@ -1,27 +1,35 @@
1
- import {types} from '@putout/babel';
2
1
  import {markAfter} from '#mark';
2
+ import {createTypeChecker} from '#type-checker';
3
+ import {isInsideBlock} from '#is';
3
4
  import {parseComments} from '../../comment/comment.js';
4
5
  import {getDirectives} from './get-directives.js';
5
6
  import {isCallInsideChain} from './is-call-inside-chain.js';
6
7
  import {shouldAddNewlineAfter} from './block-statement-newline.js';
7
8
 
8
- const {isArrayExpression} = types;
9
+ const isThree = (a) => a === 3;
9
10
 
10
- const isFirstStatement = (path) => path.node.body[0];
11
- const isFirstDirective = (path) => path.node.directives?.[0];
11
+ const isInsideArrayTupleOfThree = createTypeChecker([
12
+ ['-: parentPath.parentPath -> !ArrayExpression'],
13
+ ['+: parentPath.parentPath.node.elements.length', isThree],
14
+ ]);
12
15
 
13
- const isInsideArrayTupleOfThree = (path) => {
14
- const {parentPath} = path.parentPath;
15
-
16
- if (!isArrayExpression(parentPath))
17
- return false;
18
-
19
- const {length} = parentPath.node.elements;
20
-
21
- return length === 3;
22
- };
16
+ const hasDirectives = (a) => getDirectives(a).length;
17
+
18
+ const isNewLineAfterOpenCurlyBrace = createTypeChecker([
19
+ ['+', hasDirectives],
20
+ ['+: node.body.length', Boolean],
21
+ ]);
22
+
23
+ const isLinebreakAfterDirectives = createTypeChecker([
24
+ ['-: node.body.length -> !', Boolean],
25
+ ['+', hasDirectives],
26
+ ]);
23
27
 
24
28
  export const BlockStatement = {
29
+ beforeIf: isInsideBlock,
30
+ before: (path, {indent}) => {
31
+ indent();
32
+ },
25
33
  print(path, printer, semantics) {
26
34
  const {
27
35
  indent,
@@ -32,22 +40,21 @@ export const BlockStatement = {
32
40
 
33
41
  const body = path.get('body');
34
42
  const directives = getDirectives(path);
35
-
36
- if (path.parentPath.isBlockStatement())
37
- indent();
38
-
39
43
  const insideArray = isInsideArrayTupleOfThree(path);
44
+
40
45
  maybe.indent.inc(!insideArray);
41
46
  write('{');
42
47
 
43
- if (isFirstStatement(path) || isFirstDirective(path))
48
+ if (isNewLineAfterOpenCurlyBrace(path))
44
49
  write.newline();
45
50
 
46
51
  for (const directive of directives) {
47
52
  traverse(directive);
48
53
  }
49
54
 
50
- maybe.write.linebreak(directives.length && body.length);
55
+ if (isLinebreakAfterDirectives(path))
56
+ write.linebreak();
57
+
51
58
  const callInsideChain = isCallInsideChain(path);
52
59
 
53
60
  maybe.indent.inc(callInsideChain);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.4.4",
3
+ "version": "18.4.6",
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",