@putout/printer 12.25.0 → 12.27.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,14 @@
1
+ 2025.02.08, v12.27.0
2
+
3
+ feature:
4
+ - 7775296 @putout/printer: Decorator: trailing comments
5
+
6
+ 2025.02.08, v12.26.0
7
+
8
+ feature:
9
+ - b2afc0d @putout/printer: @putout/compare v16.0.1
10
+ - 386284a @putout/printer: ClassMethod: comments
11
+
1
12
  2025.02.07, v12.25.0
2
13
 
3
14
  feature:
@@ -19,6 +19,8 @@ const {
19
19
  isSpreadElement,
20
20
  isClassBody,
21
21
  isBinaryExpression,
22
+ isClassMethod,
23
+ isDecorator,
22
24
  } = types;
23
25
 
24
26
  const isProperty = satisfy([
@@ -41,13 +43,14 @@ const isInsideVar = (path) => {
41
43
  return isVariableDeclarator(parentPath.parentPath);
42
44
  };
43
45
 
44
- const hasDecorators = (path) => {
45
- const {parentPath} = path;
46
+ const hasDecoratorsWithComments = (path) => {
47
+ if (isDecorator(path))
48
+ return false;
46
49
 
47
- if (path.node.decorators?.length)
50
+ if (path.node.decorators)
48
51
  return true;
49
52
 
50
- return parentPath.node.decorators?.length;
53
+ return path?.parentPath.node?.decorators;
51
54
  };
52
55
 
53
56
  function isCommentOfPrevious(path) {
@@ -96,7 +99,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
96
99
  if (!leadingComments?.length)
97
100
  return;
98
101
 
99
- if (hasDecorators(path))
102
+ if (hasDecoratorsWithComments(path))
100
103
  return;
101
104
 
102
105
  const looksLikeSwitchCase = path.isSwitchCase();
@@ -136,7 +139,9 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
136
139
  maybe.print.breakline(propIs);
137
140
  maybe.print.newline(!propIs);
138
141
 
139
- if (isBinaryExpression(path)) {
142
+ if (isClassMethod(path)) {
143
+ indent();
144
+ } else if (isBinaryExpression(path) || isDecorator(path)) {
140
145
  indent.inc();
141
146
  indent();
142
147
  indent.dec();
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {parseComments} = require('../../comment/comment');
4
+
4
5
  const noop = () => {};
5
6
  const parseParams = (path) => path.get('params');
6
7
 
@@ -1,6 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const {printParams} = require('./params');
4
+ const {hasLeadingComment} = require('../../is');
5
+
6
+ const isDecoratorHasLeadingComment = (path) => {
7
+ const [firstParam] = path.get('params');
8
+ const decorators = firstParam.get('decorators');
9
+
10
+ if (!decorators.length)
11
+ return false;
12
+
13
+ const [firstDecorator] = decorators;
14
+
15
+ return hasLeadingComment(firstDecorator);
16
+ };
4
17
 
5
18
  const hasDecorators = ({decorators}) => decorators?.length;
6
19
 
@@ -10,13 +23,13 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
10
23
  const isNewline = params.filter(hasDecorators).length;
11
24
  const printSpace = isNewline ? print.breakline : print.space;
12
25
 
13
- const printBeforeFirst = createPrint({
26
+ const printBeforeFirst = createPrint(path, {
14
27
  type: 'inc',
15
28
  printer,
16
29
  isNewline,
17
30
  });
18
31
 
19
- const printAfterLast = createPrint({
32
+ const printAfterLast = createPrint(path, {
20
33
  type: 'dec',
21
34
  printer,
22
35
  isNewline,
@@ -29,11 +42,14 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
29
42
  });
30
43
  };
31
44
 
32
- const createPrint = ({isNewline, printer, type}) => () => {
45
+ const createPrint = (path, {isNewline, printer, type}) => () => {
33
46
  if (!isNewline)
34
47
  return;
35
48
 
36
49
  const {indent, print} = printer;
37
- indent[type]();
50
+
51
+ if (!isDecoratorHasLeadingComment(path))
52
+ indent[type]();
53
+
38
54
  print.breakline();
39
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.25.0",
3
+ "version": "12.27.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",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@putout/babel": "^3.0.0",
36
- "@putout/compare": "^15.0.2",
36
+ "@putout/compare": "^16.0.1",
37
37
  "@putout/operate": "^12.0.0",
38
38
  "@putout/operator-json": "^2.0.0",
39
39
  "fullstore": "^3.0.0",