@putout/printer 15.1.3 → 15.3.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
+ 2025.06.13, v15.3.0
2
+
3
+ feature:
4
+ - 8022359 @putout/printer: ObjectPattern: AssignObject: after property
5
+
6
+ 2025.06.13, v15.2.0
7
+
8
+ feature:
9
+ - 348901a @putout/printer: ArrayExpression: maxElementsOneLine: 0
10
+
1
11
  2025.06.12, v15.1.3
2
12
 
3
13
  fix:
@@ -60,7 +60,12 @@ const isSiblingIsArray = (path) => {
60
60
  };
61
61
 
62
62
  module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
63
- if (elements.length > 3 && !isObjectExpression(elements[0]))
63
+ const [first] = elements;
64
+
65
+ if (elements.length > maxElementsInOneLine && isStringLiteral(first))
66
+ return MULTI_LINE;
67
+
68
+ if (elements.length > 3 && !isObjectExpression(first))
64
69
  return MULTI_LINE;
65
70
 
66
71
  if (isSimpleAndNotEmptyObject(elements))
@@ -133,7 +138,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
133
138
 
134
139
  const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
135
140
 
136
- const isShortTwoSimplesInsideCall = (path, short) => {
141
+ const isShortTwoSimplesInsideCall = (path, maxElementsInOneLine) => {
137
142
  const {node, parentPath} = path;
138
143
 
139
144
  const {elements} = node;
@@ -146,7 +151,7 @@ const isShortTwoSimplesInsideCall = (path, short) => {
146
151
  if (!isStringLiteral(a) || !isStringLiteral(b))
147
152
  return false;
148
153
 
149
- return length < short;
154
+ return length < maxElementsInOneLine;
150
155
  };
151
156
 
152
157
  const isTwoSimplesInsideObjectProperty = (path) => {
@@ -15,22 +15,22 @@ const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
15
15
  const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
16
16
  const {printKey} = require('../object-expression/print-key');
17
17
 
18
- const isInsideFn = (path) => {
19
- if (isFunction(path.parentPath))
20
- return true;
21
-
22
- return isFunction(path.parentPath.parentPath);
23
- };
24
-
25
18
  const {
19
+ isObjectExpression,
26
20
  isIdentifier,
27
- isObjectPattern,
28
21
  isAssignmentPattern,
29
- isObjectExpression,
30
22
  isVariableDeclarator,
31
23
  isFunction,
24
+ isObjectPattern,
32
25
  } = types;
33
26
 
27
+ const isInsideFn = (path) => {
28
+ if (isFunction(path.parentPath))
29
+ return true;
30
+
31
+ return isFunction(path.parentPath.parentPath);
32
+ };
33
+
34
34
  function isIndent(path) {
35
35
  return !path.parentPath.isArrayPattern();
36
36
  }
@@ -48,6 +48,11 @@ const isCoupleProperties = ({path, valuePath, property}) => {
48
48
  return !path.parentPath.isObjectProperty();
49
49
  };
50
50
 
51
+ function isPrevAssign(path) {
52
+ const prev = path.getPrevSibling();
53
+ return isAssignmentPattern(prev.node.value);
54
+ }
55
+
51
56
  function isPrevAssignObject(path) {
52
57
  const prev = path.getPrevSibling();
53
58
 
@@ -59,6 +64,20 @@ function isPrevAssignObject(path) {
59
64
  return isObjectExpression(right);
60
65
  }
61
66
 
67
+ function isNextAssignObject(path) {
68
+ const next = path.getNextSibling();
69
+
70
+ if (!next.node)
71
+ return false;
72
+
73
+ if (!isAssignmentPattern(next.node.value))
74
+ return false;
75
+
76
+ const {right} = next.node.value;
77
+
78
+ return isObjectExpression(right);
79
+ }
80
+
62
81
  module.exports.ObjectPattern = {
63
82
  print: maybeTypeAnnotation((path, printer, semantics) => {
64
83
  const shouldIndent = isIndent(path);
@@ -100,6 +119,7 @@ module.exports.ObjectPattern = {
100
119
  }
101
120
 
102
121
  const prevAssignObject = i && isPrevAssignObject(property);
122
+ const nextAssignObject = isNextAssignObject(property);
103
123
 
104
124
  const valuePath = property.get('value');
105
125
  const keyPath = property.get('key');
@@ -115,6 +135,9 @@ module.exports.ObjectPattern = {
115
135
  maybe.indent((prevAssignObject || is) && notInsideFn);
116
136
  maybe.print.breakline(couple);
117
137
 
138
+ if (!isAssign && nextAssignObject)
139
+ print.breakline();
140
+
118
141
  printKey(property, printer);
119
142
 
120
143
  if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
@@ -126,6 +149,18 @@ module.exports.ObjectPattern = {
126
149
 
127
150
  maybe.print(couple, ',');
128
151
  maybe.print.newline(couple);
152
+
153
+ if (i && !isPrevAssign(property)) {
154
+ print(',');
155
+ print.newline();
156
+ continue;
157
+ }
158
+ }
159
+
160
+ if (!isAssign && nextAssignObject && notInsideFn) {
161
+ print(',');
162
+ print.breakline();
163
+ continue;
129
164
  }
130
165
 
131
166
  if (is || hasObject || prevAssignObject && notInsideFn) {
@@ -229,3 +264,4 @@ function isFunctionParam({parentPath}) {
229
264
 
230
265
  return parentPath.parentPath.isFunction();
231
266
  }
267
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.1.3",
3
+ "version": "15.3.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",
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "moduleResolution": "nodenext",
3
4
  "target": "es2015",
4
5
  "skipLibCheck": true
5
6
  },