@putout/printer 18.35.0 → 18.36.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,10 @@
1
+ 2026.07.12, v18.36.0
2
+
3
+ feature:
4
+ - c1c2897c @putout/printer: TSParameterProperty: simplify
5
+ - e888f538 @putout/printer: MaybeDecorators: simplify
6
+ - 72941d94 @putout/printer: TSParameterProperty: Decorator
7
+
1
8
  2026.07.12, v18.35.0
2
9
 
3
10
  feature:
@@ -105,4 +105,3 @@ export const printTrailingComments = (path, printer, semantics, {currentTraverse
105
105
  });
106
106
  }
107
107
  };
108
-
@@ -1,4 +1,7 @@
1
- import {hasLeadingComment} from '#is';
1
+ import {
2
+ hasLeadingComment,
3
+ hasDecorators,
4
+ } from '#is';
2
5
  import {printParams} from '#print-params';
3
6
 
4
7
  const isAllParamsHasLeadingComments = (path) => {
@@ -22,10 +25,8 @@ const isAllParamsHasLeadingComments = (path) => {
22
25
  return commentsCount === decoratorsCount;
23
26
  };
24
27
 
25
- const hasDecorators = ({decorators}) => decorators?.length;
26
-
27
28
  export const printFunctionParams = (path, printer, semantics) => {
28
- const {params} = path.node;
29
+ const params = path.get('params');
29
30
  const isNewline = params.filter(hasDecorators).length;
30
31
  const isAllHasComments = isAllParamsHasLeadingComments(path);
31
32
 
@@ -200,6 +200,14 @@ export const hasTrailingComment = (path) => {
200
200
  return node.trailingComments?.length;
201
201
  };
202
202
 
203
+ export const hasDecorators = (path) => {
204
+ const {decorators} = path.node;
205
+
206
+ if (!decorators)
207
+ return false;
208
+
209
+ return decorators.length;
210
+ };
203
211
  export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
204
212
 
205
213
  export const noTrailingComment = (path) => !path.node.trailingComments?.length;
@@ -1,5 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
2
3
  import {maybeVisitor} from '#printer';
4
+ import {hasDecorators, callWithPrev} from '#is';
3
5
 
4
6
  const {
5
7
  isExportDeclaration,
@@ -15,12 +17,31 @@ const isPrevClassProperty = (path) => {
15
17
  return prev.isClassProperty() || prev.isClassAccessorProperty();
16
18
  };
17
19
 
20
+ const callWithDeclaration = (fn) => (path) => fn(path.get('declaration'));
21
+
22
+ const isNewline = createTypeChecker([
23
+ ['-: -> !', callWithPrev(isExportDeclaration)],
24
+ ['+', callWithDeclaration(hasDecorators)],
25
+ ]);
26
+
27
+ const isExportWithClass = createTypeChecker([
28
+ ['-: -> !ExportNamedDeclaration'],
29
+ ['+', callWithDeclaration(isClassDeclaration)],
30
+ ]);
31
+
18
32
  export const maybeDecorators = (visitor) => (path, printer, semantics, options) => {
19
- if (isExportDeclaration(path.parentPath))
33
+ const {parentPath} = path;
34
+ const {print} = printer;
35
+
36
+ if (isExportDeclaration(parentPath))
20
37
  return maybeVisitor(visitor, path, printer, semantics, options);
21
38
 
22
- if (isExportDeclaration(path) && isClassDeclaration(path.node.declaration)) {
39
+ if (isExportWithClass(path)) {
23
40
  const declaration = path.get('declaration');
41
+
42
+ if (isNewline(path))
43
+ print.newline();
44
+
24
45
  printDecorators(declaration, printer);
25
46
 
26
47
  return maybeVisitor(visitor, path, printer, semantics, options);
@@ -1,4 +1,15 @@
1
- import {hasLeadingComment} from '#is';
1
+ import {
2
+ hasLeadingComment,
3
+ hasTrailingComment,
4
+ } from '#is';
5
+ import {createTypeChecker} from '#type-checker';
6
+
7
+ const callWithLastDecorator = (fn) => (path) => fn(path.get('decorators').at(-1));
8
+
9
+ const isIndent = createTypeChecker([
10
+ ['-', hasLeadingComment],
11
+ ['+', callWithLastDecorator(hasTrailingComment)],
12
+ ]);
2
13
 
3
14
  export const TSParameterProperty = (path, {print, maybe, indent}) => {
4
15
  const {
@@ -19,7 +30,7 @@ export const TSParameterProperty = (path, {print, maybe, indent}) => {
19
30
 
20
31
  maybe.print.breakline(decoratorsLength);
21
32
 
22
- if (!hasLeadingComment(path))
33
+ if (isIndent(path))
23
34
  indent();
24
35
  else
25
36
  print(' ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.35.0",
3
+ "version": "18.36.0",
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",