@putout/printer 15.0.0 → 15.1.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,13 @@
1
+ 2025.06.12, v15.1.0
2
+
3
+ fix:
4
+ - 7274b61 @putout/printer: ObjectPattern: AssignmentPattern: ObjectExpression: comma
5
+
6
+ feature:
7
+ - c41eda6 @putout/printer: Decorator: printLeadingCommentLine
8
+ - 88d8cd4 @putout/printer: @putout/plugin-react-hooks v9.0.0
9
+ - 57495a1 @putout/printer: @putout/operate v14.0.1
10
+
1
11
  2025.06.01, v15.0.0
2
12
 
3
13
  feature:
@@ -48,12 +48,7 @@ const isInsideVar = (path) => {
48
48
  return isVariableDeclarator(parentPath.parentPath);
49
49
  };
50
50
 
51
- const hasDecoratorsWithComments = (path) => {
52
- if (isDecorator(path))
53
- return false;
54
-
55
- return path?.parentPath.node?.decorators;
56
- };
51
+ const hasDecoratorsWithComments = (path) => path?.parentPath.node?.decorators;
57
52
 
58
53
  function isCommentOfPrevious(path) {
59
54
  const [comment] = path.node.leadingComments;
@@ -13,3 +13,9 @@ module.exports.Decorator = (path, {print, maybe}) => {
13
13
  print('__expression');
14
14
  maybe.print(isMember, ')');
15
15
  };
16
+
17
+ module.exports.Decorator.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
18
+ const {print} = printer;
19
+ printComment();
20
+ print.breakline();
21
+ };
@@ -36,7 +36,7 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
36
36
  printer,
37
37
  });
38
38
 
39
- const printAfterOpen = createPrintAfterOpen(path, {
39
+ const printAfterOpen = createPrintAfterOpen({
40
40
  type: 'inc',
41
41
  printer,
42
42
  isNewline,
@@ -57,7 +57,7 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
57
57
  });
58
58
  };
59
59
 
60
- const createPrintAfterOpen = (path, {isNewline, isAllHasComments, printer, type}) => () => {
60
+ const createPrintAfterOpen = ({isNewline, isAllHasComments, printer, type}) => () => {
61
61
  if (!isNewline)
62
62
  return;
63
63
 
@@ -67,11 +67,6 @@ const createPrintAfterOpen = (path, {isNewline, isAllHasComments, printer, type}
67
67
  indent[type]();
68
68
 
69
69
  print.breakline();
70
-
71
- const [first] = path.get('params');
72
-
73
- if (!first.node.decorators)
74
- indent();
75
70
  };
76
71
 
77
72
  const createPrintBeforeClose = ({isNewline, printer, isAllHasComments, type}) => () => {
@@ -1,8 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {isConcatenation} = require('../binary-expression/concatenate');
4
5
  const {isOneLine} = require('./object-expression');
5
6
  const {printKey} = require('./print-key');
7
+ const {isTSImportType} = types;
8
+ const isInsideTSImportType = ({parentPath}) => isTSImportType(parentPath.parentPath);
6
9
 
7
10
  module.exports.ObjectProperty = (path, printer, semantics) => {
8
11
  const {trailingComma} = semantics;
@@ -14,7 +17,6 @@ module.exports.ObjectProperty = (path, printer, semantics) => {
14
17
  } = printer;
15
18
 
16
19
  const value = path.get('value');
17
-
18
20
  const properties = path.parentPath.get('properties');
19
21
  const isLast = path === properties.at(-1);
20
22
  const manyLines = !isOneLine(path.parentPath);
@@ -27,7 +29,7 @@ module.exports.ObjectProperty = (path, printer, semantics) => {
27
29
  traverse(value);
28
30
  }
29
31
 
30
- if (manyLines)
32
+ if (manyLines && !isInsideTSImportType(path))
31
33
  maybe.write(!isLast || trailingComma, ',');
32
34
  else if (!isLast && properties.length)
33
35
  write(', ');
@@ -115,7 +115,7 @@ module.exports.ObjectPattern = {
115
115
  continue;
116
116
  }
117
117
 
118
- if (i < n) {
118
+ if (i < n && !(isAssign && couple)) {
119
119
  print(',');
120
120
  print.space();
121
121
  }
@@ -10,7 +10,6 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
10
10
  } = path.node;
11
11
 
12
12
  const decoratorsLength = decorators?.length > 1;
13
- const isNewline = decoratorsLength || hasLeadingComment(path);
14
13
 
15
14
  maybe.print.breakline(decoratorsLength);
16
15
 
@@ -22,11 +21,10 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
22
21
 
23
22
  maybe.print.breakline(decoratorsLength);
24
23
 
25
- if (isNewline)
26
- indent();
27
-
28
24
  if (!hasLeadingComment(path))
29
- print.space();
25
+ indent();
26
+ else
27
+ print(' ');
30
28
  }
31
29
 
32
30
  if (accessibility) {
@@ -48,12 +46,21 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
48
46
  module.exports.TSParameterProperty.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
49
47
  const {indent, print} = printer;
50
48
 
51
- if (path.parentPath.isClassMethod() && !path.node.decorators) {
49
+ if (path.node.decorators) {
50
+ printComment();
51
+ print.breakline();
52
+
53
+ return;
54
+ }
55
+
56
+ if (path.parentPath.isClassMethod()) {
52
57
  indent.inc();
53
58
  print.breakline();
54
59
 
55
60
  printComment();
56
61
  print.breakline();
57
62
  indent.dec();
63
+
64
+ return;
58
65
  }
59
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.0.0",
3
+ "version": "15.1.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",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@putout/babel": "^4.0.1",
37
37
  "@putout/compare": "^18.0.0",
38
- "@putout/operate": "^13.0.0",
38
+ "@putout/operate": "^14.0.1",
39
39
  "@putout/operator-json": "^2.0.0",
40
40
  "fullstore": "^3.0.0",
41
41
  "just-snake-case": "^3.2.0",
@@ -74,7 +74,7 @@
74
74
  "@putout/plugin-printer": "^5.0.0",
75
75
  "@putout/plugin-promises": "^18.0.0",
76
76
  "@putout/plugin-react-hook-form": "^6.0.0",
77
- "@putout/plugin-react-hooks": "^8.0.1",
77
+ "@putout/plugin-react-hooks": "^9.0.0",
78
78
  "acorn": "^8.8.2",
79
79
  "c8": "^10.1.2",
80
80
  "check-dts": "^0.9.0",