@putout/printer 15.3.0 → 15.3.2

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.14, v15.3.2
2
+
3
+ fix:
4
+ - a92c4d3 @putout/printer: ObjectPattern: indent
5
+
6
+ 2025.06.14, v15.3.1
7
+
8
+ feature:
9
+ - a266b51 @putout/printer: ObjectPattern: newline
10
+
1
11
  2025.06.13, v15.3.0
2
12
 
3
13
  feature:
@@ -22,6 +22,8 @@ const {
22
22
  isVariableDeclarator,
23
23
  isFunction,
24
24
  isObjectPattern,
25
+ isForOfStatement,
26
+ isVariableDeclaration,
25
27
  } = types;
26
28
 
27
29
  const isInsideFn = (path) => {
@@ -42,14 +44,21 @@ const isCoupleProperties = ({path, valuePath, property}) => {
42
44
  if (exists(property.getPrevSibling()))
43
45
  return false;
44
46
 
45
- if (path.parentPath.isVariableDeclarator() && !hasAssign(path.get('properties')))
47
+ const properties = path.get('properties');
48
+
49
+ if (path.parentPath.isVariableDeclarator() && !hasAssign(properties))
46
50
  return false;
47
51
 
48
52
  return !path.parentPath.isObjectProperty();
49
53
  };
50
54
 
55
+ function isInsideForOf({parentPath}) {
56
+ return isForOfStatement(parentPath.parentPath.parentPath);
57
+ }
58
+
51
59
  function isPrevAssign(path) {
52
60
  const prev = path.getPrevSibling();
61
+
53
62
  return isAssignmentPattern(prev.node.value);
54
63
  }
55
64
 
@@ -150,7 +159,9 @@ module.exports.ObjectPattern = {
150
159
  maybe.print(couple, ',');
151
160
  maybe.print.newline(couple);
152
161
 
153
- if (i && !isPrevAssign(property)) {
162
+ const {right} = valuePath.node;
163
+
164
+ if (i && !isPrevAssign(property) && !isInsideForOf(path) && isObjectExpression(right)) {
154
165
  print(',');
155
166
  print.newline();
156
167
  continue;
@@ -177,7 +188,8 @@ module.exports.ObjectPattern = {
177
188
  }
178
189
 
179
190
  indent.dec();
180
- maybe.indent(is);
191
+
192
+ maybe.indent(is || hasAssignObject(path));
181
193
  maybe.indent.inc(!shouldIndent);
182
194
  print('}');
183
195
  }),
@@ -208,6 +220,28 @@ function hasAssign(properties) {
208
220
  return false;
209
221
  }
210
222
 
223
+ function hasAssignObject(path) {
224
+ const {parentPath} = path;
225
+
226
+ if (isVariableDeclaration(parentPath.parentPath)) {
227
+ const {declarations} = parentPath.parentPath.node;
228
+
229
+ if (declarations.length > 1)
230
+ return false;
231
+ }
232
+
233
+ const properties = path.get('properties');
234
+
235
+ for (const prop of properties) {
236
+ const {value} = prop.node;
237
+
238
+ if (isAssignmentPattern(value) && isObjectExpression(value.right))
239
+ return true;
240
+ }
241
+
242
+ return false;
243
+ }
244
+
211
245
  function hasObjectPattern(properties) {
212
246
  for (const property of properties) {
213
247
  if (isObjectPattern(property.node.value))
@@ -264,4 +298,3 @@ function isFunctionParam({parentPath}) {
264
298
 
265
299
  return parentPath.parentPath.isFunction();
266
300
  }
267
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.3.0",
3
+ "version": "15.3.2",
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",