@putout/printer 15.1.0 → 15.1.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.12, v15.1.2
2
+
3
+ fix:
4
+ - b3499c9 @putout/printer: ObjectPattern: destructuring
5
+
6
+ 2025.06.12, v15.1.1
7
+
8
+ feature:
9
+ - e67a827 @putout/printer: ObjectPattern: Assign: improve
10
+
1
11
  2025.06.12, v15.1.0
2
12
 
3
13
  fix:
@@ -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,21 @@ 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,
29
+ isObjectExpression,
24
30
  isVariableDeclarator,
31
+ isFunction,
25
32
  } = types;
26
33
 
27
34
  function isIndent(path) {
@@ -41,6 +48,17 @@ const isCoupleProperties = ({path, valuePath, property}) => {
41
48
  return !path.parentPath.isObjectProperty();
42
49
  };
43
50
 
51
+ function isPrevAssignObject(path) {
52
+ const prev = path.getPrevSibling();
53
+
54
+ if (!isAssignmentPattern(prev.node.value))
55
+ return false;
56
+
57
+ const {right} = prev.node.value;
58
+
59
+ return isObjectExpression(right);
60
+ }
61
+
44
62
  module.exports.ObjectPattern = {
45
63
  print: maybeTypeAnnotation((path, printer, semantics) => {
46
64
  const shouldIndent = isIndent(path);
@@ -67,8 +85,8 @@ module.exports.ObjectPattern = {
67
85
  });
68
86
 
69
87
  const hasObject = n && hasObjectPattern(properties);
70
-
71
88
  const notInsideFn = !isInsideFn(path);
89
+
72
90
  maybe.print.newline(is && notInsideFn);
73
91
 
74
92
  for (const [i, property] of properties.entries()) {
@@ -81,6 +99,8 @@ module.exports.ObjectPattern = {
81
99
  continue;
82
100
  }
83
101
 
102
+ const prevAssignObject = i && isPrevAssignObject(property);
103
+
84
104
  const valuePath = property.get('value');
85
105
  const keyPath = property.get('key');
86
106
  const isAssign = valuePath.isAssignmentPattern();
@@ -92,7 +112,7 @@ module.exports.ObjectPattern = {
92
112
  valuePath,
93
113
  });
94
114
 
95
- maybe.indent(is && notInsideFn);
115
+ maybe.indent((prevAssignObject || is) && notInsideFn);
96
116
  maybe.print.breakline(couple);
97
117
 
98
118
  printKey(property, printer);
@@ -108,7 +128,7 @@ module.exports.ObjectPattern = {
108
128
  maybe.print.newline(couple);
109
129
  }
110
130
 
111
- if (is || hasObject) {
131
+ if (is || hasObject || prevAssignObject && notInsideFn) {
112
132
  print(',');
113
133
  print.newline();
114
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.1.0",
3
+ "version": "15.1.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",