@putout/printer 15.2.0 → 15.3.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,13 @@
1
+ 2025.06.14, v15.3.1
2
+
3
+ feature:
4
+ - a266b51 @putout/printer: ObjectPattern: newline
5
+
6
+ 2025.06.13, v15.3.0
7
+
8
+ feature:
9
+ - 8022359 @putout/printer: ObjectPattern: AssignObject: after property
10
+
1
11
  2025.06.13, v15.2.0
2
12
 
3
13
  feature:
@@ -22,6 +22,7 @@ const {
22
22
  isVariableDeclarator,
23
23
  isFunction,
24
24
  isObjectPattern,
25
+ isForOfStatement,
25
26
  } = types;
26
27
 
27
28
  const isInsideFn = (path) => {
@@ -42,12 +43,24 @@ const isCoupleProperties = ({path, valuePath, property}) => {
42
43
  if (exists(property.getPrevSibling()))
43
44
  return false;
44
45
 
45
- if (path.parentPath.isVariableDeclarator() && !hasAssign(path.get('properties')))
46
+ const properties = path.get('properties');
47
+
48
+ if (path.parentPath.isVariableDeclarator() && !hasAssign(properties))
46
49
  return false;
47
50
 
48
51
  return !path.parentPath.isObjectProperty();
49
52
  };
50
53
 
54
+ function isInsideForOf({parentPath}) {
55
+ return isForOfStatement(parentPath.parentPath.parentPath);
56
+ }
57
+
58
+ function isPrevAssign(path) {
59
+ const prev = path.getPrevSibling();
60
+
61
+ return isAssignmentPattern(prev.node.value);
62
+ }
63
+
51
64
  function isPrevAssignObject(path) {
52
65
  const prev = path.getPrevSibling();
53
66
 
@@ -59,6 +72,20 @@ function isPrevAssignObject(path) {
59
72
  return isObjectExpression(right);
60
73
  }
61
74
 
75
+ function isNextAssignObject(path) {
76
+ const next = path.getNextSibling();
77
+
78
+ if (!next.node)
79
+ return false;
80
+
81
+ if (!isAssignmentPattern(next.node.value))
82
+ return false;
83
+
84
+ const {right} = next.node.value;
85
+
86
+ return isObjectExpression(right);
87
+ }
88
+
62
89
  module.exports.ObjectPattern = {
63
90
  print: maybeTypeAnnotation((path, printer, semantics) => {
64
91
  const shouldIndent = isIndent(path);
@@ -100,6 +127,7 @@ module.exports.ObjectPattern = {
100
127
  }
101
128
 
102
129
  const prevAssignObject = i && isPrevAssignObject(property);
130
+ const nextAssignObject = isNextAssignObject(property);
103
131
 
104
132
  const valuePath = property.get('value');
105
133
  const keyPath = property.get('key');
@@ -115,6 +143,9 @@ module.exports.ObjectPattern = {
115
143
  maybe.indent((prevAssignObject || is) && notInsideFn);
116
144
  maybe.print.breakline(couple);
117
145
 
146
+ if (!isAssign && nextAssignObject)
147
+ print.breakline();
148
+
118
149
  printKey(property, printer);
119
150
 
120
151
  if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
@@ -126,6 +157,20 @@ module.exports.ObjectPattern = {
126
157
 
127
158
  maybe.print(couple, ',');
128
159
  maybe.print.newline(couple);
160
+
161
+ const {right} = valuePath.node;
162
+
163
+ if (i && !isPrevAssign(property) && !isInsideForOf(path) && isObjectExpression(right)) {
164
+ print(',');
165
+ print.newline();
166
+ continue;
167
+ }
168
+ }
169
+
170
+ if (!isAssign && nextAssignObject && notInsideFn) {
171
+ print(',');
172
+ print.breakline();
173
+ continue;
129
174
  }
130
175
 
131
176
  if (is || hasObject || prevAssignObject && notInsideFn) {
@@ -142,7 +187,8 @@ module.exports.ObjectPattern = {
142
187
  }
143
188
 
144
189
  indent.dec();
145
- maybe.indent(is);
190
+
191
+ maybe.indent(is || hasAssign(properties));
146
192
  maybe.indent.inc(!shouldIndent);
147
193
  print('}');
148
194
  }),
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.StringLiteral = (path, {write}, semantics) => {
4
- const {value, raw = `'${value}'`} = path.node;
4
+ const {value, raw = `'${value}'`,
5
+ } = path.node;
5
6
 
6
7
  if (path.parentPath.isJSXAttribute()) {
7
8
  write(raw);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.2.0",
3
+ "version": "15.3.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",