@putout/printer 18.34.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,15 @@
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
+
8
+ 2026.07.12, v18.35.0
9
+
10
+ feature:
11
+ - 30405c11 @putout/printer: AssignmentExpression inside ExpressionStatement: trailing comment line
12
+
1
13
  2026.07.11, v18.34.0
2
14
 
3
15
  feature:
@@ -96,11 +96,12 @@ export const printTrailingComments = (path, printer, semantics, {currentTraverse
96
96
  continue;
97
97
  }
98
98
 
99
- isCommentBlock(comment);
100
-
101
- printTrailingCommentBlock?.(path, printer, semantics, {
102
- index,
103
- printComment: createPrintCommentBlock(print, value),
104
- });
99
+ if (isCommentBlock(comment))
100
+ printTrailingCommentBlock?.(path, printer, semantics, {
101
+ index,
102
+ printComment: createPrintCommentBlock(print, value),
103
+ isLast: index === n,
104
+ isSameLine: isSameLine(path, loc),
105
+ });
105
106
  }
106
107
  };
@@ -10,10 +10,12 @@ import {
10
10
  maybeInsideReturnWithCommentEnd,
11
11
  maybeInsideReturnWithCommentStart,
12
12
  printLeadingCommentBlock,
13
- } from './assignment-expression-comments.js';
13
+ } from './comments.js';
14
14
 
15
15
  export const AssignmentExpression = maybeParens({
16
16
  checkParens: false,
17
+ printLeadingCommentLine,
18
+ printLeadingCommentBlock,
17
19
  condition,
18
20
  print(path, printer) {
19
21
  const {print} = printer;
@@ -35,6 +37,3 @@ export const AssignmentExpression = maybeParens({
35
37
  maybeInsideReturnWithCommentEnd(path, printer);
36
38
  },
37
39
  });
38
-
39
- AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
40
- AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
@@ -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);
@@ -20,8 +20,9 @@ const maybeParensPrint = (print) => ({
20
20
  },
21
21
  });
22
22
 
23
- const maybeParensCondition = ({print, condition, checkParens = true}) => ({
23
+ const maybeParensCondition = ({print, condition, checkParens = true, ...rest}) => ({
24
24
  ...maybeParensPrint(print),
25
+ ...rest,
25
26
  condition: (path, print, semantics) => {
26
27
  const is = condition?.(path, print, semantics);
27
28
 
@@ -67,11 +67,12 @@ export const printLeadingCommentBlock = (path, printer, semantics, {printComment
67
67
  printComment();
68
68
  };
69
69
 
70
- export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
71
- const {print} = printer;
70
+ export const printTrailingCommentBlock = (path, printer, semantics, {printComment, isSameLine}) => {
71
+ const {maybe, print} = printer;
72
72
 
73
73
  if (isNext(path))
74
74
  print.breakline();
75
75
 
76
+ maybe.print.space(isSameLine);
76
77
  printComment();
77
78
  };
@@ -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.34.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",