@putout/printer 2.67.0 → 2.69.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
+ 2023.07.10, v2.69.0
2
+
3
+ feature:
4
+ - f057898 @putout/printer: TSDeclareFunction
5
+
6
+ 2023.07.10, v2.68.0
7
+
8
+ feature:
9
+ - e1fc3d9 @putout/printer: ObjectPattern: properties: AssignmentPattern: newline
10
+
1
11
  2023.07.10, v2.67.0
2
12
 
3
13
  feature:
@@ -3,6 +3,7 @@
3
3
  const {
4
4
  isIdentifier,
5
5
  isObjectPattern,
6
+ isAssignmentPattern,
6
7
  } = require('@babel/types');
7
8
 
8
9
  const {wrongShorthand} = require('./wrong-shortand');
@@ -22,6 +23,7 @@ const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.propert
22
23
  module.exports.ObjectPattern = {
23
24
  print(path, {indent, print, maybe}, semantics) {
24
25
  const {maxPropertiesInOneLine} = semantics;
26
+
25
27
  indent.inc();
26
28
  print('{');
27
29
 
@@ -51,7 +53,6 @@ module.exports.ObjectPattern = {
51
53
  const isAssign = valuePath.isAssignmentPattern();
52
54
 
53
55
  const {shorthand, computed} = property.node;
54
-
55
56
  const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty();
56
57
 
57
58
  maybe.indent(is);
@@ -117,6 +118,17 @@ function checkLength(properties) {
117
118
  return false;
118
119
  }
119
120
 
121
+ function hasAssign(properties) {
122
+ for (const prop of properties) {
123
+ const {value} = prop.node;
124
+
125
+ if (isAssignmentPattern(value))
126
+ return true;
127
+ }
128
+
129
+ return false;
130
+ }
131
+
120
132
  function hasObjectPattern(properties) {
121
133
  for (const property of properties) {
122
134
  if (isObjectPattern(property.node.value))
@@ -140,5 +152,8 @@ function shouldAddNewline(path, {maxPropertiesInOneLine}) {
140
152
  if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
141
153
  return COUPLE_LINES;
142
154
 
155
+ if (hasAssign(properties))
156
+ return COUPLE_LINES;
157
+
143
158
  return parentPath.isObjectProperty();
144
159
  }
@@ -3,7 +3,9 @@
3
3
  const {printParams} = require('../expressions/functions/params');
4
4
  const {isNext} = require('../is');
5
5
 
6
- const notInsideExport = (path) => !path.parentPath.isExportDeclaration();
6
+ const isInsideExport = (path) => {
7
+ return path.parentPath.isExportDefaultDeclaration();
8
+ };
7
9
 
8
10
  module.exports.TSDeclareFunction = (path, printer, semantics) => {
9
11
  const {print, maybe} = printer;
@@ -18,6 +20,9 @@ module.exports.TSDeclareFunction = (path, printer, semantics) => {
18
20
  print(':');
19
21
  print.space();
20
22
  print('__returnType');
21
- maybe.print(notInsideExport(path), ';');
22
- maybe.print.newline(isNext(path));
23
+
24
+ if (!isInsideExport(path)) {
25
+ print(';');
26
+ maybe.print.newline(isNext(path) || isNext(path.parentPath));
27
+ }
23
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.67.0",
3
+ "version": "2.69.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",