@putout/printer 15.0.0 → 15.1.1

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,18 @@
1
+ 2025.06.12, v15.1.1
2
+
3
+ feature:
4
+ - e67a827 @putout/printer: ObjectPattern: Assign: improve
5
+
6
+ 2025.06.12, v15.1.0
7
+
8
+ fix:
9
+ - 7274b61 @putout/printer: ObjectPattern: AssignmentPattern: ObjectExpression: comma
10
+
11
+ feature:
12
+ - c41eda6 @putout/printer: Decorator: printLeadingCommentLine
13
+ - 88d8cd4 @putout/printer: @putout/plugin-react-hooks v9.0.0
14
+ - 57495a1 @putout/printer: @putout/operate v14.0.1
15
+
1
16
  2025.06.01, v15.0.0
2
17
 
3
18
  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(', ');
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
-
5
4
  const {wrongShorthand} = require('./wrong-shortand');
6
5
 
7
6
  const {
@@ -15,13 +14,20 @@ const {moreThenMaxPropertiesInOneLine} = require('./more-then-max-properties-in-
15
14
  const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
16
15
  const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
17
16
  const {printKey} = require('../object-expression/print-key');
18
- const isInsideFn = (path) => path.parentPath.isFunction();
17
+
18
+ const isInsideFn = (path) => {
19
+ if (isFunction(path.parentPath))
20
+ return true;
21
+
22
+ return isFunction(path.parentPath.parentPath);
23
+ };
19
24
 
20
25
  const {
21
26
  isIdentifier,
22
27
  isObjectPattern,
23
28
  isAssignmentPattern,
24
29
  isVariableDeclarator,
30
+ isFunction,
25
31
  } = types;
26
32
 
27
33
  function isIndent(path) {
@@ -67,8 +73,8 @@ module.exports.ObjectPattern = {
67
73
  });
68
74
 
69
75
  const hasObject = n && hasObjectPattern(properties);
70
-
71
76
  const notInsideFn = !isInsideFn(path);
77
+
72
78
  maybe.print.newline(is && notInsideFn);
73
79
 
74
80
  for (const [i, property] of properties.entries()) {
@@ -81,6 +87,9 @@ module.exports.ObjectPattern = {
81
87
  continue;
82
88
  }
83
89
 
90
+ const prev = property.getPrevSibling();
91
+ const prevAssign = i && isAssignmentPattern(prev.node.value);
92
+
84
93
  const valuePath = property.get('value');
85
94
  const keyPath = property.get('key');
86
95
  const isAssign = valuePath.isAssignmentPattern();
@@ -92,7 +101,7 @@ module.exports.ObjectPattern = {
92
101
  valuePath,
93
102
  });
94
103
 
95
- maybe.indent(is && notInsideFn);
104
+ maybe.indent((prevAssign || is) && notInsideFn);
96
105
  maybe.print.breakline(couple);
97
106
 
98
107
  printKey(property, printer);
@@ -108,14 +117,14 @@ module.exports.ObjectPattern = {
108
117
  maybe.print.newline(couple);
109
118
  }
110
119
 
111
- if (is || hasObject) {
120
+ if (is || hasObject || prevAssign && notInsideFn) {
112
121
  print(',');
113
122
  print.newline();
114
123
 
115
124
  continue;
116
125
  }
117
126
 
118
- if (i < n) {
127
+ if (i < n && !(isAssign && couple)) {
119
128
  print(',');
120
129
  print.space();
121
130
  }
@@ -209,3 +218,4 @@ function isFunctionParam({parentPath}) {
209
218
 
210
219
  return parentPath.parentPath.isFunction();
211
220
  }
221
+
@@ -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.1",
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",